Perl 5 version 12.3 documentation
- MAIN METHODS
- SECONDARY METHODS
- SEE ALSO
- COPYRIGHT AND DISCLAIMERS
Pod::Simple is a Perl library for parsing text in the Pod ("plain old
documentation") markup language that is typically used for writing
documentation for Perl and for Perl modules. The Pod format is explained
perlpod; the most common formatter is called
Pod formatters can use Pod::Simple to parse Pod documents and render them into
plain text, HTML, or any number of other formats. Typically, such formatters
will be subclasses of Pod::Simple, and so they will inherit its methods, like
If you're reading this document just because you have a Pod-processing subclass that you want to use, this document (plus the documentation for the subclass) is probably all you need to read.
If you're reading this document because you want to write a formatter subclass, continue reading it and then read Pod::Simple::Subclassing, and then possibly even read perlpodspec (some of which is for parser-writers, but much of which is notes to formatter-writers).
$parser = SomeClass->new();
This returns a new parser object, where
SomeClassis a subclass of Pod::Simple.
$parser->output_fh( *OUT );
This sets the filehandle that
$parser's output will be written to. You can pass
*STDOUT, otherwise you should probably do something like this:
...before you call one of the
$parser->output_string( \$somestring );
This sets the string that
$parser's output will be sent to, instead of any filehandle.
$parser->parse_file( $some_filename );
$parser->parse_file( *INPUT_FH );
This reads the Pod content of the file (or filehandle) that you specify, and processes it with that
$parserobject, according to however
$parser's class works, and according to whatever parser options you have set up for this
$parser->parse_string_document( $all_content );
This works just like
parse_fileexcept that it reads the Pod content not from a file, but from a string that you have already in memory.
$parser->parse_lines( ...@lines..., undef );
This processes the lines in
@lines(where each list item must be a defined value, and must contain exactly one line of content -- so no items like
"foo\nbar"are allowed). The final
undefis used to indicate the end of document being parsed.
parser_whatevermethods are meant to be called only once per
parse_linescan be called as many times per
$parserobject as you want, as long as the last call (and only the last call) ends with an
This returns true only if there has been any real content seen for this document.
SomeClass->filter( $filename );
SomeClass->filter( *INPUT_FH );
SomeClass->filter( \$document_content );
This is a shortcut method for creating a new parser object, setting the output handle to STDOUT, and then processing the specified file (or filehandle, or in-memory document). This is handy for one-liners like this:
- perl -MPod::Simple::Text -e "Pod::Simple::Text->filter('thingy.pod')"
Some of these methods might be of interest to general users, as well as of interest to formatter-writers.
Note that the general pattern here is that the accessor-methods
read the attribute's value with
$value = $parser->attribute
and set the attribute's value with
$parser->attribute(newvalue). For each accessor, I typically
only mention one syntax or another, based on which I think you are actually
most likely to use.
$parser->no_whining( SOMEVALUE )
If you set this attribute to a true value, you will suppress the parser's complaints about irregularities in the Pod coding. By default, this attribute's value is false, meaning that irregularities will be reported.
Note that turning this attribute to true won't suppress one or two kinds of complaints about rarely occurring unrecoverable errors.
$parser->no_errata_section( SOMEVALUE )
If you set this attribute to a true value, you will stop the parser from generating a "POD ERRORS" section at the end of the document. By default, this attribute's value is false, meaning that an errata section will be generated, as necessary.
$parser->complain_stderr( SOMEVALUE )
If you set this attribute to a true value, it will send reports of parsing errors to STDERR. By default, this attribute's value is false, meaning that no output is sent to STDERR.
This returns the filename that this parser object was set to read from.
This returns true if
$parserhas read from a source, and has seen Pod content in it.
This returns true if
$parserhas read from a source, and come to the end of that source.
$parser->strip_verbatim_indent( SOMEVALUE )
The perlpod spec for a Verbatim paragraph is "It should be reproduced exactly...", which means that the whitespace you've used to indent your verbatim blocks will be preserved in the output. This can be annoying for outputs such as HTML, where that whitespace will remain in front of every line. It's an unfortunate case where syntax is turned into semantics.
If the POD your parsing adheres to a consistent indentation policy, you can have such indentation stripped from the beginning of every line of your verbatim blocks. This method tells Pod::Simple what to strip. For two-space indents, you'd use:
- $parser->strip_verbatim_indent(' ');
For tab indents, you'd use a tab character:
If the POD is inconsistent about the indentation of verbatim blocks, but you have figured out a heuristic to determine how much a particular verbatim block is indented, you can pass a code reference instead. The code reference will be executed with one argument, an array reference of all the lines in the verbatim block, and should return the value to be stripped from each line. For example, if you decide that you're fine to use the first line of the verbatim block to set the standard for indentation of the rest of the block, you can look at the first line and return the appropriate value, like so:
If you'd rather treat each line individually, you can do that, too, by just transforming them in-place in the code reference and returning
undef. Say that you don't want any lines indented. You can do something like this:
This is just a beta release -- there are a good number of things still left to do. Notably, support for EBCDIC platforms is still half-done, an untested.
Questions or discussion about POD and Pod::Simple should be sent to the firstname.lastname@example.org mail list. Send an empty email to email@example.com to subscribe.
Patches against Pod::Simple are welcome. Please send bug reports to <firstname.lastname@example.org>.
COPYRIGHT AND DISCLAIMERS
Copyright (c) 2002 Sean M. Burke.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
Pod::Simple was created by Sean M. Burke <email@example.com>. But don't bother him, he's retired.
Pod::Simple is maintained by: