5 use open qw( :std :utf8 );
10 local $/ = undef; # slurp
11 my $source = readline;
13 $pod =~ s/^=over\K/ 25/; # indent options list
14 $pod =~ s/[BC]<([^>]+)>/$1/g; # unbolden
16 ^=item \h \N*\n\n \N*\n \K # first line
17 (?: (?: ^=over .*? ^=back\n )? (?!=) \N*\n )*
18 }{\n}g; # abbreviate options
19 $pod =~ s/^=item\ \K(?=--)/____/g; # align long options
20 # abbreviate <variable> indicators
21 $pod =~ s/\Q>.../s>/g;
22 $pod =~ s/I<(?:number|count|seconds)>/N/g;
23 $pod =~ s/I<character(s?)>/\Uchar$1/g;
25 $pod =~ s/I<([a-z]+)> (?![.,])/\U$1/g; # uppercase
26 $pod =~ s/[.,](?=\n)//g; # trailing punctuation
29 my $parser = Pod::Usage->new(USAGE_OPTIONS => {
30 -indent => 2, -width => 78,
32 $parser->select('SYNOPSIS', 'OPTIONS');
33 $parser->output_string(\my $usage);
34 $parser->parse_string_document($pod);
36 $usage =~ s/\n(?=\n\h)//msg; # strip space between items
37 $usage =~ s/^\ \ \K____/ /g; # nbsp substitute
39 if (open my $logo, '<', 'mascot.txt') {
40 # append logo lines to top usage lines
41 my @ll = split /\n/, readline $logo;
42 my @ul = split /\n/, $usage, @ll + 1;
43 # centered in empty space on the second (longest) line
44 my $pad = (78 - 1 + length($ul[1]) - length($ll[0])) >> 1;
45 $ul[$_] .= (' ' x ($pad - length($ul[$_]))) . $ll[$_] for 0..$#ll;
46 $usage = join "\n", @ul;
50 # custom formatted minimal usage text from pod document
53 elsif (open my $rewrite, '>', $ARGV) {
54 # replace perl code between program end and pod start
55 $source =~ s/^__END__\n \K .*? (?=^=)/$usage/;
56 print {$rewrite} $source;