home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _c184bb699de6744c737129b84bf9bf24 < prev    next >
Encoding:
Text File  |  2004-04-13  |  39.9 KB  |  1,243 lines

  1. #############################################################################
  2. # Pod/Checker.pm -- check pod documents for syntax errors
  3. #
  4. # Copyright (C) 1994-2000 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
  7. # as Perl itself.
  8. #############################################################################
  9.  
  10. package Pod::Checker;
  11.  
  12. use vars qw($VERSION);
  13. $VERSION = 1.2;  ## Current version of this package
  14. require  5.005;    ## requires this Perl version or later
  15.  
  16. use Pod::ParseUtils; ## for hyperlinks and lists
  17.  
  18. =head1 NAME
  19.  
  20. Pod::Checker, podchecker() - check pod documents for syntax errors
  21.  
  22. =head1 SYNOPSIS
  23.  
  24.   use Pod::Checker;
  25.  
  26.   $syntax_okay = podchecker($filepath, $outputpath, %options);
  27.  
  28.   my $checker = new Pod::Checker %options;
  29.   $checker->parse_from_file($filepath, \*STDERR);
  30.  
  31. =head1 OPTIONS/ARGUMENTS
  32.  
  33. C<$filepath> is the input POD to read and C<$outputpath> is
  34. where to write POD syntax error messages. Either argument may be a scalar
  35. indicating a file-path, or else a reference to an open filehandle.
  36. If unspecified, the input-file it defaults to C<\*STDIN>, and
  37. the output-file defaults to C<\*STDERR>.
  38.  
  39. =head2 podchecker()
  40.  
  41. This function can take a hash of options:
  42.  
  43. =over 4
  44.  
  45. =item B<-warnings> =E<gt> I<val>
  46.  
  47. Turn warnings on/off. I<val> is usually 1 for on, but higher values
  48. trigger additional warnings. See L<"Warnings">.
  49.  
  50. =back
  51.  
  52. =head1 DESCRIPTION
  53.  
  54. B<podchecker> will perform syntax checking of Perl5 POD format documentation.
  55.  
  56. I<NOTE THAT THIS MODULE IS CURRENTLY IN THE BETA STAGE!>
  57.  
  58. It is hoped that curious/ambitious user will help flesh out and add the
  59. additional features they wish to see in B<Pod::Checker> and B<podchecker>
  60. and verify that the checks are consistent with L<perlpod>.
  61.  
  62. The following checks are currently preformed:
  63.  
  64. =over 4
  65.  
  66. =item *
  67.  
  68. Unknown '=xxxx' commands, unknown 'XE<lt>...E<gt>' interior-sequences,
  69. and unterminated interior sequences.
  70.  
  71. =item *
  72.  
  73. Check for proper balancing of C<=begin> and C<=end>. The contents of such
  74. a block are generally ignored, i.e. no syntax checks are performed.
  75.  
  76. =item *
  77.  
  78. Check for proper nesting and balancing of C<=over>, C<=item> and C<=back>.
  79.  
  80. =item *
  81.  
  82. Check for same nested interior-sequences (e.g. 
  83. C<LE<lt>...LE<lt>...E<gt>...E<gt>>).
  84.  
  85. =item *
  86.  
  87. Check for malformed or nonexisting entities C<EE<lt>...E<gt>>.
  88.  
  89. =item *
  90.  
  91. Check for correct syntax of hyperlinks C<LE<lt>...E<gt>>. See L<perlpod>
  92. for details.
  93.  
  94. =item *
  95.  
  96. Check for unresolved document-internal links. This check may also reveal
  97. misspelled links that seem to be internal links but should be links
  98. to something else.
  99.  
  100. =back
  101.  
  102. =head1 DIAGNOSTICS
  103.  
  104. =head2 Errors
  105.  
  106. =over 4
  107.  
  108. =item * empty =headn
  109.  
  110. A heading (C<=head1> or C<=head2>) without any text? That ain't no
  111. heading!
  112.  
  113. =item * =over on line I<N> without closing =back
  114.  
  115. The C<=over> command does not have a corresponding C<=back> before the
  116. next heading (C<=head1> or C<=head2>) or the end of the file.
  117.  
  118. =item * =item without previous =over
  119.  
  120. =item * =back without previous =over
  121.  
  122. An C<=item> or C<=back> command has been found outside a
  123. C<=over>/C<=back> block.
  124.  
  125. =item * No argument for =begin
  126.  
  127. A C<=begin> command was found that is not followed by the formatter
  128. specification.
  129.  
  130. =item * =end without =begin
  131.  
  132. A standalone C<=end> command was found.
  133.  
  134. =item * Nested =begin's
  135.  
  136. There were at least two consecutive C<=begin> commands without
  137. the corresponding C<=end>. Only one C<=begin> may be active at
  138. a time.
  139.  
  140. =item * =for without formatter specification
  141.  
  142. There is no specification of the formatter after the C<=for> command.
  143.  
  144. =item * unresolved internal link I<NAME>
  145.  
  146. The given link to I<NAME> does not have a matching node in the current
  147. POD. This also happend when a single word node name is not enclosed in
  148. C<"">.
  149.  
  150. =item * Unknown command "I<CMD>"
  151.  
  152. An invalid POD command has been found. Valid are C<=head1>, C<=head2>,
  153. C<=over>, C<=item>, C<=back>, C<=begin>, C<=end>, C<=for>, C<=pod>,
  154. C<=cut>
  155.  
  156. =item * Unknown interior-sequence "I<SEQ>"
  157.  
  158. An invalid markup command has been encountered. Valid are:
  159. C<BE<lt>E<gt>>, C<CE<lt>E<gt>>, C<EE<lt>E<gt>>, C<FE<lt>E<gt>>, 
  160. C<IE<lt>E<gt>>, C<LE<lt>E<gt>>, C<SE<lt>E<gt>>, C<XE<lt>E<gt>>, 
  161. C<ZE<lt>E<gt>>
  162.  
  163. =item * nested commands I<CMD>E<lt>...I<CMD>E<lt>...E<gt>...E<gt>
  164.  
  165. Two nested identical markup commands have been found. Generally this
  166. does not make sense.
  167.  
  168. =item * garbled entity I<STRING>
  169.  
  170. The I<STRING> found cannot be interpreted as a character entity.
  171.  
  172. =item * Entity number out of range
  173.  
  174. An entity specified by number (dec, hex, oct) is out of range (1-255).
  175.  
  176. =item * malformed link LE<lt>E<gt>
  177.  
  178. The link found cannot be parsed because it does not conform to the
  179. syntax described in L<perlpod>.
  180.  
  181. =item * nonempty ZE<lt>E<gt>
  182.  
  183. The C<ZE<lt>E<gt>> sequence is supposed to be empty.
  184.  
  185. =item * empty XE<lt>E<gt>
  186.  
  187. The index entry specified contains nothing but whitespace.
  188.  
  189. =item * Spurious text after =pod / =cut
  190.  
  191. The commands C<=pod> and C<=cut> do not take any arguments.
  192.  
  193. =item * Spurious character(s) after =back
  194.  
  195. The C<=back> command does not take any arguments.
  196.  
  197. =back
  198.  
  199. =head2 Warnings
  200.  
  201. These may not necessarily cause trouble, but indicate mediocre style.
  202.  
  203. =over 4
  204.  
  205. =item * multiple occurence of link target I<name>
  206.  
  207. The POD file has some C<=item> and/or C<=head> commands that have
  208. the same text. Potential hyperlinks to such a text cannot be unique then.
  209.  
  210. =item * line containing nothing but whitespace in paragraph
  211.  
  212. There is some whitespace on a seemingly empty line. POD is very sensitive
  213. to such things, so this is flagged. B<vi> users switch on the B<list>
  214. option to avoid this problem.
  215.  
  216. =begin _disabled_
  217.  
  218. =item * file does not start with =head
  219.  
  220. The file starts with a different POD directive than head.
  221. This is most probably something you do not want.
  222.  
  223. =end _disabled_
  224.  
  225. =item * previous =item has no contents
  226.  
  227. There is a list C<=item> right above the flagged line that has no
  228. text contents. You probably want to delete empty items.
  229.  
  230. =item * preceding non-item paragraph(s)
  231.  
  232. A list introduced by C<=over> starts with a text or verbatim paragraph,
  233. but continues with C<=item>s. Move the non-item paragraph out of the
  234. C<=over>/C<=back> block.
  235.  
  236. =item * =item type mismatch (I<one> vs. I<two>)
  237.  
  238. A list started with e.g. a bulletted C<=item> and continued with a
  239. numbered one. This is obviously inconsistent. For most translators the
  240. type of the I<first> C<=item> determines the type of the list.
  241.  
  242. =item * I<N> unescaped C<E<lt>E<gt>> in paragraph
  243.  
  244. Angle brackets not written as C<E<lt>ltE<gt>> and C<E<lt>gtE<gt>>
  245. can potentially cause errors as they could be misinterpreted as
  246. markup commands. This is only printed when the -warnings level is
  247. greater than 1.
  248.  
  249. =item * Unknown entity
  250.  
  251. A character entity was found that does not belong to the standard
  252. ISO set or the POD specials C<verbar> and C<sol>.
  253.  
  254. =item * No items in =over
  255.  
  256. The list opened with C<=over> does not contain any items.
  257.  
  258. =item * No argument for =item
  259.  
  260. C<=item> without any parameters is deprecated. It should either be followed
  261. by C<*> to indicate an unordered list, by a number (optionally followed
  262. by a dot) to indicate an ordered (numbered) list or simple text for a
  263. definition list.
  264.  
  265. =item * empty section in previous paragraph
  266.  
  267. The previous section (introduced by a C<=head> command) does not contain
  268. any text. This usually indicates that something is missing. Note: A 
  269. C<=head1> followed immediately by C<=head2> does not trigger this warning.
  270.  
  271. =item * Verbatim paragraph in NAME section
  272.  
  273. The NAME section (C<=head1 NAME>) should consist of a single paragraph
  274. with the script/module name, followed by a dash `-' and a very short
  275. description of what the thing is good for.
  276.  
  277. =back
  278.  
  279. =head2 Hyperlinks
  280.  
  281. There are some warnings wrt. malformed hyperlinks.
  282.  
  283. =over 4
  284.  
  285. =item * ignoring leading/trailing whitespace in link
  286.  
  287. There is whitespace at the beginning or the end of the contents of 
  288. LE<lt>...E<gt>.
  289.  
  290. =item * (section) in '$page' deprecated
  291.  
  292. There is a section detected in the page name of LE<lt>...E<gt>, e.g.
  293. C<LE<gt>passwd(2)E<gt>>. POD hyperlinks may point to POD documents only.
  294. Please write C<CE<lt>passwd(2)E<gt>> instead. Some formatters are able
  295. to expand this to appropriate code. For links to (builtin) functions,
  296. please say C<LE<lt>perlfunc/mkdirE<gt>>, without ().
  297.  
  298. =item * alternative text/node '%s' contains non-escaped | or /
  299.  
  300. The characters C<|> and C</> are special in the LE<lt>...E<gt> context.
  301. Although the hyperlink parser does its best to determine which "/" is
  302. text and which is a delimiter in case of doubt, one ought to escape
  303. these literal characters like this:
  304.  
  305.   /     E<sol>
  306.   |     E<verbar>
  307.  
  308. =back
  309.  
  310. =head1 RETURN VALUE
  311.  
  312. B<podchecker> returns the number of POD syntax errors found or -1 if
  313. there were no POD commands at all found in the file.
  314.  
  315. =head1 EXAMPLES
  316.  
  317. I<[T.B.D.]>
  318.  
  319. =head1 INTERFACE
  320.  
  321. While checking, this module collects document properties, e.g. the nodes
  322. for hyperlinks (C<=headX>, C<=item>) and index entries (C<XE<lt>E<gt>>).
  323. POD translators can use this feature to syntax-check and get the nodes in
  324. a first pass before actually starting to convert. This is expensive in terms
  325. of execution time, but allows for very robust conversions.
  326.  
  327. =cut
  328.  
  329. #############################################################################
  330.  
  331. use strict;
  332. #use diagnostics;
  333. use Carp;
  334. use Exporter;
  335. use Pod::Parser;
  336.  
  337. use vars qw(@ISA @EXPORT);
  338. @ISA = qw(Pod::Parser);
  339. @EXPORT = qw(&podchecker);
  340.  
  341. use vars qw(%VALID_COMMANDS %VALID_SEQUENCES);
  342.  
  343. my %VALID_COMMANDS = (
  344.     'pod'    =>  1,
  345.     'cut'    =>  1,
  346.     'head1'  =>  1,
  347.     'head2'  =>  1,
  348.     'over'   =>  1,
  349.     'back'   =>  1,
  350.     'item'   =>  1,
  351.     'for'    =>  1,
  352.     'begin'  =>  1,
  353.     'end'    =>  1,
  354. );
  355.  
  356. my %VALID_SEQUENCES = (
  357.     'I'  =>  1,
  358.     'B'  =>  1,
  359.     'S'  =>  1,
  360.     'C'  =>  1,
  361.     'L'  =>  1,
  362.     'F'  =>  1,
  363.     'X'  =>  1,
  364.     'Z'  =>  1,
  365.     'E'  =>  1,
  366. );
  367.  
  368. # stolen from HTML::Entities
  369. my %ENTITIES = (
  370.  # Some normal chars that have special meaning in SGML context
  371.  amp    => '&',  # ampersand 
  372. 'gt'    => '>',  # greater than
  373. 'lt'    => '<',  # less than
  374.  quot   => '"',  # double quote
  375.  
  376.  # PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML
  377.  AElig    => '╞',  # capital AE diphthong (ligature)
  378.  Aacute    => '┴',  # capital A, acute accent
  379.  Acirc    => '┬',  # capital A, circumflex accent
  380.  Agrave    => '└',  # capital A, grave accent
  381.  Aring    => '┼',  # capital A, ring
  382.  Atilde    => '├',  # capital A, tilde
  383.  Auml    => '─',  # capital A, dieresis or umlaut mark
  384.  Ccedil    => '╟',  # capital C, cedilla
  385.  ETH    => '╨',  # capital Eth, Icelandic
  386.  Eacute    => '╔',  # capital E, acute accent
  387.  Ecirc    => '╩',  # capital E, circumflex accent
  388.  Egrave    => '╚',  # capital E, grave accent
  389.  Euml    => '╦',  # capital E, dieresis or umlaut mark
  390.  Iacute    => '═',  # capital I, acute accent
  391.  Icirc    => '╬',  # capital I, circumflex accent
  392.  Igrave    => '╠',  # capital I, grave accent
  393.  Iuml    => '╧',  # capital I, dieresis or umlaut mark
  394.  Ntilde    => '╤',  # capital N, tilde
  395.  Oacute    => '╙',  # capital O, acute accent
  396.  Ocirc    => '╘',  # capital O, circumflex accent
  397.  Ograve    => '╥',  # capital O, grave accent
  398.  Oslash    => '╪',  # capital O, slash
  399.  Otilde    => '╒',  # capital O, tilde
  400.  Ouml    => '╓',  # capital O, dieresis or umlaut mark
  401.  THORN    => '▐',  # capital THORN, Icelandic
  402.  Uacute    => '┌',  # capital U, acute accent
  403.  Ucirc    => '█',  # capital U, circumflex accent
  404.  Ugrave    => '┘',  # capital U, grave accent
  405.  Uuml    => '▄',  # capital U, dieresis or umlaut mark
  406.  Yacute    => '▌',  # capital Y, acute accent
  407.  aacute    => 'ß',  # small a, acute accent
  408.  acirc    => 'Γ',  # small a, circumflex accent
  409.  aelig    => 'µ',  # small ae diphthong (ligature)
  410.  agrave    => 'α',  # small a, grave accent
  411.  aring    => 'σ',  # small a, ring
  412.  atilde    => 'π',  # small a, tilde
  413.  auml    => 'Σ',  # small a, dieresis or umlaut mark
  414.  ccedil    => 'τ',  # small c, cedilla
  415.  eacute    => 'Θ',  # small e, acute accent
  416.  ecirc    => 'Ω',  # small e, circumflex accent
  417.  egrave    => 'Φ',  # small e, grave accent
  418.  eth    => '≡',  # small eth, Icelandic
  419.  euml    => 'δ',  # small e, dieresis or umlaut mark
  420.  iacute    => 'φ',  # small i, acute accent
  421.  icirc    => 'ε',  # small i, circumflex accent
  422.  igrave    => '∞',  # small i, grave accent
  423.  iuml    => '∩',  # small i, dieresis or umlaut mark
  424.  ntilde    => '±',  # small n, tilde
  425.  oacute    => '≤',  # small o, acute accent
  426.  ocirc    => '⌠',  # small o, circumflex accent
  427.  ograve    => '≥',  # small o, grave accent
  428.  oslash    => '°',  # small o, slash
  429.  otilde    => '⌡',  # small o, tilde
  430.  ouml    => '÷',  # small o, dieresis or umlaut mark
  431.  szlig    => '▀',  # small sharp s, German (sz ligature)
  432.  thorn    => '■',  # small thorn, Icelandic
  433.  uacute    => '·',  # small u, acute accent
  434.  ucirc    => '√',  # small u, circumflex accent
  435.  ugrave    => '∙',  # small u, grave accent
  436.  uuml    => 'ⁿ',  # small u, dieresis or umlaut mark
  437.  yacute    => '²',  # small y, acute accent
  438.  yuml    => ' ',  # small y, dieresis or umlaut mark
  439.  
  440.  # Some extra Latin 1 chars that are listed in the HTML3.2 draft (21-May-96)
  441.  copy   => '⌐',  # copyright sign
  442.  reg    => '«',  # registered sign
  443.  nbsp   => "\240", # non breaking space
  444.  
  445.  # Additional ISO-8859/1 entities listed in rfc1866 (section 14)
  446.  iexcl  => 'í',
  447.  cent   => 'ó',
  448.  pound  => 'ú',
  449.  curren => 'ñ',
  450.  yen    => 'Ñ',
  451.  brvbar => 'ª',
  452.  sect   => 'º',
  453.  uml    => '¿',
  454.  ordf   => '¬',
  455.  laquo  => '½',
  456. 'not'   => '¼',    # not is a keyword in perl
  457.  shy    => '¡',
  458.  macr   => '»',
  459.  deg    => '░',
  460.  plusmn => '▒',
  461.  sup1   => '╣',
  462.  sup2   => '▓',
  463.  sup3   => '│',
  464.  acute  => '┤',
  465.  micro  => '╡',
  466.  para   => '╢',
  467.  middot => '╖',
  468.  cedil  => '╕',
  469.  ordm   => '║',
  470.  raquo  => '╗',
  471.  frac14 => '╝',
  472.  frac12 => '╜',
  473.  frac34 => '╛',
  474.  iquest => '┐',
  475. 'times' => '╫',    # times is a keyword in perl
  476.  divide => '≈',
  477.  
  478. # some POD special entities
  479.  verbar => '|',
  480.  sol => '/'
  481. );
  482.  
  483. ##---------------------------------------------------------------------------
  484.  
  485. ##---------------------------------
  486. ## Function definitions begin here
  487. ##---------------------------------
  488.  
  489. sub podchecker( $ ; $ % ) {
  490.     my ($infile, $outfile, %options) = @_;
  491.     local $_;
  492.  
  493.     ## Set defaults
  494.     $infile  ||= \*STDIN;
  495.     $outfile ||= \*STDERR;
  496.  
  497.     ## Now create a pod checker
  498.     my $checker = new Pod::Checker(%options);
  499.  
  500.     ## Now check the pod document for errors
  501.     $checker->parse_from_file($infile, $outfile);
  502.  
  503.     ## Return the number of errors found
  504.     return $checker->num_errors();
  505. }
  506.  
  507. ##---------------------------------------------------------------------------
  508.  
  509. ##-------------------------------
  510. ## Method definitions begin here
  511. ##-------------------------------
  512.  
  513. ##################################
  514.  
  515. =over 4
  516.  
  517. =item C<Pod::Checker-E<gt>new( %options )>
  518.  
  519. Return a reference to a new Pod::Checker object that inherits from
  520. Pod::Parser and is used for calling the required methods later. The
  521. following options are recognized:
  522.  
  523. C<-warnings =E<gt> num>
  524.   Print warnings if C<num> is true. The higher the value of C<num>,
  525. the more warnings are printed. Currently there are only levels 1 and 2.
  526.  
  527. C<-quiet =E<gt> num>
  528.   If C<num> is true, do not print any errors/warnings. This is useful
  529. when Pod::Checker is used to munge POD code into plain text from within
  530. POD formatters.
  531.  
  532. =cut
  533.  
  534. ## sub new {
  535. ##     my $this = shift;
  536. ##     my $class = ref($this) || $this;
  537. ##     my %params = @_;
  538. ##     my $self = {%params};
  539. ##     bless $self, $class;
  540. ##     $self->initialize();
  541. ##     return $self;
  542. ## }
  543.  
  544. sub initialize {
  545.     my $self = shift;
  546.     ## Initialize number of errors, and setup an error function to
  547.     ## increment this number and then print to the designated output.
  548.     $self->{_NUM_ERRORS} = 0;
  549.     $self->{-quiet} ||= 0;
  550.     # set the error handling subroutine
  551.     $self->errorsub($self->{-quiet} ? sub { 1; } : 'poderror');
  552.     $self->{_commands} = 0; # total number of POD commands encountered
  553.     $self->{_list_stack} = []; # stack for nested lists
  554.     $self->{_have_begin} = ''; # stores =begin
  555.     $self->{_links} = []; # stack for internal hyperlinks
  556.     $self->{_nodes} = []; # stack for =head/=item nodes
  557.     $self->{_index} = []; # text in X<>
  558.     # print warnings?
  559.     $self->{-warnings} = 1 unless(defined $self->{-warnings});
  560.     $self->{_current_head1} = ''; # the current =head1 block
  561.     $self->parseopts(-process_cut_cmd => 1, -warnings => $self->{-warnings});
  562. }
  563.  
  564. ##################################
  565.  
  566. =item C<$checker-E<gt>poderror( @args )>
  567.  
  568. =item C<$checker-E<gt>poderror( {%opts}, @args )>
  569.  
  570. Internal method for printing errors and warnings. If no options are
  571. given, simply prints "@_". The following options are recognized and used
  572. to form the output:
  573.  
  574.   -msg
  575.  
  576. A message to print prior to C<@args>.
  577.  
  578.   -line
  579.  
  580. The line number the error occurred in.
  581.  
  582.   -file
  583.  
  584. The file (name) the error occurred in.
  585.  
  586.   -severity
  587.  
  588. The error level, should be 'WARNING' or 'ERROR'.
  589.  
  590. =cut
  591.  
  592. # Invoked as $self->poderror( @args ), or $self->poderror( {%opts}, @args )
  593. sub poderror {
  594.     my $self = shift;
  595.     my %opts = (ref $_[0]) ? %{shift()} : ();
  596.  
  597.     ## Retrieve options
  598.     chomp( my $msg  = ($opts{-msg} || "")."@_" );
  599.     my $line = (exists $opts{-line}) ? " at line $opts{-line}" : "";
  600.     my $file = (exists $opts{-file}) ? " in file $opts{-file}" : "";
  601.     unless (exists $opts{-severity}) {
  602.        ## See if can find severity in message prefix
  603.        $opts{-severity} = $1  if ( $msg =~ s/^\**\s*([A-Z]{3,}):\s+// );
  604.     }
  605.     my $severity = (exists $opts{-severity}) ? "*** $opts{-severity}: " : "";
  606.  
  607.     ## Increment error count and print message "
  608.     ++($self->{_NUM_ERRORS}) 
  609.         if(!%opts || ($opts{-severity} && $opts{-severity} eq 'ERROR'));
  610.     my $out_fh = $self->output_handle() || \*STDERR;
  611.     print $out_fh ($severity, $msg, $line, $file, "\n")
  612.       if($self->{-warnings} || !%opts || $opts{-severity} ne 'WARNING');
  613. }
  614.  
  615. ##################################
  616.  
  617. =item C<$checker-E<gt>num_errors()>
  618.  
  619. Set (if argument specified) and retrieve the number of errors found.
  620.  
  621. =cut
  622.  
  623. sub num_errors {
  624.    return (@_ > 1) ? ($_[0]->{_NUM_ERRORS} = $_[1]) : $_[0]->{_NUM_ERRORS};
  625. }
  626.  
  627. ##################################
  628.  
  629. =item C<$checker-E<gt>name()>
  630.  
  631. Set (if argument specified) and retrieve the canonical name of POD as
  632. found in the C<=head1 NAME> section.
  633.  
  634. =cut
  635.  
  636. sub name {
  637.     return (@_ > 1 && $_[1]) ?
  638.         ($_[0]->{-name} = $_[1]) : $_[0]->{-name};  
  639. }
  640.  
  641. ##################################
  642.  
  643. =item C<$checker-E<gt>node()>
  644.  
  645. Add (if argument specified) and retrieve the nodes (as defined by C<=headX>
  646. and C<=item>) of the current POD. The nodes are returned in the order of
  647. their occurence. They consist of plain text, each piece of whitespace is
  648. collapsed to a single blank.
  649.  
  650. =cut
  651.  
  652. sub node {
  653.     my ($self,$text) = @_;
  654.     if(defined $text) {
  655.         $text =~ s/\s+$//s; # strip trailing whitespace
  656.         $text =~ s/\s+/ /gs; # collapse whitespace
  657.         # add node, order important!
  658.         push(@{$self->{_nodes}}, $text);
  659.         # keep also a uniqueness counter
  660.         $self->{_unique_nodes}->{$text}++ if($text !~ /^\s*$/s);
  661.         return $text;
  662.     }
  663.     @{$self->{_nodes}};
  664. }
  665.  
  666. ##################################
  667.  
  668. =item C<$checker-E<gt>idx()>
  669.  
  670. Add (if argument specified) and retrieve the index entries (as defined by
  671. C<XE<lt>E<gt>>) of the current POD. They consist of plain text, each piece
  672. of whitespace is collapsed to a single blank.
  673.  
  674. =cut
  675.  
  676. # set/return index entries of current POD
  677. sub idx {
  678.     my ($self,$text) = @_;
  679.     if(defined $text) {
  680.         $text =~ s/\s+$//s; # strip trailing whitespace
  681.         $text =~ s/\s+/ /gs; # collapse whitespace
  682.         # add node, order important!
  683.         push(@{$self->{_index}}, $text);
  684.         # keep also a uniqueness counter
  685.         $self->{_unique_nodes}->{$text}++ if($text !~ /^\s*$/s);
  686.         return $text;
  687.     }
  688.     @{$self->{_index}};
  689. }
  690.  
  691. ##################################
  692.  
  693. =item C<$checker-E<gt>hyperlink()>
  694.  
  695. Add (if argument specified) and retrieve the hyperlinks (as defined by
  696. C<LE<lt>E<gt>>) of the current POD. They consist of an 2-item array: line
  697. number and C<Pod::Hyperlink> object.
  698.  
  699. =back
  700.  
  701. =cut
  702.  
  703. # set/return hyperlinks of the current POD
  704. sub hyperlink {
  705.     my $self = shift;
  706.     if($_[0]) {
  707.         push(@{$self->{_links}}, $_[0]);
  708.         return $_[0];
  709.     }
  710.     @{$self->{_links}};
  711. }
  712.  
  713. ## overrides for Pod::Parser
  714.  
  715. sub end_pod {
  716.     ## Do some final checks and
  717.     ## print the number of errors found
  718.     my $self   = shift;
  719.     my $infile = $self->input_file();
  720.     my $out_fh = $self->output_handle();
  721.  
  722.     if(@{$self->{_list_stack}}) {
  723.         # _TODO_ display, but don't count them for now
  724.         my $list;
  725.         while(($list = $self->_close_list('EOF',$infile)) &&
  726.           $list->indent() ne 'auto') {
  727.             $self->poderror({ -line => 'EOF', -file => $infile,
  728.                 -severity => 'ERROR', -msg => "=over on line " .
  729.                 $list->start() . " without closing =back" }); #"
  730.         }
  731.     }
  732.  
  733.     # check validity of document internal hyperlinks
  734.     # first build the node names from the paragraph text
  735.     my %nodes;
  736.     foreach($self->node()) {
  737.         $nodes{$_} = 1;
  738.         if(/^(\S+)\s+\S/) {
  739.             # we have more than one word. Use the first as a node, too.
  740.             # This is used heavily in perlfunc.pod
  741.             $nodes{$1} ||= 2; # derived node
  742.         }
  743.     }
  744.     foreach($self->idx()) {
  745.         $nodes{$_} = 3; # index node
  746.     }
  747.     foreach($self->hyperlink()) {
  748.         my ($line,$link) = @$_;
  749.         # _TODO_ what if there is a link to the page itself by the name,
  750.         # e.g. in Tk::Pod : L<Tk::Pod/"DESCRIPTION">
  751.         if($link->node() && !$link->page() && $link->type() ne 'hyperlink') {
  752.             my $node = $self->_check_ptree($self->parse_text($link->node(),
  753.                 $line), $line, $infile, 'L');
  754.             if($node && !$nodes{$node}) {
  755.                 $self->poderror({ -line => $line || '', -file => $infile,
  756.                     -severity => 'ERROR',
  757.                     -msg => "unresolved internal link '$node'"});
  758.             }
  759.         }
  760.     }
  761.  
  762.     # check the internal nodes for uniqueness. This pertains to
  763.     # =headX, =item and X<...>
  764.     foreach(grep($self->{_unique_nodes}->{$_} > 1,
  765.       keys %{$self->{_unique_nodes}})) {
  766.         $self->poderror({ -line => '-', -file => $infile,
  767.             -severity => 'WARNING',
  768.             -msg => "multiple occurence of link target '$_'"});
  769.     }
  770.  
  771.     ## Print the number of errors found
  772.     my $num_errors = $self->num_errors();
  773.     if ($num_errors > 0) {
  774.         printf $out_fh ("$infile has $num_errors pod syntax %s.\n",
  775.                       ($num_errors == 1) ? "error" : "errors");
  776.     }
  777.     elsif($self->{_commands} == 0) {
  778.         print $out_fh "$infile does not contain any pod commands.\n";
  779.         $self->num_errors(-1);
  780.     }
  781.     else {
  782.         print $out_fh "$infile pod syntax OK.\n";
  783.     }
  784. }
  785.  
  786. # check a POD command directive
  787. sub command { 
  788.     my ($self, $cmd, $paragraph, $line_num, $pod_para) = @_;
  789.     my ($file, $line) = $pod_para->file_line;
  790.     ## Check the command syntax
  791.     my $arg; # this will hold the command argument
  792.     if (! $VALID_COMMANDS{$cmd}) {
  793.        $self->poderror({ -line => $line, -file => $file, -severity => 'ERROR',
  794.                          -msg => "Unknown command '$cmd'" });
  795.     }
  796.     else { # found a valid command
  797.         $self->{_commands}++; # delete this line if below is enabled again
  798.  
  799.         ##### following check disabled due to strong request
  800.         #if(!$self->{_commands}++ && $cmd !~ /^head/) {
  801.         #    $self->poderror({ -line => $line, -file => $file,
  802.         #         -severity => 'WARNING', 
  803.         #         -msg => "file does not start with =head" });
  804.         #}
  805.  
  806.         # check syntax of particular command
  807.         if($cmd eq 'over') {
  808.             # check for argument
  809.             $arg = $self->interpolate_and_check($paragraph, $line,$file);
  810.             my $indent = 4; # default
  811.             if($arg && $arg =~ /^\s*(\d+)\s*$/) {
  812.                 $indent = $1;
  813.             }
  814.             # start a new list
  815.             $self->_open_list($indent,$line,$file);
  816.         }
  817.         elsif($cmd eq 'item') {
  818.             # are we in a list?
  819.             unless(@{$self->{_list_stack}}) {
  820.                 $self->poderror({ -line => $line, -file => $file,
  821.                      -severity => 'ERROR', 
  822.                      -msg => "=item without previous =over" });
  823.                 # auto-open in case we encounter many more
  824.                 $self->_open_list('auto',$line,$file);
  825.             }
  826.             my $list = $self->{_list_stack}->[0];
  827.             # check whether the previous item had some contents
  828.             if(defined $self->{_list_item_contents} &&
  829.               $self->{_list_item_contents} == 0) {
  830.                 $self->poderror({ -line => $line, -file => $file,
  831.                      -severity => 'WARNING', 
  832.                      -msg => "previous =item has no contents" });
  833.             }
  834.             if($list->{_has_par}) {
  835.                 $self->poderror({ -line => $line, -file => $file,
  836.                      -severity => 'WARNING', 
  837.                      -msg => "preceding non-item paragraph(s)" });
  838.                 delete $list->{_has_par};
  839.             }
  840.             # check for argument
  841.             $arg = $self->interpolate_and_check($paragraph, $line, $file);
  842.             if($arg && $arg =~ /(\S+)/) {
  843.                 $arg =~ s/[\s\n]+$//;
  844.                 my $type;
  845.                 if($arg =~ /^[*]\s*(\S*.*)/) {
  846.                   $type = 'bullet';
  847.                   $self->{_list_item_contents} = $1 ? 1 : 0;
  848.                   $arg = $1;
  849.                 }
  850.                 elsif($arg =~ /^\d+\.?\s*(\S*)/) {
  851.                   $type = 'number';
  852.                   $self->{_list_item_contents} = $1 ? 1 : 0;
  853.                   $arg = $1;
  854.                 }
  855.                 else {
  856.                   $type = 'definition';
  857.                   $self->{_list_item_contents} = 1;
  858.                 }
  859.                 my $first = $list->type();
  860.                 if($first && $first ne $type) {
  861.                     $self->poderror({ -line => $line, -file => $file,
  862.                        -severity => 'WARNING', 
  863.                        -msg => "=item type mismatch ('$first' vs. '$type')"});
  864.                 }
  865.                 else { # first item
  866.                     $list->type($type);
  867.                 }
  868.             }
  869.             else {
  870.                 $self->poderror({ -line => $line, -file => $file,
  871.                      -severity => 'WARNING', 
  872.                      -msg => "No argument for =item" });
  873.         $arg = ' '; # empty
  874.                 $self->{_list_item_contents} = 0;
  875.             }
  876.             # add this item
  877.             $list->item($arg);
  878.             # remember this node
  879.             $self->node($arg);
  880.         }
  881.         elsif($cmd eq 'back') {
  882.             # check if we have an open list
  883.             unless(@{$self->{_list_stack}}) {
  884.                 $self->poderror({ -line => $line, -file => $file,
  885.                          -severity => 'ERROR', 
  886.                          -msg => "=back without previous =over" });
  887.             }
  888.             else {
  889.                 # check for spurious characters
  890.                 $arg = $self->interpolate_and_check($paragraph, $line,$file);
  891.                 if($arg && $arg =~ /\S/) {
  892.                     $self->poderror({ -line => $line, -file => $file,
  893.                          -severity => 'ERROR', 
  894.                          -msg => "Spurious character(s) after =back" });
  895.                 }
  896.                 # close list
  897.                 my $list = $self->_close_list($line,$file);
  898.                 # check for empty lists
  899.                 if(!$list->item() && $self->{-warnings}) {
  900.                     $self->poderror({ -line => $line, -file => $file,
  901.                          -severity => 'WARNING', 
  902.                          -msg => "No items in =over (at line " .
  903.                          $list->start() . ") / =back list"}); #"
  904.                 }
  905.             }
  906.         }
  907.         elsif($cmd =~ /^head(\d+)/) {
  908.             # check whether the previous =head section had some contents
  909.             if(defined $self->{_commands_in_head} &&
  910.               $self->{_commands_in_head} == 0 &&
  911.               defined $self->{_last_head} &&
  912.               $self->{_last_head} >= $1) {
  913.                 $self->poderror({ -line => $line, -file => $file,
  914.                      -severity => 'WARNING', 
  915.                      -msg => "empty section in previous paragraph"});
  916.             }
  917.             $self->{_commands_in_head} = -1;
  918.             $self->{_last_head} = $1;
  919.             # check if there is an open list
  920.             if(@{$self->{_list_stack}}) {
  921.                 my $list;
  922.                 while(($list = $self->_close_list($line,$file)) &&
  923.                   $list->indent() ne 'auto') {
  924.                     $self->poderror({ -line => $line, -file => $file,
  925.                          -severity => 'ERROR', 
  926.                          -msg => "=over on line ". $list->start() .
  927.                          " without closing =back (at $cmd)" });
  928.                 }
  929.             }
  930.             # remember this node
  931.             $arg = $self->interpolate_and_check($paragraph, $line,$file);
  932.             $arg =~ s/[\s\n]+$//s;
  933.             $self->node($arg);
  934.             unless(length($arg)) {
  935.                 $self->poderror({ -line => $line, -file => $file,
  936.                      -severity => 'ERROR', 
  937.                      -msg => "empty =$cmd"});
  938.             }
  939.             if($cmd eq 'head1') {
  940.                 $self->{_current_head1} = $arg;
  941.             } else {
  942.                 $self->{_current_head1} = '';
  943.             }
  944.         }
  945.         elsif($cmd eq 'begin') {
  946.             if($self->{_have_begin}) {
  947.                 # already have a begin
  948.                 $self->poderror({ -line => $line, -file => $file,
  949.                      -severity => 'ERROR', 
  950.                      -msg => "Nested =begin's (first at line " .
  951.                      $self->{_have_begin} . ")"});
  952.             }
  953.             else {
  954.                 # check for argument
  955.                 $arg = $self->interpolate_and_check($paragraph, $line,$file);
  956.                 unless($arg && $arg =~ /(\S+)/) {
  957.                     $self->poderror({ -line => $line, -file => $file,
  958.                          -severity => 'ERROR', 
  959.                          -msg => "No argument for =begin"});
  960.                 }
  961.                 # remember the =begin
  962.                 $self->{_have_begin} = "$line:$1";
  963.             }
  964.         }
  965.         elsif($cmd eq 'end') {
  966.             if($self->{_have_begin}) {
  967.                 # close the existing =begin
  968.                 $self->{_have_begin} = '';
  969.                 # check for spurious characters
  970.                 $arg = $self->interpolate_and_check($paragraph, $line,$file);
  971.                 # the closing argument is optional
  972.                 #if($arg && $arg =~ /\S/) {
  973.                 #    $self->poderror({ -line => $line, -file => $file,
  974.                 #         -severity => 'WARNING', 
  975.                 #         -msg => "Spurious character(s) after =end" });
  976.                 #}
  977.             }
  978.             else {
  979.                 # don't have a matching =begin
  980.                 $self->poderror({ -line => $line, -file => $file,
  981.                      -severity => 'ERROR', 
  982.                      -msg => "=end without =begin" });
  983.             }
  984.         }
  985.         elsif($cmd eq 'for') {
  986.             unless($paragraph =~ /\s*(\S+)\s*/) {
  987.                 $self->poderror({ -line => $line, -file => $file,
  988.                      -severity => 'ERROR', 
  989.                      -msg => "=for without formatter specification" });
  990.             }
  991.             $arg = ''; # do not expand paragraph below
  992.         }
  993.         elsif($cmd =~ /^(pod|cut)$/) {
  994.             # check for argument
  995.             $arg = $self->interpolate_and_check($paragraph, $line,$file);
  996.             if($arg && $arg =~ /(\S+)/) {
  997.                 $self->poderror({ -line => $line, -file => $file,
  998.                       -severity => 'ERROR', 
  999.                       -msg => "Spurious text after =$cmd"});
  1000.             }
  1001.         }
  1002.     $self->{_commands_in_head}++;
  1003.     ## Check the interior sequences in the command-text
  1004.     $self->interpolate_and_check($paragraph, $line,$file)
  1005.         unless(defined $arg);
  1006.     }
  1007. }
  1008.  
  1009. sub _open_list
  1010. {
  1011.     my ($self,$indent,$line,$file) = @_;
  1012.     my $list = Pod::List->new(
  1013.            -indent => $indent,
  1014.            -start => $line,
  1015.            -file => $file);
  1016.     unshift(@{$self->{_list_stack}}, $list);
  1017.     undef $self->{_list_item_contents};
  1018.     $list;
  1019. }
  1020.  
  1021. sub _close_list
  1022. {
  1023.     my ($self,$line,$file) = @_;
  1024.     my $list = shift(@{$self->{_list_stack}});
  1025.     if(defined $self->{_list_item_contents} &&
  1026.       $self->{_list_item_contents} == 0) {
  1027.         $self->poderror({ -line => $line, -file => $file,
  1028.             -severity => 'WARNING', 
  1029.             -msg => "previous =item has no contents" });
  1030.     }
  1031.     undef $self->{_list_item_contents};
  1032.     $list;
  1033. }
  1034.  
  1035. # process a block of some text
  1036. sub interpolate_and_check {
  1037.     my ($self, $paragraph, $line, $file) = @_;
  1038.     ## Check the interior sequences in the command-text
  1039.     # and return the text
  1040.     $self->_check_ptree(
  1041.         $self->parse_text($paragraph,$line), $line, $file, '');
  1042. }
  1043.  
  1044. sub _check_ptree {
  1045.     my ($self,$ptree,$line,$file,$nestlist) = @_;
  1046.     local($_);
  1047.     my $text = '';
  1048.     # process each node in the parse tree
  1049.     foreach(@$ptree) {
  1050.         # regular text chunk
  1051.         unless(ref) {
  1052.             my $count;
  1053.             # count the unescaped angle brackets
  1054.             # complain only when warning level is greater than 1
  1055.             my $i = $_;
  1056.             if($count = $i =~ tr/<>/<>/) {
  1057.                 $self->poderror({ -line => $line, -file => $file,
  1058.                      -severity => 'WARNING', 
  1059.                      -msg => "$count unescaped <> in paragraph" })
  1060.                 if($self->{-warnings} && $self->{-warnings}>1);
  1061.             }
  1062.             $text .= $i;
  1063.             next;
  1064.         }
  1065.         # have an interior sequence
  1066.         my $cmd = $_->cmd_name();
  1067.         my $contents = $_->parse_tree();
  1068.         ($file,$line) = $_->file_line();
  1069.         # check for valid tag
  1070.         if (! $VALID_SEQUENCES{$cmd}) {
  1071.             $self->poderror({ -line => $line, -file => $file,
  1072.                  -severity => 'ERROR', 
  1073.                  -msg => qq(Unknown interior-sequence '$cmd')});
  1074.             # expand it anyway
  1075.             $text .= $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
  1076.             next;
  1077.         }
  1078.         if($nestlist =~ /$cmd/) {
  1079.             $self->poderror({ -line => $line, -file => $file,
  1080.                  -severity => 'ERROR', 
  1081.                  -msg => "nested commands $cmd<...$cmd<...>...>"});
  1082.             # _TODO_ should we add the contents anyway?
  1083.             # expand it anyway, see below
  1084.         }
  1085.         if($cmd eq 'E') {
  1086.             # preserve entities
  1087.             if(@$contents > 1 || ref $$contents[0] || $$contents[0] !~ /^\w+$/) {
  1088.                 $self->poderror({ -line => $line, -file => $file,
  1089.                     -severity => 'ERROR', 
  1090.                     -msg => "garbled entity " . $_->raw_text()});
  1091.                 next;
  1092.             }
  1093.             my $ent = $$contents[0];
  1094.             my $val;
  1095.             if($ent =~ /^0x[0-9a-f]+$/i) {
  1096.                 # hexadec entity
  1097.                 $val = hex($ent);
  1098.             }
  1099.             elsif($ent =~ /^0\d+$/) {
  1100.                 # octal
  1101.                 $val = oct($ent);
  1102.             }
  1103.             elsif($ent =~ /^\d+$/) {
  1104.                 # numeric entity
  1105.                 $val = $ent;
  1106.             }
  1107.             if(defined $val) {
  1108.                 if($val>0 && $val<256) {
  1109.                     $text .= chr($val);
  1110.                 }
  1111.                 else {
  1112.                     $self->poderror({ -line => $line, -file => $file,
  1113.                         -severity => 'ERROR', 
  1114.                         -msg => "Entity number out of range " . $_->raw_text()});
  1115.                 }
  1116.             }
  1117.             elsif($ENTITIES{$ent}) {
  1118.                 # known ISO entity
  1119.                 $text .= $ENTITIES{$ent};
  1120.             }
  1121.             else {
  1122.                 $self->poderror({ -line => $line, -file => $file,
  1123.                     -severity => 'WARNING', 
  1124.                     -msg => "Unknown entity " . $_->raw_text()});
  1125.                 $text .= "E<$ent>";
  1126.             }
  1127.         }
  1128.         elsif($cmd eq 'L') {
  1129.             # try to parse the hyperlink
  1130.             my $link = Pod::Hyperlink->new($contents->raw_text());
  1131.             unless(defined $link) {
  1132.                 $self->poderror({ -line => $line, -file => $file,
  1133.                     -severity => 'ERROR', 
  1134.                     -msg => "malformed link " . $_->raw_text() ." : $@"});
  1135.                 next;
  1136.             }
  1137.             $link->line($line); # remember line
  1138.             if($self->{-warnings}) {
  1139.                 foreach my $w ($link->warning()) {
  1140.                     $self->poderror({ -line => $line, -file => $file,
  1141.                         -severity => 'WARNING', 
  1142.                         -msg => $w });
  1143.                 }
  1144.             }
  1145.             # check the link text
  1146.             $text .= $self->_check_ptree($self->parse_text($link->text(),
  1147.                 $line), $line, $file, "$nestlist$cmd");
  1148.             # remember link
  1149.             $self->hyperlink([$line,$link]);
  1150.         }
  1151.         elsif($cmd =~ /[BCFIS]/) {
  1152.             # add the guts
  1153.             $text .= $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
  1154.         }
  1155.         elsif($cmd eq 'Z') {
  1156.             if(length($contents->raw_text())) {
  1157.                 $self->poderror({ -line => $line, -file => $file,
  1158.                     -severity => 'ERROR', 
  1159.                     -msg => "Nonempty Z<>"});
  1160.             }
  1161.         }
  1162.         elsif($cmd eq 'X') {
  1163.             my $idx = $self->_check_ptree($contents, $line, $file, "$nestlist$cmd");
  1164.             if($idx =~ /^\s*$/s) {
  1165.                 $self->poderror({ -line => $line, -file => $file,
  1166.                     -severity => 'ERROR', 
  1167.                     -msg => "Empty X<>"});
  1168.             }
  1169.             else {
  1170.                 # remember this node
  1171.                 $self->idx($idx);
  1172.             }
  1173.         }
  1174.         else {
  1175.             # not reached
  1176.             die "internal error";
  1177.         }
  1178.     }
  1179.     $text;
  1180. }
  1181.  
  1182. # process a block of verbatim text
  1183. sub verbatim { 
  1184.     ## Nothing particular to check
  1185.     my ($self, $paragraph, $line_num, $pod_para) = @_;
  1186.  
  1187.     $self->_preproc_par($paragraph);
  1188.  
  1189.     if($self->{_current_head1} eq 'NAME') {
  1190.         my ($file, $line) = $pod_para->file_line;
  1191.         $self->poderror({ -line => $line, -file => $file,
  1192.             -severity => 'WARNING',
  1193.             -msg => 'Verbatim paragraph in NAME section' });
  1194.     }
  1195. }
  1196.  
  1197. # process a block of regular text
  1198. sub textblock { 
  1199.     my ($self, $paragraph, $line_num, $pod_para) = @_;
  1200.     my ($file, $line) = $pod_para->file_line;
  1201.  
  1202.     $self->_preproc_par($paragraph);
  1203.  
  1204.     # skip this paragraph if in a =begin block
  1205.     unless($self->{_have_begin}) {
  1206.         my $block = $self->interpolate_and_check($paragraph, $line,$file);
  1207.         if($self->{_current_head1} eq 'NAME') {
  1208.             if($block =~ /^\s*(\S+?)\s*[,-]/) {
  1209.                 # this is the canonical name
  1210.                 $self->{-name} = $1 unless(defined $self->{-name});
  1211.             }
  1212.         }
  1213.     }
  1214. }
  1215.  
  1216. sub _preproc_par
  1217. {
  1218.     my $self = shift;
  1219.     $_[0] =~ s/[\s\n]+$//;
  1220.     if($_[0]) {
  1221.         $self->{_commands_in_head}++;
  1222.         $self->{_list_item_contents}++ if(defined $self->{_list_item_contents});
  1223.         if(@{$self->{_list_stack}} && !$self->{_list_stack}->[0]->item()) {
  1224.             $self->{_list_stack}->[0]->{_has_par} = 1;
  1225.         }
  1226.     }
  1227. }
  1228.  
  1229. 1;
  1230.  
  1231. __END__
  1232.  
  1233. =head1 AUTHOR
  1234.  
  1235. Brad Appleton E<lt>bradapp@enteract.comE<gt> (initial version),
  1236. Marek Rouchal E<lt>marek@saftsack.fs.uni-bayreuth.deE<gt>
  1237.  
  1238. Based on code for B<Pod::Text::pod2text()> written by
  1239. Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
  1240.  
  1241. =cut
  1242.  
  1243.