Blob
- Date:
- Message:
- refactor the parsing into the module change the mscan format string to siplify the parsing, and refactor the parsing code into the module for reuse. pe is an exception in that it doesn't care about the format string, it just need to decide if the current line starts a new thread or not, that's why it doesn't use the newly introduced `parse'. The new format simplifies pe too though.
- Actions:
- History | Blame | Raw File
1 package GotMArc;2 use strict;3 use warnings;4 use v5.32;5 use Exporter;7 our @ISA = qw(Exporter);8 our @EXPORT_OK = qw($logo san parse initpage endpage);10 our $logo = <<'EOF';11 <a href="https://gameoftrees.org" target="_blank">12 <img srcset='/got-tiny.png, /got-tiny@2x.png 2x'13 src='/got-tiny.png'14 width='64' height='39'15 alt='"GOT", but the "O" is a cute, smiling sun' /></a>16 EOF18 sub san {19 my $str = shift;20 $str =~ s/&/\&/g;21 $str =~ s/</\</g;22 $str =~ s/>/\>/g;23 return $str;24 }26 sub ssan {27 my $str = shift;28 $str =~ s/\s+/ /g;29 $str =~ s/\s+$//;30 return san($str);31 }33 sub mid2path {34 my $mid = shift;35 $mid =~ s,_,__,g;36 $mid =~ s,/,_,g;37 return $mid;38 }40 sub parse {41 my ($indent, $fname, $mid, $date, $from, $subj) = m{42 ^([^-]*)- # the indent level43 ([^ ]+)\s # filename44 <([^>]+)> # message id45 (\d{4}-\d\d-\d\d[ ]\d\d:\d\d) # date46 <([^>]+)> # from47 (.*) # subject48 }x or die "can't parse: $_";50 my $level = length($indent);51 $level = 10 if $indent =~ m/\.\.\d+\.\./;53 $mid = mid2path($mid);54 $from = ssan($from);55 $subj = ssan($subj);57 return ($level, $fname, $mid, $date, $from, $subj);58 }60 my $hdr = do {61 local $/ = undef;62 open my $fh, "<", "head.html"63 or die "can't open head.html: $!";64 <$fh>;65 };67 sub initpage {68 my ($fh, $title) = @_;69 say $fh $hdr =~ s/TITLE/$title/r;70 }72 my $foot = do {73 local $/ = undef;74 open my $fh, "<", "foot.html"75 or die "can't open foot.html: $!";76 <$fh>;77 };79 sub endpage {80 my $fh = shift;81 say $fh $foot;82 }84 1;