4 use open qw( :std :utf8 );
9 local $/ = undef; # slurp
10 my $source = readline;
12 $pod =~ s/^=over\K/ 25/; # indent options list
14 ^=item \h \N*\n\n \N*\n \K # first line
15 (?: (?: ^=over .*? ^=back\n )? (?!=) \N*\n )*
16 }{\n}g; # abbreviate options
17 $pod =~ s/[.,](?=\n)//g; # trailing punctuation
18 $pod =~ s/^=item\ \K(?=--)/____/g; # align long options
19 # abbreviate <variable> indicators
20 $pod =~ s/\Q>.../s>/g;
21 $pod =~ s/<(?:number|count|seconds)>/N/g;
22 $pod =~ s/<character(s?)>/\Uchar$1/g;
24 $pod =~ s/(?<!\w)<([a-z]+)>/\U$1/g; # uppercase
27 my $parser = Pod::Usage->new(USAGE_OPTIONS => {
28 -indent => 2, -width => 78,
30 $parser->select('SYNOPSIS', 'OPTIONS');
31 $parser->output_string(\my $usage);
32 $parser->parse_string_document($pod);
34 $usage =~ s/\n(?=\n\h)//msg; # strip space between items
35 $usage =~ s/^\ \ \K____/ /g; # nbsp substitute
38 # custom formatted minimal usage text from pod document
41 elsif (open my $rewrite, '>', $ARGV) {
42 # replace perl code between program end and pod start
43 $source =~ s/^__END__\n \K .*? (?=^=)/$usage/;
44 print {$rewrite} $source;