3
3
use 5.038002;
4
4
use warnings;
5
5
6
- our $VERSION = " 0.02 - 20250103 " ;
6
+ our $VERSION = " 0.03 - 20250106 " ;
7
7
our $CMD = $0 =~ s { .*/} {} r ;
8
8
9
9
sub usage {
@@ -12,6 +12,7 @@ sub usage {
12
12
exit $err ;
13
13
} # usage
14
14
15
+ use Pod::Text;
15
16
use File::Find;
16
17
use List::Util qw( first ) ;
17
18
use Encode qw( encode decode ) ;
@@ -26,7 +27,7 @@ sub usage {
26
27
-d " doc" or mkdir " doc" , 0775;
27
28
28
29
my @pm ; # Do *NOT* scan t/
29
- find (sub { m /\. pm$ / and push @pm => $File::Find::name }, " lib" );
30
+ -d " lib " and find (sub { m /\. pm$ / and push @pm => $File::Find::name }, " lib" );
30
31
@pm or @pm = sort glob " *.pm" ;
31
32
if (@pm == 0 and open my $fh , " <" , " Makefile.PL" ) {
32
33
my @mpl = <$fh >;
@@ -41,6 +42,7 @@ sub usage {
41
42
}
42
43
}
43
44
45
+ push @pm => @ARGV ;
44
46
@pm = sort grep { ! -l $_ } @pm ;
45
47
@pm or die " No documentation source files found\n " ;
46
48
@@ -49,26 +51,56 @@ sub usage {
49
51
say " $_ " for @pm ;
50
52
}
51
53
54
+ sub dext {
55
+ my ($pm , $ext ) = @_ ;
56
+ my $fn = $pm =~ s { ^lib/} {} r
57
+ =~ s { ^(?:App|scripts|examples)/} {} r
58
+ =~ s { /} { -} gr
59
+ =~ s { (?:\. pm)?$} { .$ext } r # examples, scripts
60
+ =~ s { ^(?=CSV_XS\. )} { Text-} r
61
+ =~ s { ^(?=Peek\. )} { Data-} r
62
+ =~ s { ^(?=Read\. )} { Spreadsheet-} r
63
+ =~ s { ^(SpeedTest)} { \L $1 } ri
64
+ =~ s { ^} { doc/} r ;
65
+ $fn ;
66
+ } # dext
67
+
52
68
my %enc ;
69
+ my %pod ;
70
+ { # Check if file had pod at all
71
+ foreach my $pm (@pm ) {
72
+ open my $fh , " >" , \$pod {$pm };
73
+ Pod::Text-> new-> parse_from_file ($pm , $fh );
74
+ close $fh ;
75
+ }
76
+ }
77
+
53
78
eval { require Pod::Checker; };
54
79
if ($@ ) {
55
80
warn " Cannot convert pod to markdown: $@ \n " ;
56
81
}
57
82
else {
58
83
my $fail = 0;
84
+ my %ignore_empty = (
85
+ " lib/DBI/ProfileData.pm" => 7,
86
+ " Peek.pm" => 4,
87
+ " Read.pm" => 5,
88
+ );
59
89
foreach my $pm (@pm ) {
60
90
open my $eh , " >" , \my $err ;
61
91
my $pc = Pod::Checker-> new ();
62
92
my $ok = $pc -> parse_from_file ($pm , $eh );
63
93
close $eh ;
64
94
$enc {$pm } = $pc -> {encoding };
65
95
$err && $err =~ m /\S / or next ;
66
- if ($pm eq " lib/DBI/ProfileData.pm" ) {
67
- # DBI::Profile has 7 warnings on empty previous paragraphs
68
- # as it uses =head2 for all possible invocation alternatives
69
- # Ignore these warnings if those are all
70
- my @err = grep m / WARNING: / => split m /\n +/ => $err ;
71
- @err == 7 && $err eq join " \n " => @err , " " and next ;
96
+ # Ignore warnings here on empty previous paragraphs as it
97
+ # uses =head2 for all possible invocation alternatives
98
+ if (my $ni = $ignore_empty {$pm }) {
99
+ my $pat = qr { WARNING: empty section } ;
100
+ my @err = split m /\n +/ => $err ;
101
+ my @wrn = grep m /$pat / => @err ;
102
+ @wrn == $ni and $err = join " \n " => grep !m /$pat / => @err ;
103
+ $err =~ m /\S / or next ;
72
104
}
73
105
say $pm ;
74
106
say $err ;
@@ -83,10 +115,9 @@ sub usage {
83
115
}
84
116
else {
85
117
foreach my $pm (@pm ) {
86
- my $md = $pm =~ s { ^lib/(?:App/)?} {} r =~ s { /} { -} gr =~ s {\. pm$} { .md} r =~ s { ^} { doc/} r ;
87
- printf STDERR " %-43s <- %s \n " , $md , $pm if $opt_v ;
118
+ my $md = dext ($pm , " md" );
88
119
my $enc = $enc {$pm } ? " encoding($enc {$pm })" : " bytes" ;
89
- say " $pm ( $enc ) " if $opt_v > 1 ;
120
+ printf STDERR " %-43s <- %s ( %s ) \n " , $md , $pm , $enc if $opt_v ;
90
121
open my $ph , " <:$enc " , $pm ;
91
122
my $p = Pod::Markdown-> new ();
92
123
$p -> output_string (\my $m );
@@ -111,8 +142,9 @@ sub usage {
111
142
}
112
143
else {
113
144
foreach my $pm (@pm ) {
114
- my $html = $pm =~ s { ^lib/(?:App/)?} {} r =~ s { /} { -} gr =~ s {\. pm$} { .html} r =~ s { ^} { doc/} r ;
115
- printf STDERR " %-43s <- %s \n " , $html , $pm if $opt_v ;
145
+ $pod {$pm } or next ; # Skip HTML for files without pod
146
+ my $html = dext ($pm , " html" );
147
+ printf STDERR " %-43s <- %s (%s )\n " , $html , $pm , $enc {$pm } // " -" if $opt_v ;
116
148
my $tf = " x_$$ .html" ;
117
149
unlink $tf if -e $tf ;
118
150
Pod::Html::pod2html (" --infile=$pm " , " --outfile=$tf " , " --quiet" );
@@ -142,7 +174,7 @@ sub usage {
142
174
split m / :+/ => $ENV {PATH };
143
175
$opt_v and say $nrf ;
144
176
foreach my $pm (@pm ) {
145
- my $man = $pm =~ s { ^lib/(?:App/)? } {} r =~ s { / } { - } gr =~ s { \. pm$ } { .3 } r =~ s { ^ } { doc/ } r ;
177
+ my $man = dext ( $pm , " 3 " ) ;
146
178
printf STDERR " %-43s <- %s \n " , $man , $pm if $opt_v ;
147
179
open my $fh , " >" , \my $p ;
148
180
Pod::Man-> new (section => 3)-> parse_from_file ($pm , $fh );
@@ -171,6 +203,7 @@ sub usage {
171
203
|\x{201d} |\xe2\x80\x9d )} { "} grx # "
172
204
=~ s { (?:\x{2212} |\xe2\x88\x92
173
205
|\x{2010} |\xe2\x80\x90 )} { -} grx # -
206
+ =~ s { (?:\x{2022} |\xe2\x80\xa2 )} { *} grx # BULLET
174
207
=~ s { (?:\e\[ |\x9b )[0-9;]*m} {} grx ); # colors
175
208
}
176
209
@@ -181,7 +214,8 @@ sub usage {
181
214
}
182
215
$opt_v and say " Writing $mfn (" , length $p , " )" ;
183
216
open $oh , " >:encoding(utf-8)" , $mfn or die " $mfn : $! \n " ;
184
- print $oh $p ;
217
+ # nroff / troff / grotty cause double-encoding
218
+ print $oh encode (" iso-8859-1" , decode (" utf-8" , $p ));
185
219
close $oh ;
186
220
}
187
221
}
0 commit comments