Bring Pod::Simple up to 3.09 as on CPAN.
[p5sagit/p5-mst-13.2.git] / cpan / Pod-Simple / lib / Pod / Simple.pod
CommitLineData
351625bd 1
2=head1 NAME
3
4Pod::Simple - framework for parsing Pod
5
6=head1 SYNOPSIS
7
8 TODO
9
10=head1 DESCRIPTION
11
12Pod::Simple is a Perl library for parsing text in the Pod ("plain old
13documentation") markup language that is typically used for writing
14documentation for Perl and for Perl modules. The Pod format is explained
15in the L<perlpod|perlpod> man page; the most common formatter is called
16"perldoc".
17
18Pod formatters can use Pod::Simple to parse Pod documents into produce
19renderings of them in plain ASCII, in HTML, or in any number of other
20formats. Typically, such formatters will be subclasses of Pod::Simple,
21and so they will inherit its methods, like C<parse_file>.
22
23If you're reading this document just because you have a Pod-processing
24subclass that you want to use, this document (plus the documentation for
25the subclass) is probably all you'll need to read.
26
27If you're reading this document because you want to write a formatter
28subclass, continue reading this document, and then read
29L<Pod::Simple::Subclassing>, and then possibly even read L<perlpodspec>
30(some of which is for parser-writers, but much of which is notes to
31formatter-writers).
32
33
34=head1 MAIN METHODS
35
36
37
38=over
39
40=item C<< $parser = I<SomeClass>->new(); >>
41
42This returns a new parser object, where I<C<SomeClass>> is a subclass
43of Pod::Simple.
44
45=item C<< $parser->output_fh( *OUT ); >>
46
47This sets the filehandle that C<$parser>'s output will be written to.
48You can pass C<*STDOUT>, otherwise you should probably do something
49like this:
50
51 my $outfile = "output.txt";
52 open TXTOUT, ">$outfile" or die "Can't write to $outfile: $!";
53 $parser->output_fh(*TXTOUT);
54
55...before you call one of the C<< $parser->parse_I<whatever> >> methods.
56
57=item C<< $parser->output_string( \$somestring ); >>
58
59This sets the string that C<$parser>'s output will be sent to,
60instead of any filehandle.
61
62
63=item C<< $parser->parse_file( I<$some_filename> ); >>
64
65=item C<< $parser->parse_file( *INPUT_FH ); >>
66
67This reads the Pod content of the file (or filehandle) that you specify,
68and processes it with that C<$parser> object, according to however
69C<$parser>'s class works, and according to whatever parser options you
70have set up for this C<$parser> object.
71
72=item C<< $parser->parse_string_document( I<$all_content> ); >>
73
74This works just like C<parse_file> except that it reads the Pod
75content not from a file, but from a string that you have already
76in memory.
77
78=item C<< $parser->parse_lines( I<...@lines...>, undef ); >>
79
80This processes the lines in C<@lines> (where each list item must be a
81defined value, and must contain exactly one line of content -- so no
82items like C<"foo\nbar"> are allowed). The final C<undef> is used to
83indicate the end of document being parsed.
84
85The other C<parser_I<whatever>> methods are meant to be called only once
86per C<$parser> object; but C<parse_lines> can be called as many times per
87C<$parser> object as you want, as long as the last call (and only
88the last call) ends with an C<undef> value.
89
90
91=item C<< $parser->content_seen >>
92
93This returns true only if there has been any real content seen
94for this document.
95
96
97=item C<< I<SomeClass>->filter( I<$filename> ); >>
98
99=item C<< I<SomeClass>->filter( I<*INPUT_FH> ); >>
100
101=item C<< I<SomeClass>->filter( I<\$document_content> ); >>
102
103This is a shortcut method for creating a new parser object, setting the
104output handle to STDOUT, and then processing the specified file (or
105filehandle, or in-memory document). This is handy for one-liners like
106this:
107
108 perl -MPod::Simple::Text -e "Pod::Simple::Text->filter('thingy.pod')"
109
110=back
111
112
113
114=head1 SECONDARY METHODS
115
116Some of these methods might be of interest to general users, as
117well as of interest to formatter-writers.
118
119Note that the general pattern here is that the accessor-methods
120read the attribute's value with C<< $value = $parser->I<attribute> >>
121and set the attribute's value with
122C<< $parser->I<attribute>(I<newvalue>) >>. For each accessor, I typically
123only mention one syntax or another, based on which I think you are actually
124most likely to use.
125
126
127=over
128
129=item C<< $parser->no_whining( I<SOMEVALUE> ) >>
130
131If you set this attribute to a true value, you will suppress the
132parser's complaints about irregularities in the Pod coding. By default,
133this attribute's value is false, meaning that irregularities will
134be reported.
135
136Note that turning this attribute to true won't suppress one or two kinds
137of complaints about rarely occurring unrecoverable errors.
138
139
140=item C<< $parser->no_errata_section( I<SOMEVALUE> ) >>
141
142If you set this attribute to a true value, you will stop the parser from
143generating a "POD ERRORS" section at the end of the document. By
144default, this attribute's value is false, meaning that an errata section
145will be generated, as necessary.
146
147
148=item C<< $parser->complain_stderr( I<SOMEVALUE> ) >>
149
150If you set this attribute to a true value, it will send reports of
151parsing errors to STDERR. By default, this attribute's value is false,
152meaning that no output is sent to STDERR.
153
9d65762f 154Setting C<complain_stderr> also sets C<no_errata_section>.
351625bd 155
156
157=item C<< $parser->source_filename >>
158
159This returns the filename that this parser object was set to read from.
160
161
162=item C<< $parser->doc_has_started >>
163
164This returns true if C<$parser> has read from a source, and has seen
165Pod content in it.
166
167
168=item C<< $parser->source_dead >>
169
170This returns true if C<$parser> has read from a source, and come to the
171end of that source.
172
9d65762f 173=item C<< $parser->strip_verbatim_indent( I<SOMEVALUE> ) >>
174
175The perlpod spec for a Verbatim paragraph is "It should be reproduced
176exactly...", which means that the whitespace you've used to indent your
177verbatim blocks will be preserved in the output. This can be annoying for
178outputs such as HTML, where that whitespace will remain in front of every
179line. It's an unfortunate case where syntax is turned into semantics.
180
181If the POD your parsing adheres to a consistent indentation policy, you can
182have such indentation stripped from the beginning of every line of your
183verbatim blocks. This method tells Pod::Simple what to strip. For two-space
184indents, you'd use:
185
186 $parser->strip_verbatim_indent(' ');
187
188For tab indents, you'd use a tab character:
189
190 $parser->strip_verbatim_indent("\t");
351625bd 191
9d65762f 192If the POD is inconsistent about the indentation of verbatim blocks, but you
193have figured out a heuristic to determine how much a particular verbatim block
194is indented, you can pass a code reference instead. The code reference will be
195executed with one argument, an array reference of all the lines in the
196verbatim block, and should return the value to be stripped from each line. For
197example, if you decide that you're fine to use the first line of the verbatim
198block to set the standard for indentation of the rest of the block, you can
199look at the first line and return the appropriate value, like so:
200
201 $new->strip_verbatim_indent(sub {
202 my $lines = shift;
203 (my $indent = $lines->[0]) =~ s/\S.*//;
204 return $indent;
205 });
206
207If you'd rather treat each line individually, you can do that, too, by just
208transforming them in-place in the code reference and returning C<undef>. Say
209that you don't want I<any> lines indented. You can do something like this:
210
211 $new->strip_verbatim_indent(sub {
212 my $lines = shift;
213 sub { s/^\s+// for @{ $lines },
214 return undef;
215 });
216
217=back
351625bd 218
219=head1 CAVEATS
220
221This is just a beta release -- there are a good number of things still
222left to do. Notably, support for EBCDIC platforms is still half-done,
223an untested.
224
225
226=head1 SEE ALSO
227
228L<Pod::Simple::Subclassing>
229
230L<perlpod|perlpod>
231
232L<perlpodspec|perlpodspec>
233
234L<Pod::Escapes|Pod::Escapes>
235
236L<perldoc>
237
238
239=head1 COPYRIGHT AND DISCLAIMERS
240
241Copyright (c) 2002 Sean M. Burke. All rights reserved.
242
243This library is free software; you can redistribute it and/or modify it
244under the same terms as Perl itself.
245
246This program is distributed in the hope that it will be useful, but
247without any warranty; without even the implied warranty of
248merchantability or fitness for a particular purpose.
249
250=head1 AUTHOR
251
252Original author: Sean M. Burke C<sburke@cpan.org>
253
69473a20 254Maintained by:
255
256=over
257
258=item * Allison Randal C<allison@perl.org>
259
260=item * Hans Dieter Pearcey C<hdp@cpan.org>
261
262=back
351625bd 263
264=cut
265
266