Pod::Text(3perl) | Perl Programmers Reference Guide | Pod::Text(3perl) |
Pod::Text - Convert POD data to formatted text
use Pod::Text; my $parser = Pod::Text->new (sentence => 1, width => 78); # Read POD from STDIN and write to STDOUT. $parser->parse_from_filehandle; # Read POD from file.pod and write to file.txt. $parser->parse_from_file ('file.pod', 'file.txt');
Pod::Text is a module that can convert documentation in the POD format (the preferred language for documenting Perl) into formatted text. It uses no special formatting controls or codes, and its output is therefore suitable for nearly any device.
Pod::Text uses the following logic to choose an output encoding, in order:
One caveat: Pod::Text has to commit to an output encoding the first time it outputs a non-ASCII character, and then has to stick with it for consistency. However, "=encoding" commands don't have to be at the beginning of a POD document. If someone uses a non-ASCII character early in a document with an escape, such as E<0xEF>, and then puts "=encoding iso-8859-1" later, ideally Pod::Text would follow rule 3 and output the entire document as ISO 8859-1. Instead, it will commit to UTF-8 following rule 4 as soon as it sees that escape, and then stick with that encoding for the rest of the document.
Unfortunately, there's no universally good choice for an output encoding. Each choice will be incorrect in some circumstances. This approach was chosen primarily for backwards compatibility. Callers should consider forcing the output encoding via "encoding" if they have any knowledge about what encoding the user may expect.
In particular, consider importing the Encode::Locale module, if available, and setting "encoding" to "locale" to use an output encoding appropriate to the user's locale. But be aware that if the user is not using locales or is using a locale of "C", Encode::Locale will set the output encoding to US-ASCII. This will cause all non-ASCII characters will be replaced with "?" and produce a flurry of warnings about unsupported characters, which may or may not be what you want.
If the output file handle has a PerlIO encoding layer set, this parameter will be ignored and no encoding will be done by Pod::Man. It will instead rely on the encoding layer to make whatever output encoding transformations are desired.
WARNING: The input encoding of the POD source is independent from the output encoding, and setting this option does not affect the interpretation of the POD input. Unless your POD source is US-ASCII, its encoding should be declared with the "=encoding" command in the source, as near to the top of the file as possible. If this is not done, Pod::Simple will will attempt to guess the encoding and may be successful if it's Latin-1 or UTF-8, but it will produce warnings. See perlpod(1) for more information.
The default is "pod".
The special value "all" enables all guesswork. This is also the default for backward compatibility reasons. The special value "none" disables all guesswork. Otherwise, the value of this option should be a comma-separated list of one or more of the following keywords:
Any unknown guesswork name is silently ignored (for potential future compatibility), so be careful about spelling.
L<foo|http://example.com/>
is formatted as:
foo <http://example.com/>
This option, if set to a true value, suppresses the URL when anchor text is given, so this example would be formatted as just "foo". This can produce less cluttered output in cases where the URLs are not particularly important.
This may also be set to the special value "none", in which case no quote marks are added around C<> text.
As a derived class from Pod::Simple, Pod::Text supports the same methods and interfaces. See Pod::Simple for all the details. This section summarizes the most-frequently-used methods and the ones added by Pod::Text.
my $man = Pod::Man->new(); my $output; $man->output_string(\$output); $man->parse_file('/some/input/file');
Be aware that the output in that variable will already be encoded (see "Encoding").
parse_from_filehandle() is provided for backward compatibility with older versions of Pod::Man. parse_from_file() should be used instead.
This method expects raw bytes, not decoded characters.
This method expects raw bytes, not decoded characters.
Pod::Text exports one function for backward compatibility with older versions. This function is deprecated; instead, use the object-oriented interface described above.
If "-a" is given as an initial argument, pass the "alt" option to the Pod::Text constructor. This enables alternative formatting.
If "-NNN" is given as an initial argument, pass the "width" option to the Pod::Text constructor with the number "NNN" as its argument. This sets the wrap line width to NNN.
Pod::Text 2.03 (based on Pod::Parser) was the first version of this module included with Perl, in Perl 5.6.0. Earlier versions of Perl had a different Pod::Text module, with a different API.
The current API based on Pod::Simple was added in Pod::Text 3.00. Pod::Text 3.01 was included in Perl 5.9.3, the first version of Perl to incorporate those changes. This is the first version that correctly supports all modern POD syntax. The parse_from_filehandle() method was re-added for backward compatibility in Pod::Text 3.07, included in Perl 5.9.4.
Pod::Text 3.12, included in Perl 5.10.1, first implemented the current practice of attempting to match the default output encoding with the input encoding of the POD source, unless overridden by the "utf8" option or (added later) the "encoding" option.
Support for anchor text in L<> links of type URL was added in Pod::Text 3.14, included in Perl 5.11.5.
parse_lines(), parse_string_document(), and parse_file() set a default output file handle of "STDOUT" if one was not already set as of Pod::Text 3.18, included in Perl 5.19.5.
Pod::Text 4.00, included in Perl 5.23.7, aligned the module version and the version of the podlators distribution. All modules included in podlators, and the podlators distribution itself, share the same version number from this point forward.
Pod::Text 4.09, included in Perl 5.25.7, fixed a serious bug on EBCDIC systems, present in all versions back to 3.00, that would cause opening brackets to disappear.
Pod::Text 5.00 now defaults, on non-EBCDIC systems, to UTF-8 encoding if it sees a non-ASCII character in the input and the input encoding is not specified. It also commits to an encoding with the first non-ASCII character and does not change the output encoding if the input encoding changes. The Encode module is now used for all output encoding rather than PerlIO layers, which fixes earlier problems with output to scalars.
Russ Allbery <rra@cpan.org>, based very heavily on the original Pod::Text by Tom Christiansen <tchrist@mox.perl.com> and its conversion to Pod::Parser by Brad Appleton <bradapp@enteract.com>. Sean Burke's initial conversion of Pod::Man to use Pod::Simple provided much-needed guidance on how to use Pod::Simple.
Copyright 1999-2002, 2004, 2006, 2008-2009, 2012-2016, 2018-2019, 2022 Russ Allbery <rra@cpan.org>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
Encode::Locale, Encode::Supproted, Pod::Simple, Pod::Text::Termcap, perlpod(1), pod2text(1)
The current version of this module is always available from its web site at <https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the Perl core distribution as of 5.6.0.
2024-10-02 | perl v5.38.2 |