5 use feature 'unicode_strings';
15 require '../regen/regen_lib.pl';
24 podcheck.t - Look for possible problems in the Perl pods
29 ./perl -I../lib porting/podcheck.t [--show_all] [--cpan] [--deltas]
30 [--counts] [ FILE ...]
31 ./perl -I../lib porting/podcheck.t --add_link MODULE ...
33 ./perl -I../lib porting/podcheck.t --regen
37 podcheck.t is an extension of Pod::Checker. It looks for pod errors and
38 potential errors in the files given as arguments, or if none specified, in all
39 pods in the distribution workspace, except certain known special ones
40 (specified below). It does additional checking beyond that done by
41 Pod::Checker, and keeps a database of known potential problems, and will
42 fail a pod only if the number of such problems differs from that given in the
43 database. It also suppresses the C<(section) deprecated> message from
44 Pod::Checker, since specifying the man page section number is quite proper to do.
46 The additional checks it makes are:
50 =item Cross-pod link checking
52 Pod::Checker verifies that links to an internal target in a pod are not
53 broken. podcheck.t extends that (when called without FILE arguments) to
54 external links. It does this by gathering up all the possible targets in the
55 workspace, and cross-checking them. It also checks that a non-broken link
56 points to just one target. (The destination pod could have two targets with
59 The way that the C<LE<lt>E<gt>> pod command works (for links outside the pod)
60 is to actually create a link to C<search.cpan.org> with an embedded query for
61 the desired pod or man page. That means that links outside the distribution
62 are valid. podcheck.t doesn't verify the validity of such links, but instead
63 keeps a data base of those known to be valid. This means that if a link to a
64 target not on the list is created, the target needs to be added to the data
65 base. This is accomplished via the L<--add_link|/--add_link MODULE ...>
66 option to podcheck.t, described below.
68 =item An internal link that isn't so specified
70 If a link is broken, but there is an existing internal target of the same
71 name, it is likely that the internal target was meant, and the C<"/"> is
72 missing from the C<LE<lt>E<gt>> pod command.
74 =item Verbatim paragraphs that wrap in an 80 (including 1 spare) column window
76 It's annoying to have lines wrap when displaying pod documentation in a
77 terminal window. This checks that all verbatim lines fit in a standard 80
78 column window, even when using a pager that reserves a column for its own use.
79 (Thus the check is for a net of 79 columns.)
80 For those that lines that don't fit, it tells you how much needs to be cut in
83 Often, the easiest thing to do to gain space for these is to lower the indent
86 =item Missing or duplicate NAME or missing NAME short description
88 A pod can't be linked to unless it has a unique name.
89 And a NAME should have a dash and short description after it.
91 =item =encoding statement issues
93 This indicates if an C<=encoding> statement should be present, or moved to the
96 =item Items that perhaps should be links
98 There are mentions of apparent files in the pods that perhaps should be links
99 instead, using C<LE<lt>...E<gt>>
101 =item Items that perhaps should be C<FE<lt>...E<gt>>
103 What look like path names enclosed in C<CE<lt>...E<gt>> should perhaps have
104 C<FE<lt>...E<gt>> mark-up instead.
108 A number of issues raised by podcheck.t and by the base Pod::Checker are not
109 really problems, but merely potential problems, that is, false positives.
110 After inspecting them and
111 deciding that they aren't real problems, it is possible to shut up this program
112 about them, unlike base Pod::Checker. To do this, call podcheck.t with the
113 C<--regen> option to regenerate the database. This tells it that all existing
114 issues are to not be mentioned again.
116 This isn't fool-proof. The database merely keeps track of the number of these
117 potential problems of each type for each pod. If a new problem of a given
118 type is introduced into the pod, podcheck.t will spit out all of them. You
119 then have to figure out which is the new one, and should it be changed or not.
120 But doing it this way insulates the database from having to keep track of line
121 numbers of problems, which may change, or the exact wording of each problem
122 which might also change without affecting whether it is a problem or not.
124 Also, if the count of potential problems of a given type for a pod decreases,
125 the database must be regenerated so that it knows the new number. The program
126 gives instructions when this happens.
128 Some pods will have varying numbers of problems of a given type. This can
129 be handled by manually editing the database file (see L</FILES>), and setting
130 the number of those problems for that pod to a negative number. This will
131 cause the corresponding error to always be suppressed no matter how many there
134 There is currently no check that modules listed as valid in the data base
135 actually are. Thus any errors introduced there will remain there.
137 =head2 Specially handled pods
143 This pod is generated by pasting bits from other pods. Errors in those bits
144 will show up as errors here, as well as for those other pods. Therefore
145 errors here are suppressed, and the pod is checked only to verify that nodes
146 within it that are externally linked to actually exist.
150 The current perldelta pod is initialized from a template that contains
151 placeholder text. Some of this text is in the form of links that don't really
152 exist. Any such links that are listed in C<@perldelta_ignore_links> will not
153 generate messages. It is presumed that these links will be cleaned up when
154 the perldelta is cleaned up for release since they should be marked with
157 =item Porting/perldelta_template.pod
159 This is not a pod, but a template for C<perldelta>. Any errors introduced
160 here will show up when C<perldelta> is created from it.
162 =item cpan-upstream pods
164 See the L</--cpan> option documentation
168 See the L</--deltas> option documentation
176 =item --add_link MODULE ...
178 Use this option to teach podcheck.t that the C<MODULE>s or man pages actually
179 exist, and to silence any messages that links to them are broken.
181 podcheck.t checks that links within the Perl core distribution are valid, but
182 it doesn't check links to man pages or external modules. When it finds
183 a broken link, it checks its data base of external modules and man pages,
184 and only if not found there does it raise a message. This option just adds
185 the list of modules and man page references that follow it on the command line
191 ./perl -I../lib porting/podcheck.t --add_link Unicode::Casing
193 causes the external module "Unicode::Casing" to be added to the data base, so
194 C<LE<lt>Unicode::Casing<gt>> will be considered valid.
198 Regenerate the data base used by podcheck.t to include all the existing
199 potential problems. Future runs of the program will not then flag any of
204 Normally, all pods in the cpan directory are skipped, except to make sure that
205 any blead-upstream links to such pods are valid.
206 This option will cause cpan upstream pods to be fully checked.
210 Normally, all old perldelta pods are skipped, except to make sure that
211 any links to such pods are valid. This is because they are considered
212 stable, and perhaps trying to fix them will cause changes that will
213 misrepresent Perl's history. But, this option will cause them to be fully
218 Normally, if the number of potential problems of a given type found for a
219 pod matches the expected value in the database, they will not be displayed.
220 This option forces the database to be ignored during the run, so all potential
221 problems are displayed and will fail their respective pod test. Specifying
222 any particular FILES to operate on automatically selects this option.
226 Instead of testing, this just dumps the counts of the occurrences of the
227 various types of potential problems in the data base.
233 The database is stored in F<t/porting/known_pod_issues.dat>
241 #####################################################
242 # HOW IT WORKS (in general)
244 # If not called with specific files to check, the directory structure is
245 # examined for files that have pods in them. Files that might not have to be
246 # fully parsed (e.g. in cpan) are parsed enough at this time to find their
247 # pod's NAME, and to get a checksum.
249 # Those kinds of files are sorted last, but otherwise the pods are parsed with
250 # the package coded here, My::Pod::Checker, which is an extension to
251 # Pod::Checker that adds some tests and suppresses others that aren't
252 # appropriate. The latter module has no provision for capturing diagnostics,
253 # so a package, Tie_Array_to_FH, is used to force them to be placed into an
254 # array instead of printed.
256 # Parsing the files builds up a list of links. The files are gone through
257 # again, doing cross-link checking and outputting all saved-up problems with
260 # Sorting the files last that potentially don't need to be fully parsed allows
261 # us to not parse them unless there is a link to an internal anchor in them
262 # from something that we have already parsed. Keeping checksums allows us to
263 # not parse copies of other pods.
265 #####################################################
267 # 1 => Exclude low priority messages that aren't likely to be problems, and
268 # has many false positives; higher numbers give more messages.
269 my $Warnings_Level = 200;
271 # perldelta during construction may have place holder links.
272 our @perldelta_ignore_links = ( "XXX", "perl5YYYdelta", "perldiag/message" );
274 # To see if two pods with the same NAME are actually copies of the same pod,
275 # which is not an error, it uses a checksum to save work.
276 my $digest_type = "SHA-1";
278 my $original_dir = File::Spec->rel2abs(File::Spec->curdir);
279 my $data_dir = File::Spec->catdir($original_dir, 'porting');
280 my $known_issues = File::Spec->catfile($data_dir, 'known_pod_issues.dat');
283 my $MAX_LINE_LENGTH = 79; # 79 columns
284 my $INDENT = 7; # default nroff indent
286 # Our warning messages. Better not have [('"] in them, as those are used as
287 # delimiters for variable parts of the messages by poderror.
288 my $line_length = "Verbatim line length including indents exceeds $MAX_LINE_LENGTH by";
289 my $broken_link = "Apparent broken link";
290 my $broken_internal_link = "Apparent internal link is missing its forward slash";
291 my $see_not_linked = "? Should you be using L<...> instead of";
292 my $C_with_slash = "? Should you be using F<...> or maybe L<...> instead of";
293 my $multiple_targets = "There is more than one target";
294 my $duplicate_name = "Pod NAME already used";
295 my $need_encoding = "Should have =encoding statement because have non-ASCII";
296 my $encoding_first = "=encoding must be first command (if present)";
297 my $no_name = "There is no NAME";
298 my $missing_name_description = "The NAME should have a dash and short description after it";
300 # objects, tests, etc can't be pods, so don't look for them. Also skip
301 # files output by the patch program. Could also ignore most of .gitignore
302 # files, but not all, so don't.
303 my $non_pods = qr/ (?: \.
304 (?: [achot] | zip | gz | bz2 | jar | tar | tgz | PL | so
305 | orig | rej | patch # Patch program output
306 | sw[op] | \#.* # Editor droppings
307 | old # buildtoc output
310 ) | ~$ | \ \(Autosaved\)\.txt$ # Other editor droppings
314 # Pod::Checker messages to suppress
315 my @suppressed_messages = (
316 "(section) in", # Checker is wrong to flag this
317 "multiple occurrence of link target", # We catch independently the ones
318 # that are real problems.
320 "Entity number out of range", # Checker outputs this for anything above
321 # 255, and all Unicode is valid
325 # Returns bool as to if input message is one that is to be suppressed
328 return grep { $message =~ /^\Q$_/i } @suppressed_messages;
331 { # Closure to contain a simple subset of test.pl. This is to get rid of the
332 # unnecessary 'failed at' messages that would otherwise be output pointing
333 # to a particular line in this file.
335 my $current_test = 0;
340 $planned = $plan{tests};
341 print "1..$planned\n";
352 print "not " unless $success;
353 print "ok $current_test - $message\n";
359 my $n = @_ ? shift : 1;
362 print "ok $current_test # skip $why\n";
364 no warnings 'exiting';
373 print $message =~ s/^/# /mgr;
379 if ($planned && $planned != $current_test) {
381 "# Looks like you planned $planned tests but ran $current_test.\n";
386 # This is to get this to work across multiple file systems, including those
387 # that are not case sensitive. The db is stored in lower case, Un*x style,
388 # and all file name comparisons are done that way.
389 sub canonicalize($) {
391 my ($volume, $directories, $file)
392 = File::Spec->splitpath(File::Spec->canonpath($input));
393 # Assumes $volume is constant for everything in this directory structure
394 $directories = "" if ! $directories;
395 $file = "" if ! $file;
396 my $output = lc join '/', File::Spec->splitdir($directories), $file;
397 $output =~ s! / /+ !/!gx; # Multiple slashes => single slash
402 # List of known potential problems by pod and type.
405 # Pods given by the keys contain an interior node that is referred to from
407 my %has_referred_to_node;
414 my $do_upstream_cpan = 0; # Assume that are to skip anything in /cpan
415 my $do_deltas = 0; # And stable perldeltas
417 while (@ARGV && substr($ARGV[0], 0, 1) eq '-') {
418 my $arg = shift @ARGV;
420 $arg =~ s/^--/-/; # Treat '--' the same as a single '-'
421 if ($arg eq '-regen') {
424 elsif ($arg eq '-add_link') {
427 elsif ($arg eq '-cpan') {
428 $do_upstream_cpan = 1;
430 elsif ($arg eq '-deltas') {
433 elsif ($arg eq '-show_all') {
436 elsif ($arg eq '-counts') {
441 Unknown option '$arg'
443 Usage: $0 [ --regen | --cpan | --show_all | FILE ... | --add_link MODULE ... ]\n"
444 --add_link -> Add the MODULE and man page references to the data base
445 --regen -> Regenerate the data file for $0
446 --cpan -> Include files in the cpan subdirectory.
447 --deltas -> Include stable perldeltas
448 --show_all -> Show all known potential problems
449 --counts -> Don't test, but give summary counts of the currently
457 my $cpan_or_deltas = $do_upstream_cpan || $do_deltas;
458 if (($regen + $show_all + $show_counts + $add_link + $cpan_or_deltas ) > 1) {
459 croak "--regen, --show_all, --counts, and --add_link are mutually exclusive\n and none can be run with --cpan nor --deltas";
462 my $has_input_files = @files;
465 && ($regen || $show_counts || $do_upstream_cpan || $do_deltas))
467 croak "--regen, --counts, --deltas, and --cpan can't be used since using specific files";
470 if ($add_link && ! $has_input_files) {
471 croak "--add_link requires at least one module or man page reference";
474 our %problems; # potential problems found in this run
476 package My::Pod::Checker { # Extend Pod::Checker
477 use parent 'Pod::Checker';
479 # Uses inside out hash to protect from typos
480 # For new fields, remember to add to destructor DESTROY()
481 my %indents; # Stack of indents from =over's in effect for
483 my %current_indent; # Current line's indent
484 my %filename; # The pod is store in this file
485 my %skip; # is SKIP set for this pod
486 my %in_NAME; # true if within NAME section
487 my %in_begin; # true if within =begin section
488 my %linkable_item; # Bool: if the latest =item is linkable. It isn't
489 # for bullet and number lists
490 my %linkable_nodes; # Pod::Checker adds all =items to its node list,
491 # but not all =items are linkable to
492 my %seen_encoding_cmd; # true if have =encoding earlier
493 my %command_count; # Number of commands seen
494 my %seen_pod_cmd; # true if have =pod earlier
495 my %warned_encoding; # true if already have warned about =encoding
499 my $addr = Scalar::Util::refaddr $_[0];
500 delete $command_count{$addr};
501 delete $current_indent{$addr};
502 delete $filename{$addr};
503 delete $in_begin{$addr};
504 delete $indents{$addr};
505 delete $in_NAME{$addr};
506 delete $linkable_item{$addr};
507 delete $linkable_nodes{$addr};
508 delete $seen_encoding_cmd{$addr};
509 delete $seen_pod_cmd{$addr};
511 delete $warned_encoding{$addr};
517 my $filename = shift;
519 my $self = $class->SUPER::new(-quiet => 1,
520 -warnings => $Warnings_Level);
521 my $addr = Scalar::Util::refaddr $self;
522 $command_count{$addr} = 0;
523 $current_indent{$addr} = 0;
524 $filename{$addr} = $filename;
525 $in_begin{$addr} = 0;
527 $linkable_item{$addr} = 0;
528 $seen_encoding_cmd{$addr} = 0;
529 $seen_pod_cmd{$addr} = 0;
530 $warned_encoding{$addr} = 0;
534 # re's for messages that Pod::Checker outputs
535 my $location = qr/ \b (?:in|at|on|near) \s+ /xi;
536 my $optional_location = qr/ (?: $location )? /xi;
537 my $line_reference = qr/ [('"]? $optional_location \b line \s+
538 (?: \d+ | EOF | \Q???\E | - )
541 sub poderror { # Called to register a potential problem
543 # This adds an extra field to the parent hash, 'parameter'. It is
544 # used to extract the variable parts of a message leaving just the
545 # constant skeleton. This in turn allows the message to be
546 # categorized better, so that it shows up as a single type in our
547 # database, with the specifics of each occurrence not being stored with
553 my $addr = Scalar::Util::refaddr $self;
554 return if $skip{$addr};
556 # Input can be a string or hash. If a string, parse it to separate
557 # out the line number and convert to a hash for easier further
560 if (ref $opts ne 'HASH') {
561 $message = join "", $opts, @_;
563 if ($message =~ s/\s*($line_reference)//) {
564 ($line_number = $1) =~ s/\s*$optional_location//;
567 $line_number = '???';
569 $opts = { -msg => $message, -line => $line_number };
571 $message = $opts->{'-msg'};
575 $message =~ s/^\d+\s+//;
576 return if main::suppressed($message);
578 $self->SUPER::poderror($opts, @_);
580 $opts->{parameter} = "" unless $opts->{parameter};
582 # The variable parts of the message tend to be enclosed in '...',
583 # "....", or (...). Extract them and put them in an extra field,
584 # 'parameter'. This is trickier because the matching delimiter to a
585 # '(' is its mirror, and not itself. Text::Balanced could be used
587 while ($message =~ m/ \s* $optional_location ( [('"] )/xg) {
590 $delimiter = ')' if $delimiter eq '(';
592 # If there is no ending delimiter, don't consider it to be a
593 # variable part. Most likely it is a contraction like "Don't"
594 last unless $message =~ m/\G .+? \Q$delimiter/xg;
596 my $length = $+[0] - $start;
598 # Get the part up through the closing delimiter
599 my $special = substr($message, $start, $length);
600 $special =~ s/^\s+//; # No leading whitespace
602 # And add that variable part to the parameter, while removing it
603 # from the message. This isn't a foolproof way of finding the
604 # variable part. For example '(s)' can occur in e.g.,
606 if ($special ne '(s)') {
607 substr($message, $start, $length) = "";
608 pos $message = $start;
609 $opts->{-msg} = $message;
610 $opts->{parameter} .= " " if $opts->{parameter};
611 $opts->{parameter} .= $special;
615 # Extract any additional line number given. This is often the
616 # beginning location of something whereas the main line number gives
618 if ($message =~ /( $line_reference )/xi) {
620 while ($message =~ s/\s*\Q$line_ref//) {
621 $opts->{-msg} = $message;
622 $opts->{parameter} .= " " if $opts->{parameter};
623 $opts->{parameter} .= $line_ref;
627 Carp::carp("Couldn't extract line number from '$message'") if $message =~ /line \d+/;
628 push @{$problems{$filename{$addr}}{$message}}, $opts;
629 #push @{$problems{$self->get_filename}{$message}}, $opts;
632 sub check_encoding { # Does it need an =encoding statement?
633 my ($self, $paragraph, $line_num, $pod_para) = @_;
635 # Do nothing if there is an =encoding in the file, or if the line
636 # doesn't require an =encoding, or have already warned.
637 my $addr = Scalar::Util::refaddr $self;
638 return if $seen_encoding_cmd{$addr}
639 || $warned_encoding{$addr}
640 || $paragraph !~ /\P{ASCII}/;
642 $warned_encoding{$addr} = 1;
643 my ($file, $line) = $pod_para->file_line;
644 $self->poderror({ -line => $line, -file => $file,
645 -msg => $need_encoding
651 my ($self, $paragraph, $line_num, $pod_para) = @_;
652 $self->check_encoding($paragraph, $line_num, $pod_para);
654 $self->SUPER::verbatim($paragraph, $line_num, $pod_para);
656 my $addr = Scalar::Util::refaddr $self;
658 # Pick up the name, since the parent class doesn't in verbatim
659 # NAMEs; so treat as non-verbatim. The parent class only allows one
660 # paragraph in a NAME section, so if there is an extra blank line, it
661 # will trigger a message, but such a blank line is harmless, so skip
663 if ($in_NAME{$addr} && $paragraph =~ /\S/) {
664 $self->textblock($paragraph, $line_num, $pod_para);
667 my @lines = split /^/, $paragraph;
668 for my $i (0 .. @lines - 1) {
669 if ( my $encoding = $seen_encoding_cmd{$addr} ) {
671 $lines[$i] = Encode::decode($encoding, $lines[$i]);
673 $lines[$i] =~ s/\s+$//;
674 my $indent = $self->get_current_indent;
675 my $exceeds = length(Text::Tabs::expand($lines[$i]))
676 + $indent - $MAX_LINE_LENGTH;
677 next unless $exceeds > 0;
678 my ($file, $line) = $pod_para->file_line;
679 $self->poderror({ -line => $line + $i, -file => $file,
680 -msg => $line_length,
681 parameter => "+$exceeds (including " . ($indent - $INDENT) . " from =over's)",
687 my ($self, $paragraph, $line_num, $pod_para) = @_;
688 $self->check_encoding($paragraph, $line_num, $pod_para);
690 $self->SUPER::textblock($paragraph, $line_num, $pod_para);
692 my ($file, $line) = $pod_para->file_line;
693 my $addr = Scalar::Util::refaddr $self;
694 if ($in_NAME{$addr}) {
696 my $text = $self->interpolate($paragraph, $line_num);
697 if ($text =~ /^\s*(\S+?)\s*$/) {
699 $self->poderror({ -line => $line, -file => $file,
700 -msg => $missing_name_description,
705 $paragraph = join " ", split /^/, $paragraph;
707 # Matches something that looks like a file name, but is enclosed in
709 my $C_path_re = qr{ \b ( C<
710 # exclude various things that have slashes
711 # in them but aren't paths
713 (?: (?: s | qr | m) / ) # regexes
714 | \d+/\d+> # probable fractions
719 | - # File names don't begin with "-"
721 [-\w]+ (?: / [-\w]+ )+ (?: \. \w+ )? > )
724 # If looks like a reference to other documentation by containing the
725 # word 'See' and then a likely pod directive, warn.
726 while ($paragraph =~ m{
727 ( (?: \w+ \s+ )* ) # The phrase before, if any
731 ( [^<]*? ) # The not < excludes nested C<L<...
734 ( \s+ (?: under | in ) \s+ L< )?
736 my $prefix = $1 // "";
737 my $construct = $2; # The whole thing, like C<...>
740 my $trailing = $5; # After the whole thing ending in "L<"
742 # If the full phrase is something like, "you might see C<", or
743 # similar, it really isn't a reference to a link. The ones I saw
744 # all had the word "you" in them; and the "you" wasn't the
745 # beginning of a sentence.
746 if ($prefix !~ / \b you \b /x) {
748 # Now, find what the module or man page name within the
749 # construct would be if it actually has L<> syntax. If it
750 # doesn't have that syntax, will set the module to the entire
753 (?: [^|]+ \| )? # Optional arbitrary text ending
755 ( .+? ) # module, etc. name
756 (?: \/ .+ )? # target within module
760 if (! defined $trailing # not referring to something in another
762 && $interior !~ /$non_pods/
764 # C<> that look like files have their own message below, so
766 && $construct !~ /$C_path_re/g
768 # There can't be spaces (I think) in module names or man
770 && $module !~ / \s /x
772 # F<> that end in eg \.pl are almost certainly ok, as are
773 # those that look like a path with multiple "/" chars
776 && $interior !~ /\.\w+$/
777 && $interior !~ /\/.+\//)
780 $self->poderror({ -line => $line, -file => $file,
781 -msg => $see_not_linked,
782 parameter => $construct
787 while ($paragraph =~ m/$C_path_re/g) {
789 $self->poderror({ -line => $line, -file => $file,
790 -msg => $C_with_slash,
791 parameter => $construct
798 my ($self, $cmd, $paragraph, $line_num, $pod_para) = @_;
799 my $addr = Scalar::Util::refaddr $self;
801 $seen_pod_cmd{$addr}++;
803 elsif ($cmd eq "encoding") {
804 my ($file, $line) = $pod_para->file_line;
805 $seen_encoding_cmd{$addr} = $paragraph; # for later decoding
806 if ($command_count{$addr} != 1 && $seen_pod_cmd{$addr}) {
807 $self->poderror({ -line => $line, -file => $file,
808 -msg => $encoding_first
812 $self->check_encoding($paragraph, $line_num, $pod_para);
814 # Pod::Check treats all =items as linkable, but the bullet and
815 # numbered lists really aren't. So keep our own list. This has to be
816 # processed before SUPER is called so that the list is started before
817 # the rest of it gets parsed.
818 if ($cmd eq 'item') { # Not linkable if item begins with * or a digit
819 $linkable_item{$addr} = ($paragraph !~ / ^ \s*
821 | \d+ \.? (?: \$ | \s+ )
827 $self->SUPER::command($cmd, $paragraph, $line_num, $pod_para);
829 $command_count{$addr}++;
831 $in_NAME{$addr} = 0; # Will change to 1 below if necessary
832 $in_begin{$addr} = 0; # ibid
833 if ($cmd eq 'over') {
834 my $text = $self->interpolate($paragraph, $line_num);
835 my $indent = 4; # default
836 $indent = $1 if $text && $text =~ /^\s*(\d+)\s*$/;
837 push @{$indents{$addr}}, $indent;
838 $current_indent{$addr} += $indent;
840 elsif ($cmd eq 'back') {
841 if (@{$indents{$addr}}) {
842 $current_indent{$addr} -= pop @{$indents{$addr}};
845 # =back without corresponding =over, but should have
847 $current_indent{$addr} = 0;
850 elsif ($cmd =~ /^head/) {
851 if (! $in_begin{$addr}) {
853 # If a particular formatter, then this command doesn't really
855 $current_indent{$addr} = 0;
856 undef @{$indents{$addr}};
859 my $text = $self->interpolate($paragraph, $line_num);
860 $in_NAME{$addr} = 1 if $cmd eq 'head1'
861 && $text && $text =~ /^NAME\b/;
863 elsif ($cmd eq 'begin') {
864 $in_begin{$addr} = 1;
874 if ($_[0] && ($page = $_[0][1]{'-page'})) {
875 my $node = $_[0][1]{'-node'};
877 # If the hyperlink is to an interior node of another page, save it
878 # so that we can see if we need to parse normally skipped files.
879 $has_referred_to_node{$page} = 1 if $node;
881 # Ignore certain placeholder links in perldelta. Check if the
882 # link is page-level, and also check if to a node within the page
883 if ($self->name && $self->name eq "perldelta"
884 && ((grep { $page eq $_ } @perldelta_ignore_links)
886 && (grep { "$page/$node" eq $_ } @perldelta_ignore_links)
891 return $self->SUPER::hyperlink($_[0]);
898 $text =~ s/\s+$//s; # strip trailing whitespace
899 $text =~ s/\s+/ /gs; # collapse whitespace
900 my $addr = Scalar::Util::refaddr $self;
901 push(@{$linkable_nodes{$addr}}, $text) if
902 ! $current_indent{$addr}
903 || $linkable_item{$addr};
905 return $self->SUPER::node($_[0]);
908 sub get_current_indent {
909 return $INDENT + $current_indent{Scalar::Util::refaddr $_[0]};
913 return $filename{Scalar::Util::refaddr $_[0]};
917 my $linkables = $linkable_nodes{Scalar::Util::refaddr $_[0]};
918 return undef unless $linkables;
923 return $skip{Scalar::Util::refaddr $_[0]} // 0;
928 $skip{Scalar::Util::refaddr $self} = shift;
930 # If skipping, no need to keep the problems for it
931 delete $problems{$self->get_filename};
936 package Tie_Array_to_FH { # So printing actually goes to an array
942 my $array_ref = shift;
944 my $self = bless \do{ my $anonymous_scalar }, $class;
945 $array{Scalar::Util::refaddr $self} = $array_ref;
952 push @{$array{Scalar::Util::refaddr $self}}, @_;
958 my %filename_to_checker; # Map a filename to it's pod checker object
959 my %id_to_checker; # Map a checksum to it's pod checker object
960 my %nodes; # key is filename, values are nodes in that file.
961 my %nodes_first_word; # same, but value is first word of each node
962 my %valid_modules; # List of modules known to exist outside us.
963 my %digests; # checksums of files, whose names are the keys
964 my %filename_to_pod; # Map a filename to its pod NAME
965 my %files_with_unknown_issues;
966 my %files_with_fixes;
969 open $data_fh, '<:bytes', $known_issues or die "Can't open $known_issues";
971 my %counts; # For --counts param, count of each issue type
972 my %suppressed_files; # Files with at least one issue type to suppress
974 # This file is the data file for $0.
975 # There are three types of lines.
976 # Comment lines are white-space only or begin with a '#', like this one. Any
977 # changes you make to the comment lines will be lost when the file is
979 # Lines without tab characters are simply NAMES of pods that the program knows
980 # will have links to them and the program does not check if those links are
982 # All other lines should have three fields, each separated by a tab. The
983 # first field is the name of a pod; the second field is an error message
984 # generated by this program; and the third field is a count of how many
985 # known instances of that message there are in the pod. -1 means that the
986 # program can expect any number of this type of message.
992 while (<$data_fh>) { # Read the data base
994 next if /^\s*(?:#|$)/; # Skip comment and empty lines
997 if ($add_link) { # The issues are saved and later output unchanged
998 push @existing_issues, $_;
1002 # Keep track of counts of each issue type for each file
1003 my ($filename, $message, $count) = split /\t/;
1004 $known_problems{$filename}{$message} = $count;
1007 if ($count < 0) { # -1 means to suppress this issue type
1008 $suppressed_files{$filename} = $filename;
1011 $counts{$message} += $count;
1015 else { # Lines without a tab are modules known to be valid
1016 $valid_modules{$_} = 1
1022 $copy_fh = open_new($known_issues);
1024 # Check for basic sanity, and add each command line argument
1025 foreach my $module (@files) {
1026 die "\"$module\" does not look like a module or man page"
1027 # Must look like (A or A::B or A::B::C ..., or foo(3C)
1028 if $module !~ /^ (?: \w+ (?: :: \w+ )* | \w+ \( \d \w* \) ) $/x;
1029 $valid_modules{$module} = 1
1031 my_safer_print($copy_fh, $HEADER);
1032 foreach (sort { lc $a cmp lc $b } keys %valid_modules) {
1033 my_safer_print($copy_fh, $_, "\n");
1036 # The rest of the db file is output unchanged.
1037 my_safer_print($copy_fh, join "\n", @existing_issues, "");
1039 close_and_rename($copy_fh);
1045 foreach my $message (sort keys %counts) {
1046 $total += $counts{$message};
1047 note(Text::Tabs::expand("$counts{$message}\t$message"));
1049 note("-----\n" . Text::Tabs::expand("$total\tknown potential issues"));
1050 if (%suppressed_files) {
1051 note("\nFiles that have all messages of at least one type suppressed:");
1052 note(join ",", keys %suppressed_files);
1058 # Not really pods, but can look like them.
1059 my %excluded_files = (
1060 "lib/unicore/mktables" => 1,
1061 "Porting/perldelta_template.pod" => 1,
1068 # Convert to more generic form.
1069 foreach my $file (keys %excluded_files) {
1070 delete $excluded_files{$file};
1071 $excluded_files{canonicalize($file)} = 1;
1074 # re to match files that are to be parsed only if there is an internal link
1075 # to them. It does not include cpan, as whether those are parsed depends
1076 # on a switch. Currently, only perltoc and the stable perldelta.pod's
1077 # are included. The latter all have characters between 'perl' and
1078 # 'delta'. (Actually the currently developed one matches as well, but
1079 # is a duplicate of perldelta.pod, so can be skipped, so fine for it to
1081 my $only_for_interior_links_re = qr/ ^ pod\/perltoc.pod $
1083 unless ($do_deltas) {
1084 $only_for_interior_links_re = qr/$only_for_interior_links_re |
1085 \b perl \d+ delta \. pod \b
1092 sub output_thanks ($$$$) { # Called when an issue has been fixed
1093 my $filename = shift;
1094 my $original_count = shift;
1095 my $current_count = shift;
1096 my $message = shift;
1098 $files_with_fixes{$filename} = 1;
1100 my $fixed_count = $original_count - $current_count;
1101 my $a_problem = ($fixed_count == 1) ? "a problem" : "multiple problems";
1102 my $another_problem = ($fixed_count == 1) ? "another problem" : "another set of problems";
1106 There were $original_count occurrences (now $current_count) in this pod of type
1111 There are no longer any problems found in this pod!
1118 Thanks for fixing $a_problem!
1120 Now you must teach $0 that this was fixed.
1125 Thanks for fixing $another_problem.
1134 sub my_safer_print { # print, with error checking for outputting to db
1135 my ($fh, @lines) = @_;
1137 if (! print $fh @lines) {
1138 my $save_error = $!;
1140 die "Write failure: $save_error";
1144 sub extract_pod { # Extracts just the pod from a file
1145 my $filename = shift;
1149 # Arrange for the output of Pod::Parser to be collected in an array we can
1150 # look at instead of being printed
1151 tie *ALREADY_FH, 'Tie_Array_to_FH', \@pod;
1152 open my $in_fh, '<:bytes', $filename
1154 # The file should already have been opened once to get here, so if
1155 # fails, just die. It's possible that a transitory file containing a
1156 # pod would get here, but not bothering to add code for that very
1158 or die "Can't open '$filename': $!\n";
1160 my $parser = Pod::Parser->new();
1161 $parser->parse_from_filehandle($in_fh, *ALREADY_FH);
1164 return join "", @pod
1167 my $digest = Digest->new($digest_type);
1170 # If $_ is a pod file, add it to the lists and do other prep work.
1173 # Don't look at files in directories that are for tests, nor those
1174 # beginning with a dot
1175 if ($_ eq 't' || $_ =~ /^\../) {
1176 $File::Find::prune = 1;
1181 return if $_ =~ /^\./; # No hidden Unix files
1182 return if $_ =~ $non_pods;
1184 my $filename = $File::Find::name;
1186 # Assumes that the path separator is exactly one character.
1187 $filename =~ s/^\..//;
1189 return if $excluded_files{canonicalize($filename)};
1194 if (! open $candidate, '<:bytes', $_) {
1196 # If a transitory file was found earlier, the open could fail
1197 # legitimately and we just skip the file; also skip it if it is a
1198 # broken symbolic link, as it is probably just a build problem;
1199 # certainly not a file that we would want to check the pod of.
1200 # Otherwise fail it here and no reason to process it further.
1201 # (But the test count will be off too)
1202 ok(0, "Can't open '$filename': $!")
1203 if -e $filename && ! -l $filename;
1209 # If the file is a .pm or .pod, having any initial '=' on a line is
1210 # grounds for testing it. Otherwise, require a head1 NAME line to view it
1211 # as a potential pod
1212 if ($filename =~ /\.(?:pm|pod)/) {
1213 return unless $contents =~ /^=/m;
1215 return unless $contents =~ /^=head1 +NAME/m;
1218 # Here, we know that the file is a pod. Add it to the list of files
1219 # to check and create a checker object for it.
1221 push @files, $filename;
1222 my $checker = My::Pod::Checker->new($filename);
1223 $filename_to_checker{$filename} = $checker;
1225 # In order to detect duplicate pods and only analyze them once, we
1226 # compute checksums for the file, so don't have to do an exact
1227 # compare. Note that if the pod is just part of the file, the
1228 # checksums can differ for the same pod. That special case is handled
1229 # later, since if the checksums of the whole file are the same, that
1230 # case won't even come up. We don't need the checksums for files that
1231 # we parse only if there is a link to its interior, but we do need its
1232 # NAME, which is also retrieved in the code below.
1234 if ($filename =~ / (?: ^(cpan|lib|ext|dist)\/ )
1235 | $only_for_interior_links_re
1237 $digest->add($contents);
1238 $digests{$filename} = $digest->digest;
1240 # lib files aren't analyzed if they are duplicates of files copied
1241 # there from some other directory. But to determine this, we need
1242 # to know their NAMEs. We might as well find the NAME now while
1243 # the file is open. Similarly, cpan files aren't analyzed unless
1244 # we're analyzing all of them, or this particular file is linked
1245 # to by a file we are analyzing, and thus we will want to verify
1246 # that the target exists in it. We need to know at least the NAME
1247 # to see if it's worth analyzing, or so we can determine if a lib
1248 # file is a copy of a cpan one.
1249 if ($filename =~ m{ (?: ^ (?: cpan | lib ) / )
1250 | $only_for_interior_links_re
1252 if ($contents =~ /^=head1 +NAME.*/mg) {
1253 # The NAME is the first non-spaces on the line up to a
1254 # comma, dash or end of line. Otherwise, it's invalid and
1255 # this pod doesn't have a legal name that we're smart
1256 # enough to find currently. But the parser will later
1257 # find it if it thinks there is a legal name, and set the
1259 if ($contents =~ /\G # continue from the line after =head1
1260 \s* # ignore any empty lines
1261 ^ \s* ( \S+?) \s* (?: [,-] | $ )/mx) {
1263 $checker->name($name);
1264 $id_to_checker{$name} = $checker
1265 if $filename =~ m{^cpan/};
1268 elsif ($filename =~ m{^cpan/}) {
1269 $id_to_checker{$digests{$filename}} = $checker;
1275 } # End of is_pod_file()
1277 # Start of real code that isn't processing the command line (except the
1278 # db is read in above, as is processing of the --add_link option).
1279 # Here, @files contains list of files on the command line. If have any of
1280 # these, unconditionally test them, and show all the errors, even the known
1281 # ones, and, since not testing other pods, don't do cross-pod link tests.
1282 # (Could add extra code to do cross-pod tests for the ones in the list.)
1284 if ($has_input_files) {
1285 undef %known_problems;
1286 $do_upstream_cpan = $do_deltas = 1; # In case one of the inputs is one
1289 else { # No input files -- go find all the possibilities.
1291 $copy_fh = open_new($known_issues);
1292 note("Regenerating $known_issues, please be patient...");
1293 print $copy_fh $HEADER;
1296 # Move to the directory above us, but have to adjust @INC to account for
1298 s{^\.\./lib$}{lib} for @INC;
1299 chdir File::Spec->updir;
1301 # And look in this directory and all its subdirectories
1302 find( \&is_pod_file, '.');
1304 # Add ourselves to the test
1305 push @files, "t/porting/podcheck.t";
1308 # Now we know how many tests there will be.
1309 plan (tests => scalar @files) if ! $regen;
1312 # Sort file names so we get consistent results, and to put cpan last,
1313 # preceeded by the ones that we don't generally parse. This is because both
1314 # these classes are generally parsed only if there is a link to the interior
1315 # of them, and we have to parse all others first to guarantee that they don't
1316 # have such a link. 'lib' files come just before these, as some of these are
1317 # duplicates of others. We already have figured this out when gathering the
1318 # data as a special case for all such files, but this, while unnecessary,
1319 # puts the derived file last in the output. 'readme' files come before those,
1320 # as those also could be duplicates of others, which are considered the
1321 # primary ones. These currently aren't figured out when gathering data, so
1323 @files = sort { if ($a =~ /^cpan/) {
1324 return 1 if $b !~ /^cpan/;
1327 elsif ($b =~ /^cpan/) {
1330 elsif ($a =~ /$only_for_interior_links_re/) {
1331 return 1 if $b !~ /$only_for_interior_links_re/;
1334 elsif ($b =~ /$only_for_interior_links_re/) {
1337 elsif ($a =~ /^lib/) {
1338 return 1 if $b !~ /^lib/;
1341 elsif ($b =~ /^lib/) {
1343 } elsif ($a =~ /\breadme\b/i) {
1344 return 1 if $b !~ /\breadme\b/i;
1347 elsif ($b =~ /\breadme\b/i) {
1351 return lc $a cmp lc $b;
1356 # Now go through all the files and parse them
1357 foreach my $filename (@files) {
1359 note("parsing $filename") if DEBUG;
1361 # We may have already figured out some things in the process of generating
1362 # the file list. If so, have a $checker object already. But if not,
1364 my $checker = $filename_to_checker{$filename};
1366 $checker = My::Pod::Checker->new($filename);
1367 $filename_to_checker{$filename} = $checker;
1370 # We have set the name in the checker object if there is a possibility
1371 # that no further parsing is necessary, but otherwise do the parsing now.
1372 if (! $checker->name) {
1374 $checker->parse_from_file($filename, undef);
1377 if ($checker->num_errors() < 0) { # Returns negative if not a pod
1378 $checker->set_skip("$filename is not a pod");
1382 # Here, is a pod. See if it is one that has already been tested,
1383 # or should be tested under another directory. Use either its NAME
1384 # if it has one, or a checksum if not.
1385 my $name = $checker->name;
1392 my $digest = Digest->new($digest_type);
1393 $digest->add(extract_pod($filename));
1394 $id = $digest->digest;
1397 # If there is a match for this pod with something that we've already
1398 # processed, don't process it, and output why.
1400 if (defined ($prior_checker = $id_to_checker{$id})
1401 && $prior_checker != $checker) # Could have defined the checker
1402 # earlier without pursuing it
1405 # If the pods are identical, then it's just a copy, and isn't an
1406 # error. First use the checksums we have already computed to see
1407 # if the entire files are identical, which means that the pods are
1409 my $prior_filename = $prior_checker->get_filename;
1411 || ($digests{$prior_filename}
1412 && $digests{$filename}
1413 && $digests{$prior_filename} eq $digests{$filename}));
1415 # If they differ, it could be that the files differ for some
1416 # reason, but the pods they contain are identical. Extract the
1417 # pods and do the comparisons on just those.
1418 if (! $same && $name) {
1419 $same = extract_pod($prior_filename) eq extract_pod($filename);
1423 $checker->set_skip("The pod of $filename is a duplicate of "
1424 . "the pod for $prior_filename");
1425 } elsif ($prior_filename =~ /\breadme\b/i) {
1426 $checker->set_skip("$prior_filename is a README apparently for $filename");
1427 } elsif ($filename =~ /\breadme\b/i) {
1428 $checker->set_skip("$filename is a README apparently for $prior_filename");
1429 } elsif (! $do_upstream_cpan && $filename =~ /^cpan/) {
1430 $checker->set_skip("CPAN is upstream for $filename");
1431 } else { # Here have two pods with identical names that differ
1432 $prior_checker->poderror(
1433 { -msg => $duplicate_name,
1435 parameter => "'$filename' also has NAME '$name'"
1438 { -msg => $duplicate_name,
1440 parameter => "'$prior_filename' also has NAME '$name'"
1443 # Changing the names helps later.
1444 $prior_checker->name("$name version arbitrarily numbered 1");
1445 $checker->name("$name version arbitrarily numbered 2");
1448 # In any event, don't process this pod that has the same name as
1454 $id_to_checker{$id} = $checker;
1456 my $parsed_for_links = ", but parsed for its interior links";
1457 if ((! $do_upstream_cpan && $filename =~ /^cpan/)
1458 || $filename =~ $only_for_interior_links_re)
1460 if ($filename =~ /^cpan/) {
1461 $checker->set_skip("CPAN is upstream for $filename");
1463 elsif ($filename =~ /perl\d+delta/ && ! $do_deltas) {
1464 $checker->set_skip("$filename is a stable perldelta");
1466 elsif ($filename =~ /perltoc/) {
1467 $checker->set_skip("$filename dependent on component pods");
1470 croak("Unexpected file '$filename' encountered that has parsing for interior-linking only");
1473 if ($name && $has_referred_to_node{$name}) {
1474 $checker->set_skip($checker->get_skip() . $parsed_for_links);
1478 # Need a name in order to process it, because not meaningful
1479 # otherwise, and also can't test links to this without a name.
1480 if (!defined $name) {
1481 $checker->poderror( { -msg => $no_name,
1487 # For skipped files, just get its NAME
1489 if (($skip = $checker->get_skip()) && $skip !~ /$parsed_for_links/)
1491 $checker->node($name) if $name;
1494 $checker->parse_from_file($filename, undef) if ! $parsed;
1497 # Go through everything in the file that could be an anchor that
1498 # could be a link target. Count how many there are of the same name.
1499 foreach my $node ($checker->linkable_nodes) {
1500 next if ! $node; # Can be empty is like '=item *'
1501 if (exists $nodes{$name}{$node}) {
1502 $nodes{$name}{$node}++;
1505 $nodes{$name}{$node} = 1;
1508 # Experiments have shown that cpan search can figure out the
1509 # target of a link even if the exact wording is incorrect, as long
1510 # as the first word is. This happens frequently in perlfunc.pod,
1511 # where the link will be just to the function, but the target
1512 # entry also includes parameters to the function.
1513 my $first_word = $node;
1514 if ($first_word =~ s/^(\S+)\s+\S.*/$1/) {
1515 $nodes_first_word{$name}{$first_word} = $node;
1518 $filename_to_pod{$filename} = $name;
1522 # Here, all files have been parsed, and all links and link targets are stored.
1523 # Now go through the files again and see which don't have matches.
1524 if (! $has_input_files) {
1525 foreach my $filename (@files) {
1526 next if $filename_to_checker{$filename}->get_skip;
1527 my $checker = $filename_to_checker{$filename};
1528 foreach my $link ($checker->hyperlink) {
1529 my $linked_to_page = $link->[1]->page;
1530 next unless $linked_to_page; # intra-file checks are handled by std
1533 # Initialize the potential message.
1534 my %problem = ( -msg => $broken_link,
1535 -line => $link->[0],
1536 parameter => "to \"$linked_to_page\"",
1539 # See if we have found the linked-to_file in our parse
1540 if (exists $nodes{$linked_to_page}) {
1541 my $node = $link->[1]->node;
1543 # If link is only to the page-level, already have it
1546 # Transform pod language to what we are expecting
1547 $node =~ s,E<sol>,/,g;
1548 $node =~ s/E<verbar>/|/g;
1550 # If link is to a node that exists in the file, is ok
1551 if ($nodes{$linked_to_page}{$node}) {
1553 # But if the page has multiple targets with the same name,
1554 # it's ambiguous which one this should be to.
1555 if ($nodes{$linked_to_page}{$node} > 1) {
1556 $problem{-msg} = $multiple_targets;
1557 $problem{parameter} = "in $linked_to_page that $node could be pointing to";
1558 $checker->poderror(\%problem);
1560 } elsif (! $nodes_first_word{$linked_to_page}{$node}) {
1562 # Here the link target was not found, either exactly or to
1563 # the first word. Is an error.
1564 $problem{parameter} =~ s,"$,/$node",;
1565 $checker->poderror(\%problem);
1568 } # Linked-to-file not in parse; maybe is in exception list
1569 elsif (! exists $valid_modules{$link->[1]->page}) {
1571 # Here, is a link to a target that we can't find. Check if
1572 # there is an internal link on the page with the target name.
1573 # If so, it could be that they just forgot the initial '/'
1574 # But perldelta is handled specially: only do this if the
1575 # broken link isn't one of the known bad ones (that are
1576 # placemarkers and should be removed for the final)
1577 my $NAME = $filename_to_pod{$filename};
1578 if (! defined $NAME) {
1579 $checker->poderror(\%problem);
1582 if ($nodes{$NAME}{$linked_to_page}) {
1583 $problem{-msg} = $broken_internal_link;
1585 $checker->poderror(\%problem);
1592 # If regenerating the data file, start with the modules for which we don't
1595 foreach (sort { lc $a cmp lc $b } keys %valid_modules) {
1596 my_safer_print($copy_fh, $_, "\n");
1600 # Now ready to output the messages.
1601 foreach my $filename (@files) {
1602 my $test_name = "POD of $filename";
1603 my $canonical = canonicalize($filename);
1605 my $skip = $filename_to_checker{$filename}->get_skip // "";
1608 foreach my $message ( sort keys %{$problems{$filename}}) {
1611 # Preserve a negative setting.
1612 if ($known_problems{$canonical}{$message}
1613 && $known_problems{$canonical}{$message} < 0)
1615 $count = $known_problems{$canonical}{$message};
1618 $count = @{$problems{$filename}{$message}};
1620 my_safer_print($copy_fh, canonicalize($filename) . "\t$message\t$count\n");
1625 skip($skip, 1) if $skip;
1629 my $total_known = 0;
1630 foreach my $message ( sort keys %{$problems{$filename}}) {
1631 $known_problems{$canonical}{$message} = 0
1632 if ! $known_problems{$canonical}{$message};
1633 my $diagnostic = "";
1634 my $problem_count = scalar @{$problems{$filename}{$message}};
1635 $total_known += $problem_count;
1636 next if $known_problems{$canonical}{$message} < 0;
1637 if ($problem_count > $known_problems{$canonical}{$message}) {
1639 # Here we are about to output all the messages for this type,
1640 # subtract back this number we previously added in.
1641 $total_known -= $problem_count;
1643 $diagnostic .= $indent . $message;
1644 if ($problem_count > 2) {
1645 $diagnostic .= " ($problem_count occurrences)";
1647 foreach my $problem (@{$problems{$filename}{$message}}) {
1648 $diagnostic .= " " if $problem_count == 1;
1649 $diagnostic .= "\n$indent$indent";
1650 $diagnostic .= "$problem->{parameter}" if $problem->{parameter};
1651 $diagnostic .= " near line $problem->{-line}";
1652 $diagnostic .= " $problem->{comment}" if $problem->{comment};
1654 $diagnostic .= "\n";
1655 $files_with_unknown_issues{$filename} = 1;
1656 } elsif ($problem_count < $known_problems{$canonical}{$message}) {
1657 $diagnostic = output_thanks($filename, $known_problems{$canonical}{$message}, $problem_count, $message);
1659 push @diagnostics, $diagnostic if $diagnostic;
1662 # The above loop has output messages where there are current potential
1663 # issues. But it misses where there were some that have been entirely
1664 # fixed. For those, we need to look through the old issues
1665 foreach my $message ( sort keys %{$known_problems{$canonical}}) {
1666 next if $problems{$filename}{$message};
1667 next if ! $known_problems{$canonical}{$message};
1668 next if $known_problems{$canonical}{$message} < 0; # Preserve negs
1669 my $diagnostic = output_thanks($filename, $known_problems{$canonical}{$message}, 0, $message);
1670 push @diagnostics, $diagnostic if $diagnostic;
1673 my $output = "POD of $filename";
1674 $output .= ", excluding $total_known not shown known potential problems"
1676 ok(@diagnostics == 0, $output);
1678 note(join "", @diagnostics,
1679 "See end of this test output for your options on silencing this");
1685 run this test script by hand, using the following formula (on
1686 Un*x-like machines):
1688 ./perl -I../lib porting/podcheck.t --regen
1691 if (%files_with_unknown_issues) {
1692 my $were_count_files = scalar keys %files_with_unknown_issues;
1693 $were_count_files = ($were_count_files == 1)
1694 ? "was $were_count_files file"
1695 : "were $were_count_files files";
1696 my $message = <<EOF;
1698 HOW TO GET THIS .t TO PASS
1700 There $were_count_files that had new potential problems identified.
1701 Some of them may be real, and some of them may be false positives because
1702 this program isn't as smart as it likes to think it is. You can teach this
1703 program to ignore the issues it has identified, and hence pass, by doing the
1706 1) If a problem is about a link to an unknown module or man page that
1707 you know exists, re-run the command something like:
1708 ./perl -I../lib porting/podcheck.t --add_link MODULE man_page ...
1709 (MODULEs should look like Foo::Bar, and man_pages should look like
1710 bar(3c); don't do this for a module or man page that you aren't sure
1711 about; instead treat as another type of issue and follow the
1712 instructions below.)
1714 2) For other issues, decide if each should be fixed now or not. Fix the
1715 ones you decided to, and rerun this test to verify that the fixes
1718 3) If there remain false positive or problems that you don't plan to fix right
1721 That should cause all current potential problems to be accepted by
1722 the program, so that the next time it runs, they won't be flagged.
1724 if (%files_with_fixes) {
1725 $message .= " This step will also take care of the files that have fixes in them\n";
1729 For a few files, such as perltoc, certain issues will always be
1730 expected, and more of the same will be added over time. For those,
1731 before you do the regen, you can edit
1733 and find the entry for the module's file and specific error message,
1734 and change the count of known potential problems to -1.
1738 } elsif (%files_with_fixes) {
1740 To teach this test script that the potential problems have been fixed,
1747 chdir $original_dir || die "Can't change directories to $original_dir";
1748 close_and_rename($copy_fh);