Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / 5.8.0 / Pod / Checker.pm
CommitLineData
86530b38
AT
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
10package Pod::Checker;
11
12use vars qw($VERSION);
13$VERSION = 1.3; ## Current version of this package
14require 5.005; ## requires this Perl version or later
15
16use Pod::ParseUtils; ## for hyperlinks and lists
17
18=head1 NAME
19
20Pod::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
33C<$filepath> is the input POD to read and C<$outputpath> is
34where to write POD syntax error messages. Either argument may be a scalar
35indicating a file-path, or else a reference to an open filehandle.
36If unspecified, the input-file it defaults to C<\*STDIN>, and
37the output-file defaults to C<\*STDERR>.
38
39=head2 podchecker()
40
41This function can take a hash of options:
42
43=over 4
44
45=item B<-warnings> =E<gt> I<val>
46
47Turn warnings on/off. I<val> is usually 1 for on, but higher values
48trigger additional warnings. See L<"Warnings">.
49
50=back
51
52=head1 DESCRIPTION
53
54B<podchecker> will perform syntax checking of Perl5 POD format documentation.
55
56I<NOTE THAT THIS MODULE IS CURRENTLY IN THE BETA STAGE!>
57
58It is hoped that curious/ambitious user will help flesh out and add the
59additional features they wish to see in B<Pod::Checker> and B<podchecker>
60and verify that the checks are consistent with L<perlpod>.
61
62The following checks are currently preformed:
63
64=over 4
65
66=item *
67
68Unknown '=xxxx' commands, unknown 'XE<lt>...E<gt>' interior-sequences,
69and unterminated interior sequences.
70
71=item *
72
73Check for proper balancing of C<=begin> and C<=end>. The contents of such
74a block are generally ignored, i.e. no syntax checks are performed.
75
76=item *
77
78Check for proper nesting and balancing of C<=over>, C<=item> and C<=back>.
79
80=item *
81
82Check for same nested interior-sequences (e.g.
83C<LE<lt>...LE<lt>...E<gt>...E<gt>>).
84
85=item *
86
87Check for malformed or nonexisting entities C<EE<lt>...E<gt>>.
88
89=item *
90
91Check for correct syntax of hyperlinks C<LE<lt>...E<gt>>. See L<perlpod>
92for details.
93
94=item *
95
96Check for unresolved document-internal links. This check may also reveal
97misspelled links that seem to be internal links but should be links
98to something else.
99
100=back
101
102=head1 DIAGNOSTICS
103
104=head2 Errors
105
106=over 4
107
108=item * empty =headn
109
110A heading (C<=head1> or C<=head2>) without any text? That ain't no
111heading!
112
113=item * =over on line I<N> without closing =back
114
115The C<=over> command does not have a corresponding C<=back> before the
116next 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
122An C<=item> or C<=back> command has been found outside a
123C<=over>/C<=back> block.
124
125=item * No argument for =begin
126
127A C<=begin> command was found that is not followed by the formatter
128specification.
129
130=item * =end without =begin
131
132A standalone C<=end> command was found.
133
134=item * Nested =begin's
135
136There were at least two consecutive C<=begin> commands without
137the corresponding C<=end>. Only one C<=begin> may be active at
138a time.
139
140=item * =for without formatter specification
141
142There is no specification of the formatter after the C<=for> command.
143
144=item * unresolved internal link I<NAME>
145
146The given link to I<NAME> does not have a matching node in the current
147POD. This also happend when a single word node name is not enclosed in
148C<"">.
149
150=item * Unknown command "I<CMD>"
151
152An invalid POD command has been found. Valid are C<=head1>, C<=head2>,
153C<=head3>, C<=head4>, C<=over>, C<=item>, C<=back>, C<=begin>, C<=end>,
154C<=for>, C<=pod>, C<=cut>
155
156=item * Unknown interior-sequence "I<SEQ>"
157
158An invalid markup command has been encountered. Valid are:
159C<BE<lt>E<gt>>, C<CE<lt>E<gt>>, C<EE<lt>E<gt>>, C<FE<lt>E<gt>>,
160C<IE<lt>E<gt>>, C<LE<lt>E<gt>>, C<SE<lt>E<gt>>, C<XE<lt>E<gt>>,
161C<ZE<lt>E<gt>>
162
163=item * nested commands I<CMD>E<lt>...I<CMD>E<lt>...E<gt>...E<gt>
164
165Two nested identical markup commands have been found. Generally this
166does not make sense.
167
168=item * garbled entity I<STRING>
169
170The I<STRING> found cannot be interpreted as a character entity.
171
172=item * Entity number out of range
173
174An entity specified by number (dec, hex, oct) is out of range (1-255).
175
176=item * malformed link LE<lt>E<gt>
177
178The link found cannot be parsed because it does not conform to the
179syntax described in L<perlpod>.
180
181=item * nonempty ZE<lt>E<gt>
182
183The C<ZE<lt>E<gt>> sequence is supposed to be empty.
184
185=item * empty XE<lt>E<gt>
186
187The index entry specified contains nothing but whitespace.
188
189=item * Spurious text after =pod / =cut
190
191The commands C<=pod> and C<=cut> do not take any arguments.
192
193=item * Spurious character(s) after =back
194
195The C<=back> command does not take any arguments.
196
197=back
198
199=head2 Warnings
200
201These may not necessarily cause trouble, but indicate mediocre style.
202
203=over 4
204
205=item * multiple occurrence of link target I<name>
206
207The POD file has some C<=item> and/or C<=head> commands that have
208the same text. Potential hyperlinks to such a text cannot be unique then.
209
210=item * line containing nothing but whitespace in paragraph
211
212There is some whitespace on a seemingly empty line. POD is very sensitive
213to such things, so this is flagged. B<vi> users switch on the B<list>
214option to avoid this problem.
215
216=begin _disabled_
217
218=item * file does not start with =head
219
220The file starts with a different POD directive than head.
221This is most probably something you do not want.
222
223=end _disabled_
224
225=item * previous =item has no contents
226
227There is a list C<=item> right above the flagged line that has no
228text contents. You probably want to delete empty items.
229
230=item * preceding non-item paragraph(s)
231
232A list introduced by C<=over> starts with a text or verbatim paragraph,
233but continues with C<=item>s. Move the non-item paragraph out of the
234C<=over>/C<=back> block.
235
236=item * =item type mismatch (I<one> vs. I<two>)
237
238A list started with e.g. a bulletted C<=item> and continued with a
239numbered one. This is obviously inconsistent. For most translators the
240type 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
244Angle brackets not written as C<E<lt>ltE<gt>> and C<E<lt>gtE<gt>>
245can potentially cause errors as they could be misinterpreted as
246markup commands. This is only printed when the -warnings level is
247greater than 1.
248
249=item * Unknown entity
250
251A character entity was found that does not belong to the standard
252ISO set or the POD specials C<verbar> and C<sol>.
253
254=item * No items in =over
255
256The list opened with C<=over> does not contain any items.
257
258=item * No argument for =item
259
260C<=item> without any parameters is deprecated. It should either be followed
261by C<*> to indicate an unordered list, by a number (optionally followed
262by a dot) to indicate an ordered (numbered) list or simple text for a
263definition list.
264
265=item * empty section in previous paragraph
266
267The previous section (introduced by a C<=head> command) does not contain
268any text. This usually indicates that something is missing. Note: A
269C<=head1> followed immediately by C<=head2> does not trigger this warning.
270
271=item * Verbatim paragraph in NAME section
272
273The NAME section (C<=head1 NAME>) should consist of a single paragraph
274with the script/module name, followed by a dash `-' and a very short
275description of what the thing is good for.
276
277=back
278
279=head2 Hyperlinks
280
281There are some warnings wrt. malformed hyperlinks.
282
283=over 4
284
285=item * ignoring leading/trailing whitespace in link
286
287There is whitespace at the beginning or the end of the contents of
288LE<lt>...E<gt>.
289
290=item * (section) in '$page' deprecated
291
292There is a section detected in the page name of LE<lt>...E<gt>, e.g.
293C<LE<lt>passwd(2)E<gt>>. POD hyperlinks may point to POD documents only.
294Please write C<CE<lt>passwd(2)E<gt>> instead. Some formatters are able
295to expand this to appropriate code. For links to (builtin) functions,
296please say C<LE<lt>perlfunc/mkdirE<gt>>, without ().
297
298=item * alternative text/node '%s' contains non-escaped | or /
299
300The characters C<|> and C</> are special in the LE<lt>...E<gt> context.
301Although the hyperlink parser does its best to determine which "/" is
302text and which is a delimiter in case of doubt, one ought to escape
303these literal characters like this:
304
305 / E<sol>
306 | E<verbar>
307
308=back
309
310=head1 RETURN VALUE
311
312B<podchecker> returns the number of POD syntax errors found or -1 if
313there were no POD commands at all found in the file.
314
315=head1 EXAMPLES
316
317I<[T.B.D.]>
318
319=head1 INTERFACE
320
321While checking, this module collects document properties, e.g. the nodes
322for hyperlinks (C<=headX>, C<=item>) and index entries (C<XE<lt>E<gt>>).
323POD translators can use this feature to syntax-check and get the nodes in
324a first pass before actually starting to convert. This is expensive in terms
325of execution time, but allows for very robust conversions.
326
327=cut
328
329#############################################################################
330
331use strict;
332#use diagnostics;
333use Carp;
334use Exporter;
335use Pod::Parser;
336
337use vars qw(@ISA @EXPORT);
338@ISA = qw(Pod::Parser);
339@EXPORT = qw(&podchecker);
340
341use vars qw(%VALID_COMMANDS %VALID_SEQUENCES);
342
343my %VALID_COMMANDS = (
344 'pod' => 1,
345 'cut' => 1,
346 'head1' => 1,
347 'head2' => 1,
348 'head3' => 1,
349 'head4' => 1,
350 'over' => 1,
351 'back' => 1,
352 'item' => 1,
353 'for' => 1,
354 'begin' => 1,
355 'end' => 1,
356);
357
358my %VALID_SEQUENCES = (
359 'I' => 1,
360 'B' => 1,
361 'S' => 1,
362 'C' => 1,
363 'L' => 1,
364 'F' => 1,
365 'X' => 1,
366 'Z' => 1,
367 'E' => 1,
368);
369
370# stolen from HTML::Entities
371my %ENTITIES = (
372 # Some normal chars that have special meaning in SGML context
373 amp => '&', # ampersand
374'gt' => '>', # greater than
375'lt' => '<', # less than
376 quot => '"', # double quote
377
378 # PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML
379