Pod::Man(3pm) | Perl Programmers Reference Guide | Pod::Man(3pm) |
Pod::Man - Convert POD data to formatted *roff input
use Pod::Man; my $parser = Pod::Man->new (release => $VERSION, section => 8); # Read POD from STDIN and write to STDOUT. $parser->parse_file (\*STDIN); # Read POD from file.pod and write to file.1. $parser->parse_from_file ('file.pod', 'file.1');
Pod::Man is a module to convert documentation in the POD format (the preferred language for documenting Perl) into *roff input using the man macro set. The resulting *roff code is suitable for display on a terminal using nroff(1), normally via man(1), or printing using troff(1). It is conventionally invoked using the driver script pod2man, but it can also be used directly.
As a derived class from Pod::Simple, Pod::Man supports the same methods and interfaces. See Pod::Simple for all the details.
new() can take options, in the form of key/value pairs that control the behavior of the parser. See below for details.
If no options are given, Pod::Man uses the name of the input file with any trailing ".pod", ".pm", or ".pl" stripped as the man page title, to section 1 unless the file ended in ".pm" in which case it defaults to section 3, to a centered title of "User Contributed Perl Documentation", to a centered footer of the Perl version it is run with, and to a left-hand footer of the modification date of its input (or the current date if given "STDIN" for input).
Pod::Man assumes that your *roff formatters have a fixed-width font named "CW". If yours is called something else (like "CR"), use the "fixed" option to specify it. This generally only matters for troff output for printing. Similarly, you can set the fonts used for bold, italic, and bold italic fixed-width output.
Besides the obvious pod conversions, Pod::Man also takes care of formatting func(), func(3), and simple variable references like $foo or @bar so you don't have to use code escapes for them; complex expressions like $fred{'stuff'} will still need to be escaped, though. It also translates dashes that aren't used as hyphens into en dashes, makes long dashes--like this--into proper em dashes, fixes "paired quotes," makes C++ look right, puts a little space between double underscores, makes ALLCAPS a teeny bit smaller in troff, and escapes stuff that *roff treats as special so that you don't have to.
The recognized options to new() are as follows. All options take a single argument.
The default is "pod".
Also see the "quotes" option, which can be used to set both quotes at once. If both "quotes" and one of the other options is set, "lquote" or "rquote" overrides "quotes".
If generating a manual page from standard input, the name will be set to "STDIN" if this option is not provided. Providing this option is strongly recommended to set a meaningful manual page name.
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 (but the font is still changed for troff output).
Also see the "lquote" and "rquote" options, which can be used to set the left and right quotes independently. If both "quotes" and one of the other options is set, "lquote" or "rquote" overrides "quotes".
Note that some system "an" macro sets assume that the centered footer will be a modification date and will prepend something like "Last modified: ". If this is the case for your target system, you may want to set "release" to the last modified date and "date" to the version number.
By default, section 1 will be used unless the file ends in ".pm" in which case section 3 will be selected.
If this option is set, Pod::Man will instead output UTF-8. If your *roff implementation can handle it, this is the best output format to use and avoids corruption of documents containing non-ASCII characters. However, be warned that *roff source with literal UTF-8 characters is not supported by many implementations and may even result in segfaults and other bad behavior.
Be aware that, when using this option, the input encoding of your POD source should be properly declared unless it's US-ASCII. 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. Use the "=encoding" command to declare the encoding. See perlpod(1) for more information.
The standard Pod::Simple method parse_file() takes one argument naming the POD file to read from. By default, the output is sent to "STDOUT", but this can be changed with the output_fh() method.
The standard Pod::Simple method parse_from_file() takes up to two arguments, the first being the input file to read POD from and the second being the file to write the formatted output to.
You can also call parse_lines() to parse an array of lines or parse_string_document() to parse a document already in memory. As with parse_file(), parse_lines() and parse_string_document() default to sending their output to "STDOUT" unless changed with the output_fh() method. Be aware that parse_lines() and parse_string_document() both expect raw bytes, not decoded characters.
To put the output from any parse method into a string instead of a file handle, call the output_string() method instead of output_fh().
See Pod::Simple for more specific details on the methods available to all derived parsers.
(Arguably, according to the specification, this variable should be used only if the timestamp of the input file is not available and Pod::Man uses the current time. However, for reproducible builds in Debian, results were more reliable if this variable overrode the timestamp of the input file.)
Encoding handling assumes that PerlIO is available and does not work properly if it isn't. The "utf8" option is therefore not supported unless Perl is built with PerlIO support.
There is currently no way to turn off the guesswork that tries to format unmarked text appropriately, and sometimes it isn't wanted (particularly when using POD to document something other than Perl). Most of the work toward fixing this has now been done, however, and all that's still needed is a user interface.
The NAME section should be recognized specially and index entries emitted for everything in that section. This would have to be deferred until the next section, since extraneous things in NAME tends to confuse various man page processors. Currently, no index entries are emitted for anything in NAME.
Pod::Man doesn't handle font names longer than two characters. Neither do most troff implementations, but GNU troff does as an extension. It would be nice to support as an option for those who want to use it.
The preamble added to each output file is rather verbose, and most of it is only necessary in the presence of non-ASCII characters. It would ideally be nice if all of those definitions were only output if needed, perhaps on the fly as the characters are used.
Pod::Man is excessively slow.
If Pod::Man is given the "utf8" option, the encoding of its output file handle will be forced to UTF-8 if possible, overriding any existing encoding. This will be done even if the file handle is not created by Pod::Man and was passed in from outside. This maintains consistency regardless of PERL_UNICODE and other settings.
The handling of hyphens and em dashes is somewhat fragile, and one may get the wrong one under some circumstances. This should only matter for troff output.
When and whether to use small caps is somewhat tricky, and Pod::Man doesn't necessarily get it right.
Converting neutral double quotes to properly matched double quotes doesn't work unless there are no formatting codes between the quote marks. This only matters for troff output.
Russ Allbery <rra@cpan.org>, based very heavily on the original pod2man by Tom Christiansen <tchrist@mox.perl.com>. The modifications to work with Pod::Simple instead of Pod::Parser were originally contributed by Sean Burke <sburke@cpan.org> (but I've since hacked them beyond recognition and all bugs are mine).
Copyright 1999-2010, 2012-2019 Russ Allbery <rra@cpan.org>
Substantial contributions by Sean Burke <sburke@cpan.org>.
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
Pod::Simple, perlpod(1), pod2man(1), nroff(1), troff(1), man(1), man(7)
Ossanna, Joseph F., and Brian W. Kernighan. "Troff User's Manual," Computing Science Technical Report No. 54, AT&T Bell Laboratories. This is the best documentation of standard nroff and troff. At the time of this writing, it's available at <http://www.troff.org/54.pdf>.
The man page documenting the man macro set may be man(5) instead of man(7) on your system. Also, please see pod2man(1) for extensive documentation on writing manual pages if you've not done it before and aren't familiar with the conventions.
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.
2022-02-19 | perl v5.34.1 |