Cross Reference: Checker.pm
xref
: /
osnet-11
/
usr
/
src
/
cmd
/
perl
/
5.8.4
/
distrib
/
lib
/
Pod
/
Checker.pm
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
1
N/A
#############################################################################
1
N/A
#
Pod
/
Checker.pm
-- check pod documents for syntax errors
1
N/A
#
1
N/A
# Copyright (C) 1994-2000 by Bradford Appleton. All rights reserved.
1
N/A
# This file is part of "PodParser". PodParser is free software;
1
N/A
# you can redistribute it
and
/
or
modify it under the same terms
1
N/A
# as Perl itself.
1
N/A
#############################################################################
1
N/A
1
N/A
package
Pod
::
Checker
;
1
N/A
1
N/A
use
vars
qw
($
VERSION
);
1
N/A
$
VERSION
=
1.41
;
## Current version of this package
1
N/A
require
5.005
;
## requires this Perl version or later
1
N/A
1
N/A
use
Pod
::
ParseUtils
;
## for hyperlinks and lists
1
N/A
1
N/A
=head1 NAME
1
N/A
1
N/A
Pod::Checker, podchecker() - check pod documents for syntax errors
1
N/A
1
N/A
=head1 SYNOPSIS
1
N/A
1
N/A
use Pod::Checker;
1
N/A
1
N/A
$syntax_okay = podchecker($filepath, $outputpath, %options);
1
N/A
1
N/A
my $checker = new Pod::Checker %options;
1
N/A
$checker->parse_from_file($filepath, \*STDERR);
1
N/A
1
N/A
=head1
OPTIONS
/
ARGUMENTS
1
N/A
1
N/A
C<$filepath> is the input POD to read and C<$outputpath> is
1
N/A
where to write POD syntax error messages. Either argument may be a scalar
1
N/A
indicating a file-path, or else a reference to an open filehandle.
1
N/A
If unspecified, the input-file it defaults to C<\*STDIN>, and
1
N/A
the output-file defaults to C<\*STDERR>.
1
N/A
1
N/A
=head2 podchecker()
1
N/A
1
N/A
This function can take a hash of options:
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item B<-warnings> =E<gt> I<val>
1
N/A
1
N/A
Turn warnings
on
/
off
. I<val> is usually 1 for on, but higher values
1
N/A
trigger additional warnings. See L<"Warnings">.
1
N/A
1
N/A
=back
1
N/A
1
N/A
=head1 DESCRIPTION
1
N/A
1
N/A
B<podchecker> will perform syntax checking of Perl5 POD format documentation.
1
N/A
1
N/A
Curious
/
ambitious
users are welcome to propose additional features they wish
1
N/A
to see in B<Pod::Checker> and B<podchecker> and verify that the checks are
1
N/A
consistent with L<perlpod>.
1
N/A
1
N/A
The following checks are currently preformed:
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Unknown '=xxxx' commands, unknown 'XE<lt>...E<gt>' interior-sequences,
1
N/A
and unterminated interior sequences.
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for proper balancing of C<=begin> and C<=end>. The contents of such
1
N/A
a block are generally ignored, i.e. no syntax checks are performed.
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for proper nesting and balancing of C<=over>, C<=item> and C<=back>.
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for same nested interior-sequences (e.g.
1
N/A
C<LE<lt>...LE<lt>...E<gt>...E<gt>>).
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for malformed or nonexisting entities C<EE<lt>...E<gt>>.
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for correct syntax of hyperlinks C<LE<lt>...E<gt>>. See L<perlpod>
1
N/A
for details.
1
N/A
1
N/A
=item *
1
N/A
1
N/A
Check for unresolved document-internal links. This check may also reveal
1
N/A
misspelled links that seem to be internal links but should be links
1
N/A
to something else.
1
N/A
1
N/A
=back
1
N/A
1
N/A
=head1 DIAGNOSTICS
1
N/A
1
N/A
=head2 Errors
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item * empty =headn
1
N/A
1
N/A
A heading (C<=head1> or C<=head2>) without any text? That ain't no
1
N/A
heading!
1
N/A
1
N/A
=item * =over on line I<N> without closing =back
1
N/A
1
N/A
The C<=over> command does not have a corresponding C<=back> before the
1
N/A
next heading (C<=head1> or C<=head2>) or the end of the file.
1
N/A
1
N/A
=item * =item without previous =over
1
N/A
1
N/A
=item * =back without previous =over
1
N/A
1
N/A
An C<=item> or C<=back> command has been found outside a
1
N/A
C<=over>/C<=back> block.
1
N/A
1
N/A
=item * No argument for =begin
1
N/A
1
N/A
A C<=begin> command was found that is not followed by the formatter
1
N/A
specification.
1
N/A
1
N/A
=item * =end without =begin
1
N/A
1
N/A
A standalone C<=end> command was found.
1
N/A
1
N/A
=item * Nested =begin's
1
N/A
1
N/A
There were at least two consecutive C<=begin> commands without
1
N/A
the corresponding C<=end>. Only one C<=begin> may be active at
1
N/A
a time.
1
N/A
1
N/A
=item * =for without formatter specification
1
N/A
1
N/A
There is no specification of the formatter after the C<=for> command.
1
N/A
1
N/A
=item * unresolved internal link I<NAME>
1
N/A
1
N/A
The given link to I<NAME> does not have a matching node in the current
1
N/A
POD. This also happend when a single word node name is not enclosed in
1
N/A
C<"">.
1
N/A
1
N/A
=item * Unknown command "I<CMD>"
1
N/A
1
N/A
An invalid POD command has been found. Valid are C<=head1>, C<=head2>,
1
N/A
C<=head3>, C<=head4>, C<=over>, C<=item>, C<=back>, C<=begin>, C<=end>,
1
N/A
C<=for>, C<=pod>, C<=cut>
1
N/A
1
N/A
=item * Unknown interior-sequence "I<SEQ>"
1
N/A
1
N/A
An invalid markup command has been encountered. Valid are:
1
N/A
C<BE<lt>E<gt>>, C<CE<lt>E<gt>>, C<EE<lt>E<gt>>, C<FE<lt>E<gt>>,
1
N/A
C<IE<lt>E<gt>>, C<LE<lt>E<gt>>, C<SE<lt>E<gt>>, C<XE<lt>E<gt>>,
1
N/A
C<ZE<lt>E<gt>>
1
N/A
1
N/A
=item * nested commands I<CMD>E<lt>...I<CMD>E<lt>...E<gt>...E<gt>
1
N/A
1
N/A
Two nested identical markup commands have been found. Generally this
1
N/A
does not make sense.
1
N/A
1
N/A
=item * garbled entity I<STRING>
1
N/A
1
N/A
The I<STRING> found cannot be interpreted as a character entity.
1
N/A
1
N/A
=item * Entity number out of range
1
N/A
1
N/A
An entity specified by number (dec, hex, oct) is out of range (1-255).
1
N/A
1
N/A
=item * malformed link LE<lt>E<gt>
1
N/A
1
N/A
The link found cannot be parsed because it does not conform to the
1
N/A
syntax described in L<perlpod>.
1
N/A
1
N/A
=item * nonempty ZE<lt>E<gt>
1
N/A
1
N/A
The C<ZE<lt>E<gt>> sequence is supposed to be empty.
1
N/A
1
N/A
=item * empty XE<lt>E<gt>
1
N/A
1
N/A
The index entry specified contains nothing but whitespace.
1
N/A
1
N/A
=item * Spurious text after =pod / =cut
1
N/A
1
N/A
The commands C<=pod> and C<=cut> do not take any arguments.
1
N/A
1
N/A
=item * Spurious character(s) after =back
1
N/A
1
N/A
The C<=back> command does not take any arguments.
1
N/A
1
N/A
=back
1
N/A
1
N/A
=head2 Warnings
1
N/A
1
N/A
These may not necessarily cause trouble, but indicate mediocre style.
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item * multiple occurrence of link target I<name>
1
N/A
1
N/A
The POD file has some C<=item>
and
/
or
C<=head> commands that have
1
N/A
the same text. Potential hyperlinks to such a text cannot be unique then.
1
N/A
1
N/A
=item * line containing nothing but whitespace in paragraph
1
N/A
1
N/A
There is some whitespace on a seemingly empty line. POD is very sensitive
1
N/A
to such things, so this is flagged. B<vi> users switch on the B<list>
1
N/A
option to avoid this problem.
1
N/A
1
N/A
=begin _disabled_
1
N/A
1
N/A
=item * file does not start with =head
1
N/A
1
N/A
The file starts with a different POD directive than head.
1
N/A
This is most probably something you do not want.
1
N/A
1
N/A
=end _disabled_
1
N/A
1
N/A
=item * previous =item has no contents
1
N/A
1
N/A
There is a list C<=item> right above the flagged line that has no
1
N/A
text contents. You probably want to delete empty items.
1
N/A
1
N/A
=item * preceding non-item paragraph(s)
1
N/A
1
N/A
A list introduced by C<=over> starts with a text or verbatim paragraph,
1
N/A
but continues with C<=item>s. Move the non-item paragraph out of the
1
N/A
C<=over>/C<=back> block.
1
N/A
1
N/A
=item * =item type mismatch (I<one> vs. I<two>)
1
N/A
1
N/A
A list started with e.g. a bulletted C<=item> and continued with a
1
N/A
numbered one. This is obviously inconsistent. For most translators the
1
N/A
type of the I<first> C<=item> determines the type of the list.
1
N/A
1
N/A
=item * I<N> unescaped C<E<lt>E<gt>> in paragraph
1
N/A
1
N/A
Angle brackets not written as C<E<lt>ltE<gt>> and C<E<lt>gtE<gt>>
1
N/A
can potentially cause errors as they could be misinterpreted as
1
N/A
markup commands. This is only printed when the -warnings level is
1
N/A
greater than 1.
1
N/A
1
N/A
=item * Unknown entity
1
N/A
1
N/A
A character entity was found that does not belong to the standard
1
N/A
ISO set or the POD specials C<verbar> and C<sol>.
1
N/A
1
N/A
=item * No items in =over
1
N/A
1
N/A
The list opened with C<=over> does not contain any items.
1
N/A
1
N/A
=item * No argument for =item
1
N/A
1
N/A
C<=item> without any parameters is deprecated. It should either be followed
1
N/A
by C<*> to indicate an unordered list, by a number (optionally followed
1
N/A
by a dot) to indicate an ordered (numbered) list or simple text for a
1
N/A
definition list.
1
N/A
1
N/A
=item * empty section in previous paragraph
1
N/A
1
N/A
The previous section (introduced by a C<=head> command) does not contain
1
N/A
any text. This usually indicates that something is missing. Note: A
1
N/A
C<=head1> followed immediately by C<=head2> does not trigger this warning.
1
N/A
1
N/A
=item * Verbatim paragraph in NAME section
1
N/A
1
N/A
The NAME section (C<=head1 NAME>) should consist of a single paragraph
1
N/A
with the
script
/
module
name, followed by a dash `-' and a very short
1
N/A
description of what the thing is good for.
1
N/A
1
N/A
=item * =headI<n> without preceding higher level
1
N/A
1
N/A
For example if there is a C<=head2> in the POD file prior to a
1
N/A
C<=head1>.
1
N/A
1
N/A
=back
1
N/A
1
N/A
=head2 Hyperlinks
1
N/A
1
N/A
There are some warnings wrt. malformed hyperlinks.
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item * ignoring
leading
/
trailing
whitespace in link
1
N/A
1
N/A
There is whitespace at the beginning or the end of the contents of
1
N/A
LE<lt>...E<gt>.
1
N/A
1
N/A
=item * (section) in '$page' deprecated
1
N/A
1
N/A
There is a section detected in the page name of LE<lt>...E<gt>, e.g.
1
N/A
C<LE<lt>passwd(2)E<gt>>. POD hyperlinks may point to POD documents only.
1
N/A
Please write C<CE<lt>passwd(2)E<gt>> instead. Some formatters are able
1
N/A
to expand this to appropriate code. For links to (builtin) functions,
1
N/A
please say C<LE<lt>
perlfunc
/
mkdirE
<gt>>, without ().
1
N/A
1
N/A
=item * alternative
text
/
node
'%s' contains non-escaped | or /
1
N/A
1
N/A
The characters C<|> and C</> are special in the LE<lt>...E<gt> context.
1
N/A
Although the hyperlink parser does its best to determine which "/" is
1
N/A
text and which is a delimiter in case of doubt, one ought to escape
1
N/A
these literal characters like this:
1
N/A
1
N/A
/ E<sol>
1
N/A
| E<verbar>
1
N/A
1
N/A
=back
1
N/A
1
N/A
=head1 RETURN VALUE
1
N/A
1
N/A
B<podchecker> returns the number of POD syntax errors found or -1 if
1
N/A
there were no POD commands at all found in the file.
1
N/A
1
N/A
=head1 EXAMPLES
1
N/A
1
N/A
See L</SYNOPSIS>
1
N/A
1
N/A
=head1 INTERFACE
1
N/A
1
N/A
While checking, this module collects document properties, e.g. the nodes
1
N/A
for hyperlinks (C<=headX>, C<=item>) and index entries (C<XE<lt>E<gt>>).
1
N/A
POD translators can use this feature to syntax-check and get the nodes in
1
N/A
a first pass before actually starting to convert. This is expensive in terms
1
N/A
of execution time, but allows for very robust conversions.
1
N/A
1
N/A
Since PodParser-1.24 the B<Pod::Checker> module uses only the B<poderror>
1
N/A
method to print errors and warnings. The summary output (e.g.
1
N/A
"Pod syntax OK") has been dropped from the module and has been included in
1
N/A
B<podchecker> (the script). This allows users of B<Pod::Checker> to
1
N/A
control completely the output behaviour. Users of B<podchecker> (the script)
1
N/A
get the well-known behaviour.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
#############################################################################
1
N/A
1
N/A
use
strict
;
1
N/A
#use diagnostics;
1
N/A
use
Carp
;
1
N/A
use
Exporter
;
1
N/A
use
Pod
::
Parser
;
1
N/A
1
N/A
use
vars
qw
(@
ISA
@
EXPORT
);
1
N/A
@
ISA
=
qw
(
Pod
::
Parser
);
1
N/A
@
EXPORT
=
qw
(&
podchecker
);
1
N/A
1
N/A
use
vars
qw
(%
VALID_COMMANDS
%
VALID_SEQUENCES
);
1
N/A
1
N/A
my
%
VALID_COMMANDS
= (
1
N/A
'pod'
=>
1
,
1
N/A
'cut'
=>
1
,
1
N/A
'head1'
=>
1
,
1
N/A
'head2'
=>
1
,
1
N/A
'head3'
=>
1
,
1
N/A
'head4'
=>
1
,
1
N/A
'over'
=>
1
,
1
N/A
'back'
=>
1
,
1
N/A
'item'
=>
1
,
1
N/A
'for'
=>
1
,
1
N/A
'begin'
=>
1
,
1
N/A
'end'
=>
1
,
1
N/A
);
1
N/A
1
N/A
my
%
VALID_SEQUENCES
= (
1
N/A
'I'
=>
1
,
1
N/A
'B'
=>
1
,
1
N/A
'S'
=>
1
,
1
N/A
'C'
=>
1
,
1
N/A
'L'
=>
1
,
1
N/A
'F'
=>
1
,
1
N/A
'X'
=>
1
,
1
N/A
'Z'
=>
1
,
1
N/A
'E'
=>
1
,
1
N/A
);
1
N/A
1
N/A
# stolen from HTML::Entities
1
N/A
my
%
ENTITIES
= (
1
N/A
# Some normal chars that have special meaning in SGML context
1
N/A
amp
=>
'&'
,
# ampersand
1
N/A
'gt'
=>
'>'
,
# greater than
1
N/A
'lt'
=>
'<'
,
# less than
1
N/A
quot
=>
'"'
,
# double quote
1
N/A
1
N/A
# PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML
1
N/A
AElig
=>
'�'
,
# capital AE diphthong (ligature)
1
N/A
Aacute
=>
'�'
,
# capital A, acute accent
1
N/A
Acirc
=>
'�'
,
# capital A, circumflex accent
1
N/A
Agrave
=>
'�'
,
# capital A, grave accent
1
N/A
Aring
=>
'�'
,
# capital A, ring
1
N/A
Atilde
=>
'�'
,
# capital A, tilde
1
N/A
Auml
=>
'�'
,
# capital A, dieresis or umlaut mark
1
N/A
Ccedil
=>
'�'
,
# capital C, cedilla
1
N/A
ETH
=>
'�'
,
# capital Eth, Icelandic
1
N/A
Eacute
=>
'�'
,
# capital E, acute accent
1
N/A
Ecirc
=>
'�'
,
# capital E, circumflex accent
1
N/A
Egrave
=>
'�'
,
# capital E, grave accent
1
N/A
Euml
=>
'�'
,
# capital E, dieresis or umlaut mark
1
N/A
Iacute
=>
'�'
,
# capital I, acute accent
1
N/A
Icirc
=>
'�'
,
# capital I, circumflex accent
1
N/A
Igrave
=>
'�'
,
# capital I, grave accent
1
N/A
Iuml
=>
'�'
,
# capital I, dieresis or umlaut mark
1
N/A
Ntilde
=>
'�'
,
# capital N, tilde
1
N/A
Oacute
=>
'�'
,
# capital O, acute accent
1
N/A
Ocirc
=>
'�'
,
# capital O, circumflex accent
1
N/A
Ograve
=>
'�'
,
# capital O, grave accent
1
N/A
Oslash
=>
'�'
,
# capital O, slash
1
N/A
Otilde
=>
'�'
,
# capital O, tilde
1
N/A
Ouml
=>
'�'
,
# capital O, dieresis or umlaut mark
1
N/A
THORN
=>
'�'
,
# capital THORN, Icelandic
1
N/A
Uacute
=>
'�'
,
# capital U, acute accent
1
N/A
Ucirc
=>
'�'
,
# capital U, circumflex accent
1
N/A
Ugrave
=>
'�'
,
# capital U, grave accent
1
N/A
Uuml
=>
'�'
,
# capital U, dieresis or umlaut mark
1
N/A
Yacute
=>
'�'
,
# capital Y, acute accent
1
N/A
aacute
=>
'�'
,
# small a, acute accent
1
N/A
acirc
=>
'�'
,
# small a, circumflex accent
1
N/A
aelig
=>
'�'
,
# small ae diphthong (ligature)
1
N/A
agrave
=>
'�'
,
# small a, grave accent
1
N/A
aring
=>
'�'
,
# small a, ring
1
N/A
atilde
=>
'�'
,
# small a, tilde
1
N/A
auml
=>
'�'
,
# small a, dieresis or umlaut mark
1
N/A
ccedil
=>
'�'
,
# small c, cedilla
1
N/A
eacute
=>
'�'
,
# small e, acute accent
1
N/A
ecirc
=>
'�'
,
# small e, circumflex accent
1
N/A
egrave
=>
'�'
,
# small e, grave accent
1
N/A
eth
=>
'�'
,
# small eth, Icelandic
1
N/A
euml
=>
'�'
,
# small e, dieresis or umlaut mark
1
N/A
iacute
=>
'�'
,
# small i, acute accent
1
N/A
icirc
=>
'�'
,
# small i, circumflex accent
1
N/A
igrave
=>
'�'
,
# small i, grave accent
1
N/A
iuml
=>
'�'
,
# small i, dieresis or umlaut mark
1
N/A
ntilde
=>
'�'
,
# small n, tilde
1
N/A
oacute
=>
'�'
,
# small o, acute accent
1
N/A
ocirc
=>
'�'
,
# small o, circumflex accent
1
N/A
ograve
=>
'�'
,
# small o, grave accent
1
N/A
oslash
=>
'�'
,
# small o, slash
1
N/A
otilde
=>
'�'
,
# small o, tilde
1
N/A
ouml
=>
'�'
,
# small o, dieresis or umlaut mark
1
N/A
szlig
=>
'�'
,
# small sharp s, German (sz ligature)
1
N/A
thorn
=>
'�'
,
# small thorn, Icelandic
1
N/A
uacute
=>
'�'
,
# small u, acute accent
1
N/A
ucirc
=>
'�'
,
# small u, circumflex accent
1
N/A
ugrave
=>
'�'
,
# small u, grave accent
1
N/A
uuml
=>
'�'
,
# small u, dieresis or umlaut mark
1
N/A
yacute
=>
'�'
,
# small y, acute accent
1
N/A
yuml
=>
'�'
,
# small y, dieresis or umlaut mark
1
N/A
1
N/A
# Some extra Latin 1 chars that are listed in the HTML3.2 draft (21-May-96)
1
N/A
copy
=>
'�'
,
# copyright sign
1
N/A
reg
=>
'�'
,
# registered sign
1
N/A
nbsp
=>
"\240"
,
# non breaking space
1
N/A
1
N/A
# Additional ISO-8859/1 entities listed in rfc1866 (section 14)
1
N/A
iexcl
=>
'�'
,
1
N/A
cent
=>
'�'
,
1
N/A
pound
=>
'�'
,
1
N/A
curren
=>
'�'
,
1
N/A
yen
=>
'�'
,
1
N/A
brvbar
=>
'�'
,
1
N/A
sect
=>
'�'
,
1
N/A
uml
=>
'�'
,
1
N/A
ordf
=>
'�'
,
1
N/A
laquo
=>
'�'
,
1
N/A
'not'
=>
'�'
,
# not is a keyword in perl
1
N/A
shy
=>
'�'
,
1
N/A
macr
=>
'�'
,
1
N/A
deg
=>
'�'
,
1
N/A
plusmn
=>
'�'
,
1
N/A
sup1
=>
'�'
,
1
N/A
sup2
=>
'�'
,
1
N/A
sup3
=>
'�'
,
1
N/A
acute
=>
'�'
,
1
N/A
micro
=>
'�'
,
1
N/A
para
=>
'�'
,
1
N/A
middot
=>
'�'
,
1
N/A
cedil
=>
'�'
,
1
N/A
ordm
=>
'�'
,
1
N/A
raquo
=>
'�'
,
1
N/A
frac14
=>
'�'
,
1
N/A
frac12
=>
'�'
,
1
N/A
frac34
=>
'�'
,
1
N/A
iquest
=>
'�'
,
1
N/A
'times'
=>
'�'
,
# times is a keyword in perl
1
N/A
divide
=>
'�'
,
1
N/A
1
N/A
# some POD special entities
1
N/A
verbar
=>
'|'
,
1
N/A
sol
=>
'/'
1
N/A
);
1
N/A
1
N/A
##---------------------------------------------------------------------------
1
N/A
1
N/A
##---------------------------------
1
N/A
## Function definitions begin here
1
N/A
##---------------------------------
1
N/A
1
N/A
sub
podchecker
( $ ; $ % ) {
1
N/A
my
($
infile
, $
outfile
, %
options
) = @_;
1
N/A
local
$_;
1
N/A
1
N/A
## Set defaults
1
N/A
$
infile
||= \*
STDIN
;
1
N/A
$
outfile
||= \*
STDERR
;
1
N/A
1
N/A
## Now create a pod checker
1
N/A
my
$
checker
=
new
Pod
::
Checker
(%
options
);
1
N/A
1
N/A
## Now check the pod document for errors
1
N/A
$
checker
->
parse_from_file
($
infile
, $
outfile
);
1
N/A
1
N/A
## Return the number of errors found
1
N/A
return
$
checker
->
num_errors
();
1
N/A
}
1
N/A
1
N/A
##---------------------------------------------------------------------------
1
N/A
1
N/A
##-------------------------------
1
N/A
## Method definitions begin here
1
N/A
##-------------------------------
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=over 4
1
N/A
1
N/A
=item C<Pod::Checker-E<gt>new( %options )>
1
N/A
1
N/A
Return a reference to a new Pod::Checker object that inherits from
1
N/A
Pod::Parser and is used for calling the required methods later. The
1
N/A
following options are recognized:
1
N/A
1
N/A
C<-warnings =E<gt> num>
1
N/A
Print warnings if C<num> is true. The higher the value of C<num>,
1
N/A
the more warnings are printed. Currently there are only levels 1 and 2.
1
N/A
1
N/A
C<-quiet =E<gt> num>
1
N/A
If C<num> is true, do not print any
errors
/
warnings
. This is useful
1
N/A
when Pod::Checker is used to munge POD code into plain text from within
1
N/A
POD formatters.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
## sub new {
1
N/A
## my $this = shift;
1
N/A
## my $class = ref($this) || $this;
1
N/A
## my %params = @_;
1
N/A
## my $self = {%params};
1
N/A
## bless $self, $class;
1
N/A
## $self->initialize();
1
N/A
## return $self;
1
N/A
## }
1
N/A
1
N/A
sub
initialize
{
1
N/A
my
$
self
=
shift
;
1
N/A
## Initialize number of errors, and setup an error function to
1
N/A
## increment this number and then print to the designated output.
1
N/A
$
self
->{
_NUM_ERRORS
} =
0
;
1
N/A
$
self
->{
_NUM_WARNINGS
} =
0
;
1
N/A
$
self
->{-
quiet
} ||=
0
;
1
N/A
# set the error handling subroutine
1
N/A
$
self
->
errorsub
($
self
->{-
quiet
} ?
sub
{
1
; } :
'poderror'
);
1
N/A
$
self
->{
_commands
} =
0
;
# total number of POD commands encountered
1
N/A
$
self
->{
_list_stack
} = [];
# stack for nested lists
1
N/A
$
self
->{
_have_begin
} =
''
;
# stores =begin
1
N/A
$
self
->{
_links
} = [];
# stack for internal hyperlinks
1
N/A
$
self
->{
_nodes
} = [];
# stack for =head/=item nodes
1
N/A
$
self
->{
_index
} = [];
# text in X<>
1
N/A
# print warnings?
1
N/A
$
self
->{-
warnings
} =
1
unless
(
defined
$
self
->{-
warnings
});
1
N/A
$
self
->{
_current_head1
} =
''
;
# the current =head1 block
1
N/A
$
self
->
parseopts
(-
process_cut_cmd
=>
1
, -
warnings
=> $
self
->{-
warnings
});
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>poderror( @args )>
1
N/A
1
N/A
=item C<$checker-E<gt>poderror( {%opts}, @args )>
1
N/A
1
N/A
Internal method for printing errors and warnings. If no options are
1
N/A
given, simply prints "@_". The following options are recognized and used
1
N/A
to form the output:
1
N/A
1
N/A
-msg
1
N/A
1
N/A
A message to print prior to C<@args>.
1
N/A
1
N/A
-line
1
N/A
1
N/A
The line number the error occurred in.
1
N/A
1
N/A
-file
1
N/A
1
N/A
The file (name) the error occurred in.
1
N/A
1
N/A
-severity
1
N/A
1
N/A
The error level, should be 'WARNING' or 'ERROR'.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
# Invoked as $self->poderror( @args ), or $self->poderror( {%opts}, @args )
1
N/A
sub
poderror
{
1
N/A
my
$
self
=
shift
;
1
N/A
my
%
opts
= (
ref
$_[
0
]) ? %{
shift
()} : ();
1
N/A
1
N/A
## Retrieve options
1
N/A
chomp
(
my
$
msg
= ($
opts
{-
msg
} ||
""
).
"@_"
);
1
N/A
my
$
line
= (
exists
$
opts
{-
line
}) ?
" at line $opts{-line}"
:
""
;
1
N/A
my
$
file
= (
exists
$
opts
{-
file
}) ?
" in file $opts{-file}"
:
""
;
1
N/A
unless
(
exists
$
opts
{-
severity
}) {
1
N/A
## See if can find severity in message prefix
1
N/A
$
opts
{-
severity
} = $
1
if
( $
msg
=~ s/^\**\s*([A-Z]{
3
,}):\s+// );
1
N/A
}
1
N/A
my
$
severity
= (
exists
$
opts
{-
severity
}) ?
"*** $opts{-severity}: "
:
""
;
1
N/A
1
N/A
## Increment error count and print message "
1
N/A
++($
self
->{
_NUM_ERRORS
})
1
N/A
if
(!%
opts
|| ($
opts
{-
severity
} && $
opts
{-
severity
}
eq
'ERROR'
));
1
N/A
++($
self
->{
_NUM_WARNINGS
})
1
N/A
if
(!%
opts
|| ($
opts
{-
severity
} && $
opts
{-
severity
}
eq
'WARNING'
));
1
N/A
my
$
out_fh
= $
self
->
output_handle
() || \*
STDERR
;
1
N/A
print
$
out_fh
($
severity
, $
msg
, $
line
, $
file
,
"\n"
)
1
N/A
if
($
self
->{-
warnings
} || !%
opts
|| $
opts
{-
severity
}
ne
'WARNING'
);
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>num_errors()>
1
N/A
1
N/A
Set (if argument specified) and retrieve the number of errors found.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
sub
num_errors
{
1
N/A
return
(@_ >
1
) ? ($_[
0
]->{
_NUM_ERRORS
} = $_[
1
]) : $_[
0
]->{
_NUM_ERRORS
};
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>num_warnings()>
1
N/A
1
N/A
Set (if argument specified) and retrieve the number of warnings found.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
sub
num_warnings
{
1
N/A
return
(@_ >
1
) ? ($_[
0
]->{
_NUM_WARNINGS
} = $_[
1
]) : $_[
0
]->{
_NUM_WARNINGS
};
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>name()>
1
N/A
1
N/A
Set (if argument specified) and retrieve the canonical name of POD as
1
N/A
found in the C<=head1 NAME> section.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
sub
name
{
1
N/A
return
(@_ >
1
&& $_[
1
]) ?
1
N/A
($_[
0
]->{-
name
} = $_[
1
]) : $_[
0
]->{-
name
};
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>node()>
1
N/A
1
N/A
Add (if argument specified) and retrieve the nodes (as defined by C<=headX>
1
N/A
and C<=item>) of the current POD. The nodes are returned in the order of
1
N/A
their occurrence. They consist of plain text, each piece of whitespace is
1
N/A
collapsed to a single blank.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
sub
node
{
1
N/A
my
($
self
,$
text
) = @_;
1
N/A
if
(
defined
$
text
) {
1
N/A
$
text
=~ s/\s+$//s;
# strip trailing whitespace
1
N/A
$
text
=~ s/\s+/ /
gs
;
# collapse whitespace
1
N/A
# add node, order important!
1
N/A
push
(@{$
self
->{
_nodes
}}, $
text
);
1
N/A
# keep also a uniqueness counter
1
N/A
$
self
->{
_unique_nodes
}->{$
text
}++
if
($
text
!~ /^\s*$/s);
1
N/A
return
$
text
;
1
N/A
}
1
N/A
@{$
self
->{
_nodes
}};
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>idx()>
1
N/A
1
N/A
Add (if argument specified) and retrieve the index entries (as defined by
1
N/A
C<XE<lt>E<gt>>) of the current POD. They consist of plain text, each piece
1
N/A
of whitespace is collapsed to a single blank.
1
N/A
1
N/A
=cut
1
N/A
1
N/A
#
set
/
return
index entries of current POD
1
N/A
sub
idx
{
1
N/A
my
($
self
,$
text
) = @_;
1
N/A
if
(
defined
$
text
) {
1
N/A
$
text
=~ s/\s+$//s;
# strip trailing whitespace
1
N/A
$
text
=~ s/\s+/ /
gs
;
# collapse whitespace
1
N/A
# add node, order important!
1
N/A
push
(@{$
self
->{
_index
}}, $
text
);
1
N/A
# keep also a uniqueness counter
1
N/A
$
self
->{
_unique_nodes
}->{$
text
}++
if
($
text
!~ /^\s*$/s);
1
N/A
return
$
text
;
1
N/A
}
1
N/A
@{$
self
->{
_index
}};
1
N/A
}
1
N/A
1
N/A
##################################
1
N/A
1
N/A
=item C<$checker-E<gt>hyperlink()>
1
N/A
1
N/A
Add (if argument specified) and retrieve the hyperlinks (as defined by
1
N/A
C<LE<lt>E<gt>>) of the current POD. They consist of a 2-item array: line
1
N/A
number and C<Pod::Hyperlink> object.
1
N/A
1
N/A
=back
1
N/A
1
N/A
=cut
1
N/A
1
N/A
#
set
/
return
hyperlinks of the current POD
1
N/A
sub
hyperlink
{
1
N/A
my
$
self
=
shift
;
1
N/A
if
($_[
0
]) {
1
N/A
push
(@{$
self
->{
_links
}}, $_[
0
]);
1
N/A
return
$_[
0
];
1
N/A
}
1
N/A
@{$
self
->{
_links
}};
1
N/A
}
1
N/A
1
N/A
## overrides for Pod::Parser
1
N/A
1
N/A
sub
end_pod
{
1
N/A
## Do some final checks and
1
N/A
## print the number of errors found
1
N/A
my
$
self
=
shift
;
1
N/A
my
$
infile
= $
self
->
input_file
();
1
N/A
my
$
out_fh
= $
self
->
output_handle
();
1
N/A
1
N/A
if
(@{$
self
->{
_list_stack
}}) {
1
N/A
my
$
list
;
1
N/A
while
(($
list
= $
self
->
_close_list
(
'EOF'
,$
infile
)) &&
1
N/A
$
list
->
indent
()
ne
'auto'
) {
1
N/A
$
self
->
poderror
({ -
line
=>
'EOF'
, -
file
=> $
infile
,
1
N/A
-
severity
=>
'ERROR'
, -
msg
=>
"=over on line "
.
1
N/A
$
list
->
start
() .
" without closing =back"
});
#"
1
N/A
}
1
N/A
}
1
N/A
1
N/A
# check validity of document internal hyperlinks
1
N/A
# first build the node names from the paragraph text
1
N/A
my
%
nodes
;
1
N/A
foreach
($
self
->
node
()) {
1
N/A
$
nodes
{$_} =
1
;
1
N/A
if
(/^(\S+)\s+\S/) {
1
N/A
# we have more than one word. Use the first as a node, too.
1
N/A
# This is used heavily in perlfunc.pod
1
N/A
$
nodes
{$
1
} ||=
2
;
# derived node
1
N/A
}
1
N/A
}
1
N/A
foreach
($
self
->
idx
()) {
1
N/A
$
nodes
{$_} =
3
;
# index node
1
N/A
}
1
N/A
foreach
($
self
->
hyperlink
()) {
1
N/A
my
($
line
,$
link
) = @$_;
1
N/A
# _TODO_ what if there is a link to the page itself by the name,
1
N/A
# e.g. in Tk::Pod : L<Tk::Pod/"DESCRIPTION">
1
N/A
if
($
link
->
node
() && !$
link
->
page
() && $
link
->
type
()
ne
'hyperlink'
) {
1
N/A
my
$
node
= $
self
->
_check_ptree
($
self
->
parse_text
($
link
->
node
(),
1
N/A
$
line
), $
line
, $
infile
,
'L'
);
1
N/A
if
($
node
&& !$
nodes
{$
node
}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
||
''
, -
file
=> $
infile
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"unresolved internal link '$node'"
});
1
N/A
}
1
N/A
}
1
N/A
}
1
N/A
1
N/A
# check the internal nodes for uniqueness. This pertains to
1
N/A
# =headX, =item and X<...>
1
N/A
foreach
(
grep
($
self
->{
_unique_nodes
}->{$_} >
1
,
1
N/A
keys
%{$
self
->{
_unique_nodes
}})) {
1
N/A
$
self
->
poderror
({ -
line
=>
'-'
, -
file
=> $
infile
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"multiple occurrence of link target '$_'"
});
1
N/A
}
1
N/A
1
N/A
# no POD found here
1
N/A
$
self
->
num_errors
(-
1
)
if
($
self
->{
_commands
} ==
0
);
1
N/A
}
1
N/A
1
N/A
# check a POD command directive
1
N/A
sub
command
{
1
N/A
my
($
self
, $
cmd
, $
paragraph
, $
line_num
, $
pod_para
) = @_;
1
N/A
my
($
file
, $
line
) = $
pod_para
->
file_line
;
1
N/A
## Check the command syntax
1
N/A
my
$
arg
;
# this will hold the command argument
1
N/A
if
(! $
VALID_COMMANDS
{$
cmd
}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
, -
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Unknown command '$cmd'"
});
1
N/A
}
1
N/A
else
{
# found a valid command
1
N/A
$
self
->{
_commands
}++;
# delete this line if below is enabled again
1
N/A
1
N/A
##### following check disabled due to strong request
1
N/A
#if(!$self->{_commands}++ && $cmd !~ /^head/) {
1
N/A
# $self->poderror({ -line => $line, -file => $file,
1
N/A
# -severity => 'WARNING',
1
N/A
# -msg => "file does not start with =head" });
1
N/A
#}
1
N/A
1
N/A
# check syntax of particular command
1
N/A
if
($
cmd
eq
'over'
) {
1
N/A
# check for argument
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
my
$
indent
=
4
;
# default
1
N/A
if
($
arg
&& $
arg
=~ /^\s*(\d+)\s*$/) {
1
N/A
$
indent
= $
1
;
1
N/A
}
1
N/A
# start a new list
1
N/A
$
self
->
_open_list
($
indent
,$
line
,$
file
);
1
N/A
}
1
N/A
elsif
($
cmd
eq
'item'
) {
1
N/A
# are we in a list?
1
N/A
unless
(@{$
self
->{
_list_stack
}}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"=item without previous =over"
});
1
N/A
# auto-open in case we encounter many more
1
N/A
$
self
->
_open_list
(
'auto'
,$
line
,$
file
);
1
N/A
}
1
N/A
my
$
list
= $
self
->{
_list_stack
}->[
0
];
1
N/A
# check whether the previous item had some contents
1
N/A
if
(
defined
$
self
->{
_list_item_contents
} &&
1
N/A
$
self
->{
_list_item_contents
} ==
0
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"previous =item has no contents"
});
1
N/A
}
1
N/A
if
($
list
->{
_has_par
}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"preceding non-item paragraph(s)"
});
1
N/A
delete
$
list
->{
_has_par
};
1
N/A
}
1
N/A
# check for argument
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
, $
file
);
1
N/A
if
($
arg
&& $
arg
=~ /(\S+)/) {
1
N/A
$
arg
=~ s/[\s\n]+$//;
1
N/A
my
$
type
;
1
N/A
if
($
arg
=~ /^[*]\s*(\S*.*)/) {
1
N/A
$
type
=
'bullet'
;
1
N/A
$
self
->{
_list_item_contents
} = $
1
?
1
:
0
;
1
N/A
$
arg
= $
1
;
1
N/A
}
1
N/A
elsif
($
arg
=~ /^\d+\.?\s*(\S*)/) {
1
N/A
$
type
=
'number'
;
1
N/A
$
self
->{
_list_item_contents
} = $
1
?
1
:
0
;
1
N/A
$
arg
= $
1
;
1
N/A
}
1
N/A
else
{
1
N/A
$
type
=
'definition'
;
1
N/A
$
self
->{
_list_item_contents
} =
1
;
1
N/A
}
1
N/A
my
$
first
= $
list
->
type
();
1
N/A
if
($
first
&& $
first
ne
$
type
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"=item type mismatch ('$first' vs. '$type')"
});
1
N/A
}
1
N/A
else
{
# first item
1
N/A
$
list
->
type
($
type
);
1
N/A
}
1
N/A
}
1
N/A
else
{
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"No argument for =item"
});
1
N/A
$
arg
=
' '
;
# empty
1
N/A
$
self
->{
_list_item_contents
} =
0
;
1
N/A
}
1
N/A
# add this item
1
N/A
$
list
->
item
($
arg
);
1
N/A
# remember this node
1
N/A
$
self
->
node
($
arg
);
1
N/A
}
1
N/A
elsif
($
cmd
eq
'back'
) {
1
N/A
# check if we have an open list
1
N/A
unless
(@{$
self
->{
_list_stack
}}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"=back without previous =over"
});
1
N/A
}
1
N/A
else
{
1
N/A
# check for spurious characters
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
if
($
arg
&& $
arg
=~ /\S/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Spurious character(s) after =back"
});
1
N/A
}
1
N/A
# close list
1
N/A
my
$
list
= $
self
->
_close_list
($
line
,$
file
);
1
N/A
# check for empty lists
1
N/A
if
(!$
list
->
item
() && $
self
->{-
warnings
}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"No items in =over (at line "
.
1
N/A
$
list
->
start
() .
") / =back list"
});
#"
1
N/A
}
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
=~ /^
head
(\d+)/) {
1
N/A
my
$
hnum
= $
1
;
1
N/A
$
self
->{
"_have_head_$hnum"
}++;
# count head types
1
N/A
if
($
hnum
>
1
&& !$
self
->{
"_have_head_"
.($
hnum
-
1
)}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"=head$hnum without preceding higher level"
});
1
N/A
}
1
N/A
# check whether the previous =head section had some contents
1
N/A
if
(
defined
$
self
->{
_commands_in_head
} &&
1
N/A
$
self
->{
_commands_in_head
} ==
0
&&
1
N/A
defined
$
self
->{
_last_head
} &&
1
N/A
$
self
->{
_last_head
} >= $
hnum
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"empty section in previous paragraph"
});
1
N/A
}
1
N/A
$
self
->{
_commands_in_head
} = -
1
;
1
N/A
$
self
->{
_last_head
} = $
hnum
;
1
N/A
# check if there is an open list
1
N/A
if
(@{$
self
->{
_list_stack
}}) {
1
N/A
my
$
list
;
1
N/A
while
(($
list
= $
self
->
_close_list
($
line
,$
file
)) &&
1
N/A
$
list
->
indent
()
ne
'auto'
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"=over on line "
. $
list
->
start
() .
1
N/A
" without closing =back (at $cmd)"
});
1
N/A
}
1
N/A
}
1
N/A
# remember this node
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
$
arg
=~ s/[\s\n]+$//s;
1
N/A
$
self
->
node
($
arg
);
1
N/A
unless
(
length
($
arg
)) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"empty =$cmd"
});
1
N/A
}
1
N/A
if
($
cmd
eq
'head1'
) {
1
N/A
$
self
->{
_current_head1
} = $
arg
;
1
N/A
}
else
{
1
N/A
$
self
->{
_current_head1
} =
''
;
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
eq
'begin'
) {
1
N/A
if
($
self
->{
_have_begin
}) {
1
N/A
# already have a begin
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Nested =begin's (first at line "
.
1
N/A
$
self
->{
_have_begin
} .
")"
});
1
N/A
}
1
N/A
else
{
1
N/A
# check for argument
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
unless
($
arg
&& $
arg
=~ /(\S+)/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"No argument for =begin"
});
1
N/A
}
1
N/A
# remember the =begin
1
N/A
$
self
->{
_have_begin
} =
"$line:$1"
;
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
eq
'end'
) {
1
N/A
if
($
self
->{
_have_begin
}) {
1
N/A
# close the existing =begin
1
N/A
$
self
->{
_have_begin
} =
''
;
1
N/A
# check for spurious characters
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
# the closing argument is optional
1
N/A
#if($arg && $arg =~ /\S/) {
1
N/A
# $self->poderror({ -line => $line, -file => $file,
1
N/A
# -severity => 'WARNING',
1
N/A
# -msg => "Spurious character(s) after =end" });
1
N/A
#}
1
N/A
}
1
N/A
else
{
1
N/A
# don't have a matching =begin
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"=end without =begin"
});
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
eq
'for'
) {
1
N/A
unless
($
paragraph
=~ /\s*(\S+)\s*/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"=for without formatter specification"
});
1
N/A
}
1
N/A
$
arg
=
''
;
# do not expand paragraph below
1
N/A
}
1
N/A
elsif
($
cmd
=~ /^(
pod
|
cut
)$/) {
1
N/A
# check for argument
1
N/A
$
arg
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
if
($
arg
&& $
arg
=~ /(\S+)/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Spurious text after =$cmd"
});
1
N/A
}
1
N/A
}
1
N/A
$
self
->{
_commands_in_head
}++;
1
N/A
## Check the interior sequences in the command-text
1
N/A
$
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
)
1
N/A
unless
(
defined
$
arg
);
1
N/A
}
1
N/A
}
1
N/A
1
N/A
sub
_open_list
1
N/A
{
1
N/A
my
($
self
,$
indent
,$
line
,$
file
) = @_;
1
N/A
my
$
list
=
Pod
::
List
->
new
(
1
N/A
-
indent
=> $
indent
,
1
N/A
-
start
=> $
line
,
1
N/A
-
file
=> $
file
);
1
N/A
unshift
(@{$
self
->{
_list_stack
}}, $
list
);
1
N/A
undef
$
self
->{
_list_item_contents
};
1
N/A
$
list
;
1
N/A
}
1
N/A
1
N/A
sub
_close_list
1
N/A
{
1
N/A
my
($
self
,$
line
,$
file
) = @_;
1
N/A
my
$
list
=
shift
(@{$
self
->{
_list_stack
}});
1
N/A
if
(
defined
$
self
->{
_list_item_contents
} &&
1
N/A
$
self
->{
_list_item_contents
} ==
0
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"previous =item has no contents"
});
1
N/A
}
1
N/A
undef
$
self
->{
_list_item_contents
};
1
N/A
$
list
;
1
N/A
}
1
N/A
1
N/A
# process a block of some text
1
N/A
sub
interpolate_and_check
{
1
N/A
my
($
self
, $
paragraph
, $
line
, $
file
) = @_;
1
N/A
## Check the interior sequences in the command-text
1
N/A
# and return the text
1
N/A
$
self
->
_check_ptree
(
1
N/A
$
self
->
parse_text
($
paragraph
,$
line
), $
line
, $
file
,
''
);
1
N/A
}
1
N/A
1
N/A
sub
_check_ptree
{
1
N/A
my
($
self
,$
ptree
,$
line
,$
file
,$
nestlist
) = @_;
1
N/A
local
($_);
1
N/A
my
$
text
=
''
;
1
N/A
# process each node in the parse tree
1
N/A
foreach
(@$
ptree
) {
1
N/A
# regular text chunk
1
N/A
unless
(
ref
) {
1
N/A
# count the unescaped angle brackets
1
N/A
# complain only when warning level is greater than 1
1
N/A
if
($
self
->{-
warnings
} && $
self
->{-
warnings
}>
1
) {
1
N/A
my
$
count
;
1
N/A
if
($
count
=
tr
/<>/<>/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"$count unescaped <> in paragraph"
});
1
N/A
}
1
N/A
}
1
N/A
$
text
.= $_;
1
N/A
next
;
1
N/A
}
1
N/A
# have an interior sequence
1
N/A
my
$
cmd
= $_->
cmd_name
();
1
N/A
my
$
contents
= $_->
parse_tree
();
1
N/A
($
file
,$
line
) = $_->
file_line
();
1
N/A
# check for valid tag
1
N/A
if
(! $
VALID_SEQUENCES
{$
cmd
}) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
qq
(
Unknown
interior
-
sequence
'$cmd'
)});
1
N/A
# expand it anyway
1
N/A
$
text
.= $
self
->
_check_ptree
($
contents
, $
line
, $
file
,
"$nestlist$cmd"
);
1
N/A
next
;
1
N/A
}
1
N/A
if
($
nestlist
=~ /$
cmd
/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"nested commands $cmd<...$cmd<...>...>"
});
1
N/A
# _TODO_ should we add the contents anyway?
1
N/A
# expand it anyway, see below
1
N/A
}
1
N/A
if
($
cmd
eq
'E'
) {
1
N/A
# preserve entities
1
N/A
if
(@$
contents
>
1
||
ref
$$
contents
[
0
] || $$
contents
[
0
] !~ /^\w+$/) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"garbled entity "
. $_->
raw_text
()});
1
N/A
next
;
1
N/A
}
1
N/A
my
$
ent
= $$
contents
[
0
];
1
N/A
my
$
val
;
1
N/A
if
($
ent
=~ /^
0
x[
0
-
9
a-f]+$/i) {
1
N/A
# hexadec entity
1
N/A
$
val
=
hex
($
ent
);
1
N/A
}
1
N/A
elsif
($
ent
=~ /^
0
\d+$/) {
1
N/A
# octal
1
N/A
$
val
=
oct
($
ent
);
1
N/A
}
1
N/A
elsif
($
ent
=~ /^\d+$/) {
1
N/A
# numeric entity
1
N/A
$
val
= $
ent
;
1
N/A
}
1
N/A
if
(
defined
$
val
) {
1
N/A
if
($
val
>
0
&& $
val
<
256
) {
1
N/A
$
text
.=
chr
($
val
);
1
N/A
}
1
N/A
else
{
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Entity number out of range "
. $_->
raw_text
()});
1
N/A
}
1
N/A
}
1
N/A
elsif
($
ENTITIES
{$
ent
}) {
1
N/A
# known ISO entity
1
N/A
$
text
.= $
ENTITIES
{$
ent
};
1
N/A
}
1
N/A
else
{
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
"Unknown entity "
. $_->
raw_text
()});
1
N/A
$
text
.=
"E<$ent>"
;
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
eq
'L'
) {
1
N/A
# try to parse the hyperlink
1
N/A
my
$
link
=
Pod
::
Hyperlink
->
new
($
contents
->
raw_text
());
1
N/A
unless
(
defined
$
link
) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"malformed link "
. $_->
raw_text
() .
" : $@"
});
1
N/A
next
;
1
N/A
}
1
N/A
$
link
->
line
($
line
);
# remember line
1
N/A
if
($
self
->{-
warnings
}) {
1
N/A
foreach
my
$w ($
link
->
warning
()) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=> $w });
1
N/A
}
1
N/A
}
1
N/A
# check the link text
1
N/A
$
text
.= $
self
->
_check_ptree
($
self
->
parse_text
($
link
->
text
(),
1
N/A
$
line
), $
line
, $
file
,
"$nestlist$cmd"
);
1
N/A
# remember link
1
N/A
$
self
->
hyperlink
([$
line
,$
link
]);
1
N/A
}
1
N/A
elsif
($
cmd
=~ /[
BCFIS
]/) {
1
N/A
# add the guts
1
N/A
$
text
.= $
self
->
_check_ptree
($
contents
, $
line
, $
file
,
"$nestlist$cmd"
);
1
N/A
}
1
N/A
elsif
($
cmd
eq
'Z'
) {
1
N/A
if
(
length
($
contents
->
raw_text
())) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Nonempty Z<>"
});
1
N/A
}
1
N/A
}
1
N/A
elsif
($
cmd
eq
'X'
) {
1
N/A
my
$
idx
= $
self
->
_check_ptree
($
contents
, $
line
, $
file
,
"$nestlist$cmd"
);
1
N/A
if
($
idx
=~ /^\s*$/s) {
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'ERROR'
,
1
N/A
-
msg
=>
"Empty X<>"
});
1
N/A
}
1
N/A
else
{
1
N/A
# remember this node
1
N/A
$
self
->
idx
($
idx
);
1
N/A
}
1
N/A
}
1
N/A
else
{
1
N/A
# not reached
1
N/A
die
"internal error"
;
1
N/A
}
1
N/A
}
1
N/A
$
text
;
1
N/A
}
1
N/A
1
N/A
# process a block of verbatim text
1
N/A
sub
verbatim
{
1
N/A
## Nothing particular to check
1
N/A
my
($
self
, $
paragraph
, $
line_num
, $
pod_para
) = @_;
1
N/A
1
N/A
$
self
->
_preproc_par
($
paragraph
);
1
N/A
1
N/A
if
($
self
->{
_current_head1
}
eq
'NAME'
) {
1
N/A
my
($
file
, $
line
) = $
pod_para
->
file_line
;
1
N/A
$
self
->
poderror
({ -
line
=> $
line
, -
file
=> $
file
,
1
N/A
-
severity
=>
'WARNING'
,
1
N/A
-
msg
=>
'Verbatim paragraph in NAME section'
});
1
N/A
}
1
N/A
}
1
N/A
1
N/A
# process a block of regular text
1
N/A
sub
textblock
{
1
N/A
my
($
self
, $
paragraph
, $
line_num
, $
pod_para
) = @_;
1
N/A
my
($
file
, $
line
) = $
pod_para
->
file_line
;
1
N/A
1
N/A
$
self
->
_preproc_par
($
paragraph
);
1
N/A
1
N/A
# skip this paragraph if in a =begin block
1
N/A
unless
($
self
->{
_have_begin
}) {
1
N/A
my
$
block
= $
self
->
interpolate_and_check
($
paragraph
, $
line
,$
file
);
1
N/A
if
($
self
->{
_current_head1
}
eq
'NAME'
) {
1
N/A
if
($
block
=~ /^\s*(\S+?)\s*[,-]/) {
1
N/A
# this is the canonical name
1
N/A
$
self
->{-
name
} = $
1
unless
(
defined
$
self
->{-
name
});
1
N/A
}
1
N/A
}
1
N/A
}
1
N/A
}
1
N/A
1
N/A
sub
_preproc_par
1
N/A
{
1
N/A
my
$
self
=
shift
;
1
N/A
$_[
0
] =~ s/[\s\n]+$//;
1
N/A
if
($_[
0
]) {
1
N/A
$
self
->{
_commands_in_head
}++;
1
N/A
$
self
->{
_list_item_contents
}++
if
(
defined
$
self
->{
_list_item_contents
});
1
N/A
if
(@{$
self
->{
_list_stack
}} && !$
self
->{
_list_stack
}->[
0
]->
item
()) {
1
N/A
$
self
->{
_list_stack
}->[
0
]->{
_has_par
} =
1
;
1
N/A
}
1
N/A
}
1
N/A
}
1
N/A
1
N/A
1
;
1
N/A
1
N/A
__END__
1
N/A
1
N/A
=head1 AUTHOR
1
N/A
1
N/A
Please report bugs using L<
http://rt.cpan.org
>.
1
N/A
1
N/A
Brad Appleton E<lt>bradapp@enteract.comE<gt> (initial version),
1
N/A
Marek Rouchal E<lt>marekr@cpan.orgE<gt>
1
N/A
1
N/A
Based on code for B<Pod::Text::pod2text()> written by
1
N/A
Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
1
N/A
1
N/A
=cut
1
N/A