📄 checker.pm
字号:
############################################################################## Pod/Checker.pm -- check pod documents for syntax errors## Copyright (C) 1994-2000 by Bradford Appleton. All rights reserved.# This file is part of "PodParser". PodParser is free software;# you can redistribute it and/or modify it under the same terms# as Perl itself.#############################################################################package Pod::Checker;use vars qw($VERSION);$VERSION = 1.2; ## Current version of this packagerequire 5.005; ## requires this Perl version or lateruse Pod::ParseUtils; ## for hyperlinks and lists=head1 NAMEPod::Checker, podchecker() - check pod documents for syntax errors=head1 SYNOPSIS use Pod::Checker; $syntax_okay = podchecker($filepath, $outputpath, %options); my $checker = new Pod::Checker %options; $checker->parse_from_file($filepath, \*STDERR);=head1 OPTIONS/ARGUMENTSC<$filepath> is the input POD to read and C<$outputpath> iswhere to write POD syntax error messages. Either argument may be a scalarindicating a file-path, or else a reference to an open filehandle.If unspecified, the input-file it defaults to C<\*STDIN>, andthe output-file defaults to C<\*STDERR>.=head2 podchecker()This function can take a hash of options:=over 4=item B<-warnings> =E<gt> I<val>Turn warnings on/off. I<val> is usually 1 for on, but higher valuestrigger additional warnings. See L<"Warnings">.=back=head1 DESCRIPTIONB<podchecker> will perform syntax checking of Perl5 POD format documentation.I<NOTE THAT THIS MODULE IS CURRENTLY IN THE BETA STAGE!>It is hoped that curious/ambitious user will help flesh out and add theadditional features they wish to see in B<Pod::Checker> and B<podchecker>and verify that the checks are consistent with L<perlpod>.The following checks are currently preformed:=over 4=item *Unknown '=xxxx' commands, unknown 'XE<lt>...E<gt>' interior-sequences,and unterminated interior sequences.=item *Check for proper balancing of C<=begin> and C<=end>. The contents of sucha block are generally ignored, i.e. no syntax checks are performed.=item *Check for proper nesting and balancing of C<=over>, C<=item> and C<=back>.=item *Check for same nested interior-sequences (e.g. C<LE<lt>...LE<lt>...E<gt>...E<gt>>).=item *Check for malformed or nonexisting entities C<EE<lt>...E<gt>>.=item *Check for correct syntax of hyperlinks C<LE<lt>...E<gt>>. See L<perlpod>for details.=item *Check for unresolved document-internal links. This check may also revealmisspelled links that seem to be internal links but should be linksto something else.=back=head1 DIAGNOSTICS=head2 Errors=over 4=item * empty =headnA heading (C<=head1> or C<=head2>) without any text? That ain't noheading!=item * =over on line I<N> without closing =backThe C<=over> command does not have a corresponding C<=back> before thenext heading (C<=head1> or C<=head2>) or the end of the file.=item * =item without previous =over=item * =back without previous =overAn C<=item> or C<=back> command has been found outside aC<=over>/C<=back> block.=item * No argument for =beginA C<=begin> command was found that is not followed by the formatterspecification.=item * =end without =beginA standalone C<=end> command was found.=item * Nested =begin'sThere were at least two consecutive C<=begin> commands withoutthe corresponding C<=end>. Only one C<=begin> may be active ata time.=item * =for without formatter specificationThere is no specification of the formatter after the C<=for> command.=item * unresolved internal link I<NAME>The given link to I<NAME> does not have a matching node in the currentPOD. This also happend when a single word node name is not enclosed inC<"">.=item * Unknown command "I<CMD>"An invalid POD command has been found. Valid are C<=head1>, C<=head2>,C<=over>, C<=item>, C<=back>, C<=begin>, C<=end>, C<=for>, C<=pod>,C<=cut>=item * Unknown interior-sequence "I<SEQ>"An invalid markup command has been encountered. Valid are:C<BE<lt>E<gt>>, C<CE<lt>E<gt>>, C<EE<lt>E<gt>>, C<FE<lt>E<gt>>, C<IE<lt>E<gt>>, C<LE<lt>E<gt>>, C<SE<lt>E<gt>>, C<XE<lt>E<gt>>, C<ZE<lt>E<gt>>=item * nested commands I<CMD>E<lt>...I<CMD>E<lt>...E<gt>...E<gt>Two nested identical markup commands have been found. Generally thisdoes not make sense.=item * garbled entity I<STRING>The I<STRING> found cannot be interpreted as a character entity.=item * Entity number out of rangeAn entity specified by number (dec, hex, oct) is out of range (1-255).=item * malformed link LE<lt>E<gt>The link found cannot be parsed because it does not conform to thesyntax described in L<perlpod>.=item * nonempty ZE<lt>E<gt>The C<ZE<lt>E<gt>> sequence is supposed to be empty.=item * empty XE<lt>E<gt>The index entry specified contains nothing but whitespace.=item * Spurious text after =pod / =cutThe commands C<=pod> and C<=cut> do not take any arguments.=item * Spurious character(s) after =backThe C<=back> command does not take any arguments.=back=head2 WarningsThese may not necessarily cause trouble, but indicate mediocre style.=over 4=item * multiple occurence of link target I<name>The POD file has some C<=item> and/or C<=head> commands that havethe same text. Potential hyperlinks to such a text cannot be unique then.=item * line containing nothing but whitespace in paragraphThere is some whitespace on a seemingly empty line. POD is very sensitiveto such things, so this is flagged. B<vi> users switch on the B<list>option to avoid this problem.=begin _disabled_=item * file does not start with =headThe file starts with a different POD directive than head.This is most probably something you do not want.=end _disabled_=item * previous =item has no contentsThere is a list C<=item> right above the flagged line that has notext contents. You probably want to delete empty items.=item * preceding non-item paragraph(s)A list introduced by C<=over> starts with a text or verbatim paragraph,but continues with C<=item>s. Move the non-item paragraph out of theC<=over>/C<=back> block.=item * =item type mismatch (I<one> vs. I<two>)A list started with e.g. a bulletted C<=item> and continued with anumbered one. This is obviously inconsistent. For most translators thetype of the I<first> C<=item> determines the type of the list.=item * I<N> unescaped C<E<lt>E<gt>> in paragraphAngle brackets not written as C<E<lt>ltE<gt>> and C<E<lt>gtE<gt>>can potentially cause errors as they could be misinterpreted asmarkup commands. This is only printed when the -warnings level isgreater than 1.=item * Unknown entityA character entity was found that does not belong to the standardISO set or the POD specials C<verbar> and C<sol>.=item * No items in =overThe list opened with C<=over> does not contain any items.=item * No argument for =itemC<=item> without any parameters is deprecated. It should either be followedby C<*> to indicate an unordered list, by a number (optionally followedby a dot) to indicate an ordered (numbered) list or simple text for adefinition list.=item * empty section in previous paragraphThe previous section (introduced by a C<=head> command) does not containany text. This usually indicates that something is missing. Note: A C<=head1> followed immediately by C<=head2> does not trigger this warning.=item * Verbatim paragraph in NAME sectionThe NAME section (C<=head1 NAME>) should consist of a single paragraphwith the script/module name, followed by a dash `-' and a very shortdescription of what the thing is good for.=back=head2 HyperlinksThere are some warnings wrt. malformed hyperlinks.=over 4=item * ignoring leading/trailing whitespace in linkThere is whitespace at the beginning or the end of the contents of LE<lt>...E<gt>.=item * (section) in '$page' deprecatedThere is a section detected in the page name of LE<lt>...E<gt>, e.g.C<LE<gt>passwd(2)E<gt>>. POD hyperlinks may point to POD documents only.Please write C<CE<lt>passwd(2)E<gt>> instead. Some formatters are ableto expand this to appropriate code. For links to (builtin) functions,please say C<LE<lt>perlfunc/mkdirE<gt>>, without ().=item * alternative text/node '%s' contains non-escaped | or /The characters C<|> and C</> are special in the LE<lt>...E<gt> context.Although the hyperlink parser does its best to determine which "/" istext and which is a delimiter in case of doubt, one ought to escapethese literal characters like this: / E<sol> | E<verbar>=back=head1 RETURN VALUEB<podchecker> returns the number of POD syntax errors found or -1 ifthere were no POD commands at all found in the file.=head1 EXAMPLESI<[T.B.D.]>=head1 INTERFACEWhile checking, this module collects document properties, e.g. the nodesfor hyperlinks (C<=headX>, C<=item>) and index entries (C<XE<lt>E<gt>>).POD translators can use this feature to syntax-check and get the nodes ina first pass before actually starting to convert. This is expensive in termsof execution time, but allows for very robust conversions.=cut#############################################################################use strict;#use diagnostics;use Carp;use Exporter;use Pod::Parser;use vars qw(@ISA @EXPORT);@ISA = qw(Pod::Parser);@EXPORT = qw(&podchecker);use vars qw(%VALID_COMMANDS %VALID_SEQUENCES);my %VALID_COMMANDS = ( 'pod' => 1, 'cut' => 1, 'head1' => 1, 'head2' => 1, 'over' => 1, 'back' => 1, 'item' => 1, 'for' => 1, 'begin' => 1, 'end' => 1,);my %VALID_SEQUENCES = ( 'I' => 1, 'B' => 1, 'S' => 1, 'C' => 1, 'L' => 1, 'F' => 1, 'X' => 1, 'Z' => 1, 'E' => 1,);# stolen from HTML::Entitiesmy %ENTITIES = ( # Some normal chars that have special meaning in SGML context amp => '&', # ampersand 'gt' => '>', # greater than'lt' => '<', # less than quot => '"', # double quote # PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML AElig => '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -