1 #############################################################################
2 # Pod/Checker.pm -- check pod documents for syntax errors
4 # Copyright (C) 1994-1999 by Bradford Appleton. All rights reserved.
5 # This file is part of "PodParser". PodParser is free software;
6 # you can redistribute it and/or modify it under the same terms
8 #############################################################################
12 use vars qw($VERSION);
13 $VERSION = 1.097; ## Current version of this package
14 require 5.004; ## requires this Perl version or later
16 use Pod::ParseUtils; ## for hyperlinks and lists
20 Pod::Checker, podchecker() - check pod documents for syntax errors
26 $syntax_okay = podchecker($filepath, $outputpath, %options);
28 my $checker = new Pod::Checker %options;
30 =head1 OPTIONS/ARGUMENTS
32 C<$filepath> is the input POD to read and C<$outputpath> is
33 where to write POD syntax error messages. Either argument may be a scalar
34 indicating a file-path, or else a reference to an open filehandle.
35 If unspecified, the input-file it defaults to C<\*STDIN>, and
36 the output-file defaults to C<\*STDERR>.
40 This function can take a hash of options:
44 =item B<-warnings> =E<gt> I<val>
46 Turn warnings on/off. See L<"Warnings">.
52 B<podchecker> will perform syntax checking of Perl5 POD format documentation.
54 I<NOTE THAT THIS MODULE IS CURRENTLY IN THE BETA STAGE!>
56 It is hoped that curious/ambitious user will help flesh out and add the
57 additional features they wish to see in B<Pod::Checker> and B<podchecker>
58 and verify that the checks are consistent with L<perlpod>.
60 The following checks are preformed:
66 Unknown '=xxxx' commands, unknown 'X<...>' interior-sequences,
67 and unterminated interior sequences.
71 Check for proper balancing of C<=begin> and C<=end>. The contents of such
72 a block are generally ignored, i.e. no syntax checks are performed.
76 Check for proper nesting and balancing of C<=over>, C<=item> and C<=back>.
80 Check for same nested interior-sequences (e.g.
81 C<LE<lt>...LE<lt>...E<gt>...E<gt>>).
85 Check for malformed or nonexisting entities C<EE<lt>...E<gt>>.
89 Check for correct syntax of hyperlinks C<LE<lt>...E<gt>>. See L<perlpod>
94 Check for unresolved document-internal links. This check may also reveal
95 misspelled links that seem to be internal links but should be links
100 =head2 Additional Features
102 While checking, this module collects document properties, e.g. the nodes
103 for hyperlinks (C<=headX>, C<=item>). POD translators can use this feature
104 to syntax-check and get the nodes in a first pass before actually starting
105 to convert. This is expensive in terms of execution time, but allows for
106 very robust conversions.
116 A heading (C<=head1> or C<=head2>) without any text? That ain't no
119 =item * =over on line I<N> without closing =back
121 The C<=over> command does not have a corresponding C<=back> before the
122 next heading (C<=head1> or C<=head2>) or the end of the file.
124 =item * =item without previous =over
126 =item * =back without previous =over
128 An C<=item> or C<=back> command has been found outside a
129 C<=over>/C<=back> block.
131 =item * No argument for =begin
133 A C<=begin> command was found that is not followed by the formatter
136 =item * =end without =begin
138 A standalone C<=end> command was found.
140 =item * Nested =begin's
142 There were at least two consecutive C<=begin> commands without
143 the corresponding C<=end>. Only one C<=begin> may be active at
146 =item * =for without formatter specification
148 There is no specification of the formatter after the C<=for> command.
150 =item * unresolved internal link I<NAME>
152 The given link to I<NAME> does not have a matching node in the current
153 POD. This also happend when a single word node name is not enclosed in
156 =item * Unknown command "I<CMD>"
158 An invalid POD command has been found. Valid are C<=head1>, C<=head2>,
159 C<=over>, C<=item>, C<=back>, C<=begin>, C<=end>, C<=for>, C<=pod>,
162 =item * Unknown interior-sequence "I<SEQ>"
164 An invalid markup command has been encountered. Valid are:
165 C<BE<lt>E<gt>>, C<CE<lt>E<gt>>, C<EE<lt>E<gt>>, C<FE<lt>E<gt>>,
166 C<IE<lt>E<gt>>, C<LE<lt>E<gt>>, C<SE<lt>E<gt>>, C<XE<lt>E<gt>>,
169 =item * nested commands I<CMD>E<lt>...I<CMD>E<lt>...E<gt>...E<gt>
171 Two nested identical markup commands have been found. Generally this
174 =item * garbled entity I<STRING>
176 The I<STRING> found cannot be interpreted as a character entity.
178 =item * Entity number out of range
180 An entity specified by number (dec, hex, oct) is out of range (1-255).
182 =item * malformed link LE<lt>E<gt>
184 The link found cannot be parsed because it does not conform to the
185 syntax described in L<perlpod>.
187 =item * nonempty ZE<lt>E<gt>
189 The C<ZE<lt>E<gt>> sequence is supposed to be empty.
191 =item * Spurious text after =pod / =cut
193 The commands C<=pod> and C<=cut> do not take any arguments.
195 =item * Spurious character(s) after =back
197 The C<=back> command does not take any arguments.
203 These may not necessarily cause trouble, but indicate mediocre style.
207 =item * multiple occurence of link target I<name>
209 The POD file has some C<=item> and/or C<=head> commands that have
210 the same text. Potential hyperlinks to such a text cannot be unique then.
212 =item * line containing nothing but whitespace in paragraph
214 There is some whitespace on a seemingly empty line. POD is very sensitive
215 to such things, so this is flagged. B<vi> users switch on the B<list>
216 option to avoid this problem.
218 =item * file does not start with =head
220 The file starts with a different POD directive than head.
221 This is most probably something you do not want.
223 =item * No numeric argument for =over
225 The C<=over> command is supposed to have a numeric argument (the
228 =item * previous =item has no contents
230 There is a list C<=item> right above the flagged line that has no
231 text contents. You probably want to delete empty items.
233 =item * preceding non-item paragraph(s)
235 A list introduced by C<=over> starts with a text or verbatim paragraph,
236 but continues with C<=item>s. Move the non-item paragraph out of the
237 C<=over>/C<=back> block.
239 =item * =item type mismatch (I<one> vs. I<two>)
241 A list started with e.g. a bulletted C<=item> and continued with a
242 numbered one. This is obviously inconsistent. For most translators the
243 type of the I<first> C<=item> determines the type of the list.
245 =item * I<N> unescaped C<E<lt>E<gt>> in paragraph
247 Angle brackets not written as C<E<lt>ltE<gt>> and C<E<lt>gtE<gt>>
248 can potentially cause errors as they could be misinterpreted as
251 =item * Unknown entity
253 A character entity was found that does not belong to the standard
254 ISO set or the POD specials C<verbar> and C<sol>.
256 =item * No items in =over
258 The list opened with C<=over> does not contain any items.
260 =item * No argument for =item
262 C<=item> without any parameters is deprecated. It should either be followed
263 by C<*> to indicate an unordered list, by a number (optionally followed
264 by a dot) to indicate an ordered (numbered) list or simple text for a
267 =item * empty section in previous paragraph
269 The previous section (introduced by a C<=head> command) does not contain
270 any text. This usually indicates that something is missing. Note: A
271 C<=head1> followed immediately by C<=head2> does not trigger this warning.
273 =item * Verbatim paragraph in NAME section
275 The NAME section (C<=head1 NAME>) should consist of a single paragraph
276 with the script/module name, followed by a dash `-' and a very short
277 description of what the thing is good for.
281 There are some warnings wrt. hyperlinks:
282 Leading/trailing whitespace, newlines in hyperlinks,
289 B<podchecker> returns the number of POD syntax errors found or -1 if
290 there were no POD commands at all found in the file.
298 Brad Appleton E<lt>bradapp@enteract.comE<gt> (initial version),
299 Marek Rouchal E<lt>marek@saftsack.fs.uni-bayreuth.deE<gt>
301 Based on code for B<Pod::Text::pod2text()> written by
302 Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
306 #############################################################################
314 use vars qw(@ISA @EXPORT);
315 @ISA = qw(Pod::Parser);
316 @EXPORT = qw(&podchecker);
318 use vars qw(%VALID_COMMANDS %VALID_SEQUENCES);
320 my %VALID_COMMANDS = (
333 my %VALID_SEQUENCES = (
345 # stolen from HTML::Entities
347 # Some normal chars that have special meaning in SGML context
348 amp => '&', # ampersand
349 'gt' => '>', # greater than
350 'lt' => '<', # less than
351 quot => '"', # double quote
353 # PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML
354 AElig => 'Æ', # capital AE diphthong (ligature)
355 Aacute => 'Á', # capital A, acute accent
356 Acirc => 'Â', # capital A, circumflex accent
357 Agrave => 'À', # capital A, grave accent
358 Aring => 'Å', # capital A, ring
359 Atilde => 'Ã', # capital A, tilde
360 Auml => 'Ä', # capital A, dieresis or umlaut mark
361 Ccedil => 'Ç', # capital C, cedilla
362 ETH => 'Ð', # capital Eth, Icelandic
363 Eacute => 'É', # capital E, acute accent
364 Ecirc => 'Ê', # capital E, circumflex accent
365 Egrave => 'È', # capital E, grave accent
366 Euml => 'Ë', # capital E, dieresis or umlaut mark
367 Iacute => 'Í', # capital I, acute accent
368 Icirc => 'Î', # capital I, circumflex accent
369 Igrave => 'Ì', # capital I, grave accent
370 Iuml => 'Ï', # capital I, dieresis or umlaut mark
371 Ntilde => 'Ñ', # capital N, tilde
372 Oacute => 'Ó', # capital O, acute accent
373 Ocirc => 'Ô', # capital O, circumflex accent
374 Ograve => 'Ò', # capital O, grave accent
375 Oslash => 'Ø', # capital O, slash
376 Otilde => 'Õ', # capital O, tilde
377 Ouml => 'Ö', # capital O, dieresis or umlaut mark
378 THORN => 'Þ', # capital THORN, Icelandic
379 Uacute => 'Ú', # capital U, acute accent
380 Ucirc => 'Û', # capital U, circumflex accent
381 Ugrave => 'Ù', # capital U, grave accent
382 Uuml => 'Ü', # capital U, dieresis or umlaut mark
383 Yacute => 'Ý', # capital Y, acute accent
384 aacute => 'á', # small a, acute accent
385 acirc => 'â', # small a, circumflex accent
386 aelig => 'æ', # small ae diphthong (ligature)
387 agrave => 'à', # small a, grave accent
388 aring => 'å', # small a, ring
389 atilde => 'ã', # small a, tilde
390 auml => 'ä', # small a, dieresis or umlaut mark
391 ccedil => 'ç', # small c, cedilla
392 eacute => 'é', # small e, acute accent
393 ecirc => 'ê', # small e, circumflex accent
394 egrave => 'è', # small e, grave accent
395 eth => 'ð', # small eth, Icelandic
396 euml => 'ë', # small e, dieresis or umlaut mark
397 iacute => 'í', # small i, acute accent
398 icirc => 'î', # small i, circumflex accent
399 igrave => 'ì', # small i, grave accent
400 iuml => 'ï', # small i, dieresis or umlaut mark
401 ntilde => 'ñ', # small n, tilde
402 oacute => 'ó', # small o, acute accent
403 ocirc => 'ô', # small o, circumflex accent
404 ograve => 'ò', # small o, grave accent
405 oslash => 'ø', # small o, slash
406 otilde => 'õ', # small o, tilde
407 ouml => 'ö', # small o, dieresis or umlaut mark
408 szlig => 'ß', # small sharp s, German (sz ligature)
409 thorn => 'þ', # small thorn, Icelandic
410 uacute => 'ú', # small u, acute accent
411 ucirc => 'û', # small u, circumflex accent
412 ugrave => 'ù', # small u, grave accent
413 uuml => 'ü', # small u, dieresis or umlaut mark
414 yacute => 'ý', # small y, acute accent
415 yuml => 'ÿ', # small y, dieresis or umlaut mark
417 # Some extra Latin 1 chars that are listed in the HTML3.2 draft (21-May-96)
418 copy => '©', # copyright sign
419 reg => '®', # registered sign
420 nbsp => "\240", # non breaking space
422 # Additional ISO-8859/1 entities listed in rfc1866 (section 14)
433 'not' => '¬', # not is a keyword in perl
452 'times' => '×', # times is a keyword in perl
455 # some POD special entities
460 ##---------------------------------------------------------------------------
462 ##---------------------------------
463 ## Function definitions begin here
464 ##---------------------------------
466 sub podchecker( $ ; $ % ) {
467 my ($infile, $outfile, %options) = @_;
472 $outfile ||= \*STDERR;
474 ## Now create a pod checker
475 my $checker = new Pod::Checker(%options);
476 $checker->parseopts(-process_cut_cmd => 1);
478 ## Now check the pod document for errors
479 $checker->parse_from_file($infile, $outfile);
481 ## Return the number of errors found
482 return $checker->num_errors();
485 ##---------------------------------------------------------------------------
487 ##-------------------------------
488 ## Method definitions begin here
489 ##-------------------------------
493 ## my $class = ref($this) || $this;
495 ## my $self = {%params};
496 ## bless $self, $class;
497 ## $self->initialize();
503 ## Initialize number of errors, and setup an error function to
504 ## increment this number and then print to the designated output.
505 $self->{_NUM_ERRORS} = 0;
506 $self->errorsub('poderror'); # set the error handling subroutine
507 $self->{_commands} = 0; # total number of POD commands encountered
508 $self->{_list_stack} = []; # stack for nested lists
509 $self->{_have_begin} = ''; # stores =begin
510 $self->{_links} = []; # stack for internal hyperlinks
511 $self->{_nodes} = []; # stack for =head/=item nodes
513 $self->{-warnings} = 1 unless(defined $self->{-warnings});
514 $self->{_current_head1} = ''; # the current =head1 block
517 # Invoked as $self->poderror( @args ), or $self->poderror( {%opts}, @args )
520 my %opts = (ref $_[0]) ? %{shift()} : ();
523 chomp( my $msg = ($opts{-msg} || "")."@_" );
524 my $line = (exists $opts{-line}) ? " at line $opts{-line}" : "";
525 my $file = (exists $opts{-file}) ? " in file $opts{-file}" : "";
526 unless (exists $opts{-severity}) {
527 ## See if can find severity in message prefix
528 $opts{-severity} = $1 if ( $msg =~ s/^\**\s*([A-Z]{3,}):\s+// );
530 my $severity = (exists $opts{-severity}) ? "*** $opts{-severity}: " : "";
532 ## Increment error count and print message "
533 ++($self->{_NUM_ERRORS})
534 if(!%opts || ($opts{-severity} && $opts{-severity} eq 'ERROR'));
535 my $out_fh = $self->output_handle();
536 print $out_fh ($severity, $msg, $line, $file, "\n")
537 if($self->{-warnings} || !%opts || $opts{-severity} ne 'WARNING');
540 # set/retrieve the number of errors found
542 return (@_ > 1) ? ($_[0]->{_NUM_ERRORS} = $_[1]) : $_[0]->{_NUM_ERRORS};
545 # set and/or retrieve canonical name of POD
547 return (@_ > 1 && $_[1]) ?
548 ($_[0]->{-name} = $_[1]) : $_[0]->{-name};
551 # set/return nodes of the current POD
553 my ($self,$text) = @_;
555 $text =~ s/\s+$//s; # strip trailing whitespace
556 $text =~ s/\s+/ /gs; # collapse whitespace
557 # add node, order important!
558 push(@{$self->{_nodes}}, $text);
559 # keep also a uniqueness counter
560 $self->{_unique_nodes}->{$text}++;
566 # set/return hyperlinks of the current POD
570 push(@{$self->{_links}}, $_[0]);
576 ## overrides for Pod::Parser
579 ## Do some final checks and
580 ## print the number of errors found
582 my $infile = $self->input_file();
583 my $out_fh = $self->output_handle();
585 if(@{$self->{_list_stack}}) {
586 # _TODO_ display, but don't count them for now
588 while(($list = $self->_close_list('EOF',$infile)) &&
589 $list->indent() ne 'auto') {
590 $self->poderror({ -line => 'EOF', -file => $infile,
591 -severity => 'ERROR', -msg => "=over on line " .
592 $list->start() . " without closing =back" }); #"
596 # check validity of document internal hyperlinks
597 # first build the node names from the paragraph text
599 foreach($self->node()) {
602 # we have more than one word. Use the first as a node, too.
603 # This is used heavily in perlfunc.pod
604 $nodes{$1} ||= 2; # derived node
607 foreach($self->hyperlink()) {
609 s/^(\d+):// && ($line = $1);
610 if($_ && !$nodes{$_}) {
611 $self->poderror({ -line => $line, -file => $infile,
612 -severity => 'ERROR',
613 -msg => "unresolved internal link '$_'"});
616 foreach(grep($self->{_unique_nodes}->{$_} > 1,
617 keys %{$self->{_unique_nodes}})) {
618 $self->poderror({ -line => '-', -file => $infile,
619 -severity => 'WARNING',
620 -msg => "multiple occurence of link target '$_'"});
623 ## Print the number of errors found
624 my $num_errors = $self->num_errors();
625 if ($num_errors > 0) {
626 printf $out_fh ("$infile has $num_errors pod syntax %s.\n",
627 ($num_errors == 1) ? "error" : "errors");
629 elsif($self->{_commands} == 0) {
630 print $out_fh "$infile does not contain any pod commands.\n";
631 $self->num_errors(-1);
634 print $out_fh "$infile pod syntax OK.\n";
638 # check a POD command directive
640 my ($self, $cmd, $paragraph, $line_num, $pod_para) = @_;
641 my ($file, $line) = $pod_para->file_line;
642 ## Check the command syntax
643 my $arg; # this will hold the command argument
644 if (! $VALID_COMMANDS{$cmd}) {
645 $self->poderror({ -line => $line, -file => $file, -severity => 'ERROR',
646 -msg => "Unknown command '$cmd'" });
649 # found a valid command
650 if(!$self->{_commands}++ && $cmd !~ /^head/) {
651 $self->poderror({ -line => $line, -file => $file,
652 -severity => 'WARNING',
653 -msg => "file does not start with =head" });
655 ## check syntax of particular command
658 $arg = $self->interpolate_and_check($paragraph, $line,$file);
659 my $indent = 4; # default
660 if($arg && $arg =~ /^\s*(\d+)\s*$/) {
663 $self->poderror({ -line => $line, -file => $file,
664 -severity => 'WARNING',
665 -msg => "No numeric argument for =over"});
668 $self->_open_list($indent,$line,$file);
670 elsif($cmd eq 'item') {
672 unless(@{$self->{_list_stack}}) {
673 $self->poderror({ -line => $line, -file => $file,
674 -severity => 'ERROR',
675 -msg => "=item without previous =over" });
676 # auto-open in case we encounter many more
677 $self->_open_list('auto',$line,$file);
679 my $list = $self->{_list_stack}->[0];
680 # check whether the previous item had some contents
681 if(defined $self->{_list_item_contents} &&
682 $self->{_list_item_contents} == 0) {
683 $self->poderror({ -line => $line, -file => $file,
684 -severity => 'WARNING',
685 -msg => "previous =item has no contents" });
687 if($list->{_has_par}) {
688 $self->poderror({ -line => $line, -file => $file,
689 -severity => 'WARNING',
690 -msg => "preceding non-item paragraph(s)" });
691 delete $list->{_has_par};
694 $arg = $self->interpolate_and_check($paragraph, $line, $file);
695 if($arg && $arg =~ /(\S+)/) {
696 $arg =~ s/[\s\n]+$//;
698 if($arg =~ /^[*]\s*(\S*.*)/) {
700 $self->{_list_item_contents} = $1 ? 1 : 0;
703 elsif($arg =~ /^\d+\.?\s*(\S*)/) {
705 $self->{_list_item_contents} = $1 ? 1 : 0;
709 $type = 'definition';
710 $self->{_list_item_contents} = 1;
712 my $first = $list->type();
713 if($first && $first ne $type) {
714 $self->poderror({ -line => $line, -file => $file,
715 -severity => 'WARNING',
716 -msg => "=item type mismatch ('$first' vs. '$type')"});
723 $self->poderror({ -line => $line, -file => $file,
724 -severity => 'WARNING',
725 -msg => "No argument for =item" });
727 $self->{_list_item_contents} = 0;
734 elsif($cmd eq 'back') {
735 # check if we have an open list
736 unless(@{$self->{_list_stack}}) {
737 $self->poderror({ -line => $line, -file => $file,
738 -severity => 'ERROR',
739 -msg => "=back without previous =over" });
742 # check for spurious characters
743 $arg = $self->interpolate_and_check($paragraph, $line,$file);
744 if($arg && $arg =~ /\S/) {
745 $self->poderror({ -line => $line, -file => $file,
746 -severity => 'ERROR',
747 -msg => "Spurious character(s) after =back" });
750 my $list = $self->_close_list($line,$file);
751 # check for empty lists
752 if(!$list->item() && $self->{-warnings}) {
753 $self->poderror({ -line => $line, -file => $file,
754 -severity => 'WARNING',
755 -msg => "No items in =over (at line " .
756 $list->start() . ") / =back list"}); #"
760 elsif($cmd =~ /^head(\d+)/) {
761 if(defined $self->{_commands_in_head} &&
762 $self->{_commands_in_head} == 0 &&
763 defined $self->{_last_head} &&
764 $self->{_last_head} >= $1) {
765 $self->poderror({ -line => $line, -file => $file,
766 -severity => 'WARNING',
767 -msg => "empty section in previous paragraph"});
769 $self->{_commands_in_head} = -1;
770 $self->{_last_head} = $1;
771 # check if there is an open list
772 if(@{$self->{_list_stack}}) {
774 while(($list = $self->_close_list($line,$file)) &&
775 $list->indent() ne 'auto') {
776 $self->poderror({ -line => $line, -file => $file,
777 -severity => 'ERROR',
778 -msg => "=over on line ". $list->start() .
779 " without closing =back (at $cmd)" });
783 $arg = $self->interpolate_and_check($paragraph, $line,$file);
784 $arg =~ s/[\s\n]+$//s;
786 unless(length($arg)) {
787 $self->poderror({ -line => $line, -file => $file,
788 -severity => 'ERROR',
789 -msg => "empty =$cmd"});
791 if($cmd eq 'head1') {
792 $self->{_current_head1} = $arg;
794 $self->{_current_head1} = '';
797 elsif($cmd eq 'begin') {
798 if($self->{_have_begin}) {
799 # already have a begin
800 $self->poderror({ -line => $line, -file => $file,
801 -severity => 'ERROR',
802 -msg => "Nested =begin's (first at line " .
803 $self->{_have_begin} . ")"});
807 $arg = $self->interpolate_and_check($paragraph, $line,$file);
808 unless($arg && $arg =~ /(\S+)/) {
809 $self->poderror({ -line => $line, -file => $file,
810 -severity => 'ERROR',
811 -msg => "No argument for =begin"});
813 # remember the =begin
814 $self->{_have_begin} = "$line:$1";
817 elsif($cmd eq 'end') {
818 if($self->{_have_begin}) {
819 # close the existing =begin
820 $self->{_have_begin} = '';
821 # check for spurious characters
822 $arg = $self->interpolate_and_check($paragraph, $line,$file);
823 # the closing argument is optional
824 #if($arg && $arg =~ /\S/) {
825 # $self->poderror({ -line => $line, -file => $file,
826 # -severity => 'WARNING',
827 # -msg => "Spurious character(s) after =end" });
831 # don't have a matching =begin
832 $self->poderror({ -line => $line, -file => $file,
833 -severity => 'ERROR',
834 -msg => "=end without =begin" });
837 elsif($cmd eq 'for') {
838 unless($paragraph =~ /\s*(\S+)\s*/) {
839 $self->poderror({ -line => $line, -file => $file,
840 -severity => 'ERROR',
841 -msg => "=for without formatter specification" });
843 $arg = ''; # do not expand paragraph below
845 elsif($cmd =~ /^(pod|cut)$/) {
847 $arg = $self->interpolate_and_check($paragraph, $line,$file);
848 if($arg && $arg =~ /(\S+)/) {
849 $self->poderror({ -line => $line, -file => $file,
850 -severity => 'ERROR',
851 -msg => "Spurious text after =$cmd"});
854 $self->{_commands_in_head}++;
855 ## Check the interior sequences in the command-text
856 $self->interpolate_and_check($paragraph, $line,$file)
857 unless(defined $arg);
863 my ($self,$indent,$line,$file) = @_;
864 my $list = Pod::List->new(
868 unshift(@{$self->{_list_stack}}, $list);
869 undef $self->{_list_item_contents};
875 my ($self,$line,$file) = @_;
876 my $list = shift(@{$self->{_list_stack}});
877 if(defined $self->{_list_item_contents} &&
878 $self->{_list_item_contents} == 0) {
879 $self->poderror({ -line => $line, -file => $file,
880 -severity => 'WARNING',
881 -msg => "previous =item has no contents" });
883 undef $self->{_list_item_contents};
887 # process a block of some text
888 sub interpolate_and_check {
889 my ($self, $paragraph, $line, $file) = @_;
890 ## Check the interior sequences in the command-text
891 # and return the text
893 $self->parse_text($paragraph,$line), $line, $file, '');
897 my ($self,$ptree,$line,$file,$nestlist) = @_;
900 # process each node in the parse tree
905 # count the unescaped angle brackets
907 if($count = $i =~ tr/<>/<>/) {
908 $self->poderror({ -line => $line, -file => $file,
909 -severity => 'WARNING',
910 -msg => "$count unescaped <> in paragraph" })
911 if($self->{-warnings});
916 # have an interior sequence
917 my $cmd = $_->cmd_name();
918 my $contents = $_->parse_tree();
919 ($file,$line) = $_->file_line();
920 # check for valid tag
921 if (! $VALID_SEQUENCES{$cmd}) {
922 $self->poderror({ -line => $line, -file => $file,
923 -severity => 'ERROR',
924 -msg => qq(Unknown interior-sequence '$cmd')});
926 $text .= $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
929 if($nestlist =~ /$cmd/) {
930 $self->poderror({ -line => $line, -file => $file,
931 -severity => 'ERROR',
932 -msg => "nested commands $cmd<...$cmd<...>...>"});
933 # _TODO_ should we add the contents anyway?
934 # expand it anyway, see below
938 if(@$contents > 1 || ref $$contents[0] || $$contents[0] !~ /^\w+$/) {
939 $self->poderror({ -line => $line, -file => $file,
940 -severity => 'ERROR',
941 -msg => "garbled entity " . $_->raw_text()});
944 my $ent = $$contents[0];
946 if($ent =~ /^0x[0-9a-f]+$/i) {
950 elsif($ent =~ /^0\d+$/) {
954 elsif($ent =~ /^\d+$/) {
959 if($val>0 && $val<256) {
963 $self->poderror({ -line => $line, -file => $file,
964 -severity => 'ERROR',
965 -msg => "Entity number out of range " . $_->raw_text()});
968 elsif($ENTITIES{$ent}) {
970 $text .= $ENTITIES{$ent};
973 $self->poderror({ -line => $line, -file => $file,
974 -severity => 'WARNING',
975 -msg => "Unknown entity " . $_->raw_text()});
980 # try to parse the hyperlink
981 my $link = Pod::Hyperlink->new($contents->raw_text());
982 unless(defined $link) {
983 $self->poderror({ -line => $line, -file => $file,
984 -severity => 'ERROR',
985 -msg => "malformed link " . $_->raw_text() ." : $@"});
988 $link->line($line); # remember line
989 if($self->{-warnings}) {
990 foreach my $w ($link->warning()) {
991 $self->poderror({ -line => $line, -file => $file,
992 -severity => 'WARNING',
996 # check the link text
997 $text .= $self->_check_ptree($self->parse_text($link->text(),
998 $line), $line, $file, "$nestlist$cmd");
1000 # remember internal link
1001 # _TODO_ what if there is a link to the page itself by the name,
1002 # e.g. in Tk::Pod : L<Tk::Pod/"DESCRIPTION">
1003 if($link->node() && !$link->page() && $link->type() ne 'hyperlink') {
1004 $node = $self->_check_ptree($self->parse_text($link->node(),
1005 $line), $line, $file, "$nestlist$cmd");
1006 $self->hyperlink("$line:$node") if($node);
1009 elsif($cmd =~ /[BCFIS]/) {
1011 $text .= $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
1013 elsif($cmd eq 'Z') {
1014 if(length($contents->raw_text())) {
1015 $self->poderror({ -line => $line, -file => $file,
1016 -severity => 'ERROR',
1017 -msg => "Nonempty Z<>"});
1021 # check, but add nothing to $text
1022 $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
1028 # _TODO_ overloadable methods for BC..Z<...> expansion?
1030 # process a block of verbatim text
1032 ## Nothing particular to check
1033 my ($self, $paragraph, $line_num, $pod_para) = @_;
1035 $self->_preproc_par($paragraph);
1037 if($self->{_current_head1} eq 'NAME') {
1038 my ($file, $line) = $pod_para->file_line;
1039 $self->poderror({ -line => $line, -file => $file,
1040 -severity => 'WARNING',
1041 -msg => 'Verbatim paragraph in NAME section' });
1045 # process a block of regular text
1047 my ($self, $paragraph, $line_num, $pod_para) = @_;
1048 my ($file, $line) = $pod_para->file_line;
1050 $self->_preproc_par($paragraph);
1052 # skip this paragraph if in a =begin block
1053 unless($self->{_have_begin}) {
1054 my $block = $self->interpolate_and_check($paragraph, $line,$file);
1055 if($self->{_current_head1} eq 'NAME') {
1056 if($block =~ /^\s*(\S+?)\s*[,-]/) {
1057 # this is the canonical name
1058 $self->{-name} = $1 unless(defined $self->{-name});
1067 $_[0] =~ s/[\s\n]+$//;
1069 $self->{_commands_in_head}++;
1070 $self->{_list_item_contents}++ if(defined $self->{_list_item_contents});
1071 if(@{$self->{_list_stack}} && !$self->{_list_stack}->[0]->item()) {
1072 $self->{_list_stack}->[0]->{_has_par} = 1;