Pod::Text(3pm)
π NAME π
Pod::Text(3pm) β yes, from the Perl Programmers Reference Guide β is literally the manual for Pod::Text, the module that converts POD data into formatted text. The official name viber: Pod::Text - Convert POD data to formatted text. π«Ά
β¨ SYNOPSIS β¨
Okay bestie, here's the copy-paste moment, no cap:
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');
π DESCRIPTION π
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. iconic, honestly.
π¦ Encoding π¦
So when it comes to picking an output encoding, Pod::Text follows this logic, in order:
- If a PerlIO encoding layer is set on the output file handle, it does not do any output encoding and will instead rely on the PerlIO encoding layer.
- If the
encodingorutf8options are set, use the output encoding specified by those options. - If the input encoding of the POD source file was explicitly specified (using
=encoding) or automatically detected by Pod::Simple, use that as the output encoding as well. - Otherwise, if running on a non-EBCDIC system, use UTF-8 as the output encoding. Since this is a superset of ASCII, this will result in ASCII output unless the POD input contains non-ASCII characters without declaring or autodetecting an encoding (usually via
E<>escapes). - Otherwise, for EBCDIC systems, output without doing any encoding and hope this works. π
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. the way encoding is a whole commitment issue, iykyk.
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 to be replaced with ? and produce a flurry of warnings about unsupported characters, which may or may not be what you want.
π CLASS METHODS π
π new(ARGS) π
Create a new Pod::Text object. ARGS should be a list of key/value pairs, where the keys are chosen from the following. Each option is annotated with the version of Pod::Text in which that option was added with its current meaning.
alt[2.00]β If set to a true value, selects an alternate output format that, among other things, uses a different heading style and marks=itementries with a colon in the left margin. Defaults to false.code[2.13]β If set to a true value, the non-POD parts of the input file will be included in the output. Useful for viewing code documented with POD blocks with the POD rendered and the code left intact.encoding[5.00]β Specifies the encoding of the output. The value must be an encoding recognized by theEncodemodule (seeEncode::Supported). If the output contains characters that cannot be represented in this encoding, that is an error that will be reported as configured by theerrorsoption. If error handling is other thandie, the unrepresentable character will be replaced with theEncodesubstitution character (normally?).
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 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.
errors[3.17]β How to report errors.diesays to throw an exception on any POD formatting error.stderrsays to report errors on standard error, but not to throw an exception.podsays to include a POD ERRORS section in the resulting documentation summarizing the errors.noneignores POD errors entirely, as much as possible.
The default is pod.
guesswork[5.01]β By default,Pod::Textapplies some default formatting rules based on guesswork and regular expressions that are intended to make writing Perl documentation easier and require less explicit markup. These rules may not always be appropriate, particularly for documentation that isn't about Perl. This option allows turning all or some of it off.
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:
quotingβ If no guesswork is enabled, any text enclosed inC<>is surrounded by double quotes innroff(terminal) output unless the contents are already quoted. When this guesswork is enabled, quote marks will also be suppressed for Perl variables, function names, function calls, numbers, and hex constants.
Any unknown guesswork name is silently ignored (for potential future compatibility), so be careful about spelling.
indent[2.00]β The number of spaces to indent regular text, and the default indentation for=overblocks. Defaults to 4.loose[2.00]β If set to a true value, a blank line is printed after a=head1heading. If set to false (the default), no blank line is printed after=head1, although one is still printed after=head2. This is the default because it's the expected formatting for manual pages; if you're formatting arbitrary text documents, setting this to true may result in more pleasing output.margin[2.21]β The width of the left margin in spaces. Defaults to 0. This is the margin for all text, including headings, not the amount by which regular text is indented; for the latter, see theindentoption. To set the right margin, see thewidthoption.nourls[3.17]β Normally,L<>formatting codes with a URL but anchor text are formatted to show both the anchor text and the URL. In other words:
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.
quotes[4.00]β Sets the quote marks used to surroundC<>text. If the value is a single character, it is used as both the left and right quote. Otherwise, it is split in half, and the first half of the string is used as the left quote and the second is used as the right quote.
This may also be set to the special value none, in which case no quote marks are added around C<> text.
sentence[3.00]β If set to a true value,Pod::Textwill assume that each sentence ends in two spaces, and will try to preserve that spacing. If set to false, all consecutive whitespace in non-verbatim paragraphs is compressed into a single space. Defaults to false.stderr[3.10]β Send error messages about invalid POD to standard error instead of appending a POD ERRORS section to the generated output. This is equivalent to settingerrorstostderriferrorsis not already set. It is supported for backward compatibility.utf8[3.12]β If this option is set to a true value, the output encoding is set to UTF-8. This is equivalent to settingencodingtoUTF-8ifencodingis not already set. It is supported for backward compatibility.width[2.00]β The column at which to wrap text on the right-hand side. Defaults to 76.
π INSTANCE METHODS π
Okay so real talk β Pod::Text is a derived class of Pod::Simple, which means it supports the exact same methods and interfaces. Like, all of them. Go read Pod::Simple for the full deets if you're that girl. This section is just the highlight reel: the most-frequently-used methods plus the ones Pod::Text itself added. Slay.
output_fh(FH)
Points the output from parse_file(), parse_lines(), or parse_string_document() at the file handle FH instead of STDOUT. That's it. That's the whole vibe. π
output_string(REF)
Same idea, but instead of STDOUT, the output goes into the scalar variable that REF points to. Honestly iconic for when you just want the text in a variable and not on your terminal. Like:
my $man = Pod::Man->new();
my $output;
$man->output_string(\$output);
$man->parse_file('/some/input/file');
Heads up bestie β the stuff sitting in that variable is already encoded. See "Encoding". Don't come for me when you double-encode it. π
parse_file(PATH)
Reads the POD source from PATH and formats it. By default the output goes to STDOUT, but you can redirect it with output_fh() or output_string(). Easy.
parse_from_file(INPUT, OUTPUT)
parse_from_filehandle(FH, OUTPUT)
Reads the POD source from INPUT, formats it, and pushes the results to OUTPUT.
parse_from_filehandle() only exists for backward compatibility with older versions of Pod::Man. Use parse_from_file() instead, fr fr. It's the main character here.
parse_lines(LINES[, ...[, undef]])
Parses the lines you hand it as POD source, writing output to either STDOUT or whatever you set with output_fh() / output_string(). You can call this repeatedly to feed it more input lines. Pass an explicit undef to say "okay that's the end of the input, we're done here".
β οΈ This method expects raw bytes, not decoded characters. Bytes. Raw. Do not send it characters, I'm begging. π
parse_string_document(INPUT)
Parses the scalar variable you give it as POD source, writing output to either STDOUT or whatever you set with output_fh() / output_string().
β οΈ Again: raw bytes, not decoded characters. Same energy as above. π
πΈ FUNCTIONS πΈ
Pod::Text exports exactly one function, and only for backward compatibility with older versions. It's deprecated, bestie! Use the object-oriented interface described above instead. The function in question:
pod2text([[-a,] [-NNN,]] INPUT[, OUTPUT])β Converts the POD source from INPUT to text and writes it to OUTPUT. If OUTPUT isn't given, it defaults toSTDOUT. INPUT can be any expression supported as the second argument to two-argumentopen().
If -a is given as an initial argument, it passes the alt option to the Pod::Text constructor. That turns on alternative formatting. β¨
If -NNN is given as an initial argument, it passes the width option to the Pod::Text constructor with the number NNN as its argument. So your wrap line width becomes NNN. π
π¦ DIAGNOSTICS π¦
Time for the vibe check on error messages. Buckle up.
- Bizarre space in item
- Item called without tag
(W) Something went wrong in the internal =item processing. These messages mean there's a bug in Pod::Text β you should literally never see them. If you do, it's not you, it's the module. π
- Can't open %s for reading: %s
(F) Pod::Text was invoked through the compatibility-mode pod2text() interface and the input file it was given could not be opened. Rough.
- Invalid errors setting "%s"
(F) The errors parameter you passed to the constructor was set to a value nobody recognizes.
- Invalid quote specification "%s"
(F) The quote specification you gave (that's the quotes option to the constructor) was invalid. For the record, a quote specification must be either one character long or an even number (greater than one) characters long. That's the rule, no cap.
- POD document had syntax errors
(F) The POD document being formatted had syntax errors and the errors option was set to die. So it did exactly what you told it to. π
π COMPATIBILITY π
History lesson, but make it cute. π«Ά
Pod::Text 2.03 (based on Pod::Parser) was the first version of this module included with Perl, shipping in Perl 5.6.0. Earlier versions of Perl had a different Pod::Text module with a different API. Chaotic, I know.
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 β and that's 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. One version to rule them all. π
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. Like, just gone. Bracket erasure. Not the vibe. π
Pod::Text 5.00 and later, included in Perl 5.37.7, default, 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. They also commit to an encoding with the first non-ASCII character and do 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. Glow-up complete. β¨
β οΈ CAVEATS β οΈ
Line wrapping is done only at ASCII spaces and tabs, rather than using a correct Unicode-aware line wrapping algorithm. So yes, it's giving slightly unhinged wrapping energy. Don't @ me, that's just how it is. π
π AUTHOR π
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. Respect to the whole lineage tbh. π«Ά
π COPYRIGHT AND LICENSE π
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.
β SEE ALSO β
Encode::LocaleEncode::SupprotedPod::SimplePod::Text::Termcapperlpod(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. π¦
And that's the whole page, bestie!! π This was Pod::Text(3pm), living in perl v5.42.3, dated 2026-11-03. Go forth and format some POD β you're literally gonna slay. πβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms