1# Convert POD data to formatted *roff input.
2#
3# This module translates POD documentation into *roff markup using the man
4# macro set, and is intended for converting POD documents written as Unix
5# manual pages to manual pages that can be read by the man(1) command.  It is
6# a replacement for the pod2man command distributed with versions of Perl
7# prior to 5.6.
8#
9# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
10
11##############################################################################
12# Modules and declarations
13##############################################################################
14
15package Pod::Man;
16
17use 5.010;
18use strict;
19use warnings;
20
21use Carp qw(carp croak);
22use Pod::Simple ();
23
24# Conditionally import Encode and set $HAS_ENCODE if it is available.  This is
25# required to support building as part of Perl core, since podlators is built
26# before Encode is.
27my $HAS_ENCODE;
28BEGIN {
29    $HAS_ENCODE = eval { require Encode };
30}
31
32our @ISA = qw(Pod::Simple);
33our $VERSION = '5.01';
34
35# Ensure that $Pod::Simple::nbsp and $Pod::Simple::shy are available.  Code
36# taken from Pod::Simple 3.32, but was only added in 3.30.
37my ($NBSP, $SHY);
38if ($Pod::Simple::VERSION ge 3.30) {
39    $NBSP = $Pod::Simple::nbsp;
40    $SHY  = $Pod::Simple::shy;
41} else {
42    $NBSP = chr utf8::unicode_to_native(0xA0);
43    $SHY  = chr utf8::unicode_to_native(0xAD);
44}
45
46# Import the ASCII constant from Pod::Simple.  This is true iff we're in an
47# ASCII-based universe (including such things as ISO 8859-1 and UTF-8), and is
48# generally only false for EBCDIC.
49BEGIN { *ASCII = \&Pod::Simple::ASCII }
50
51# Formatting instructions for various types of blocks.  cleanup makes hyphens
52# hard, adds spaces between consecutive underscores, and escapes backslashes.
53# convert translates characters into escapes.  guesswork means to apply the
54# transformations done by the guesswork sub (if enabled).  literal says to
55# protect literal quotes from being turned into UTF-8 quotes.  By default, all
56# transformations are on except literal, but some elements override.
57#
58# DEFAULT specifies the default settings.  All other elements should list only
59# those settings that they are overriding.  Data indicates =for roff blocks,
60# which should be passed along completely verbatim.
61#
62# Formatting inherits negatively, in the sense that if the parent has turned
63# off guesswork, all child elements should leave it off.
64my %FORMATTING = (
65    DEFAULT  => { cleanup => 1, convert => 1, guesswork => 1, literal => 0 },
66    Data     => { cleanup => 0, convert => 0, guesswork => 0, literal => 0 },
67    Verbatim => {                             guesswork => 0, literal => 1 },
68    C        => {                             guesswork => 0, literal => 1 },
69    X        => { cleanup => 0,               guesswork => 0               },
70);
71
72# Try to map an encoding as understood by Perl Encode to an encoding
73# understood by groff's preconv.  Encode doesn't care about hyphens or
74# capitalization, but preconv does.  The key is the canonicalized Encode
75# encoding, and the value is something preconv might understand.
76#
77# FreeBSD mandoc only understands utf-8 and iso-latin-1 as of 2022-09-24.
78# groff preconv prefers iso-8859-1, but also understands iso-latin-1, so
79# convert ISO-8859-1 to iso-latin-1 for FreeBSD.
80my %ENCODINGS = (
81    ascii     => 'us-ascii',
82    big5      => 'big5',
83    big5eten  => 'big5',
84    cp950     => 'big5',
85    cp1047    => 'cp1047',
86    euccn     => 'gb2312',
87    eucjp     => 'euc-jp',
88    euckr     => 'euc-kr',
89    gb2312    => 'gb2312',
90    gb2312raw => 'gb2312',
91    iso88591  => 'iso-latin-1',
92    iso88592  => 'iso-8859-2',
93    iso88595  => 'iso-8859-5',
94    iso88597  => 'iso-8859-7',
95    iso88599  => 'iso-8859-9',
96    iso885913 => 'iso-8859-13',
97    iso885915 => 'iso-8859-15',
98    koi8r     => 'koi8-r',
99    latin1    => 'iso-8859-1',
100    usascii   => 'us-ascii',
101    utf8      => 'utf-8',
102    utf16     => 'utf-16',
103    utf16be   => 'utf-16be',
104    utf16le   => 'utf-16le',
105);
106
107##############################################################################
108# Translation tables
109##############################################################################
110
111# The following table is adapted from Tom Christiansen's pod2man.  It is only
112# used with roff output.  It assumes that the standard preamble has already
113# been printed, since that's what defines all of the accent marks.  We really
114# want to do something better than this when *roff actually supports other
115# character sets itself, since these results are pretty poor.
116#
117# This only works in an ASCII world.  What to do in a non-ASCII world is very
118# unclear, so we just output what we get and hope for the best.
119my %ESCAPES;
120@ESCAPES{0xA0 .. 0xFF} = (
121    $NBSP, undef, undef, undef,            undef, undef, undef, undef,
122    undef, undef, undef, undef,            undef, $SHY,  undef, undef,
123
124    undef, undef, undef, undef,            undef, undef, undef, undef,
125    undef, undef, undef, undef,            undef, undef, undef, undef,
126
127    "A\\*`",  "A\\*'", "A\\*^", "A\\*~",   "A\\*:", "A\\*o", "\\*(Ae", "C\\*,",
128    "E\\*`",  "E\\*'", "E\\*^", "E\\*:",   "I\\*`", "I\\*'", "I\\*^",  "I\\*:",
129
130    "\\*(D-", "N\\*~", "O\\*`", "O\\*'",   "O\\*^", "O\\*~", "O\\*:",  undef,
131    "O\\*/",  "U\\*`", "U\\*'", "U\\*^",   "U\\*:", "Y\\*'", "\\*(Th", "\\*8",
132
133    "a\\*`",  "a\\*'", "a\\*^", "a\\*~",   "a\\*:", "a\\*o", "\\*(ae", "c\\*,",
134    "e\\*`",  "e\\*'", "e\\*^", "e\\*:",   "i\\*`", "i\\*'", "i\\*^",  "i\\*:",
135
136    "\\*(d-", "n\\*~", "o\\*`", "o\\*'",   "o\\*^", "o\\*~", "o\\*:",  undef,
137    "o\\*/" , "u\\*`", "u\\*'", "u\\*^",   "u\\*:", "y\\*'", "\\*(th", "y\\*:",
138) if ASCII;
139
140##############################################################################
141# Utility functions
142##############################################################################
143
144# Quote an argument to a macro.
145#
146# $arg - Intended argument to the macro
147#
148# Returns: $arg suitably escaped and quoted
149sub _quote_macro_argument {
150    my ($arg) = @_;
151    if (length($arg) > 0 && $arg !~ m{ [\s\"] }xms) {
152        return $arg;
153    }
154    $arg =~ s{ \" }{""}xmsg;
155    return qq("$arg");
156}
157
158# Returns whether the given encoding needs a call to Encode::encode.
159sub _needs_encode {
160    my ($encoding) = @_;
161    return $encoding ne 'roff' && $encoding ne 'groff';
162}
163
164##############################################################################
165# Object initialization
166##############################################################################
167
168# Initialize the object and set various Pod::Simple options that we need.
169# Here, we also process any additional options passed to the constructor or
170# set up defaults if none were given.  Note that all internal object keys are
171# in all-caps, reserving all lower-case object keys for Pod::Simple and user
172# arguments.
173sub new {
174    my $class = shift;
175    my $self = $class->SUPER::new;
176
177    # Tell Pod::Simple to keep whitespace whenever possible.
178    if (my $preserve_whitespace = $self->can ('preserve_whitespace')) {
179        $self->$preserve_whitespace (1);
180    } else {
181        $self->fullstop_space_harden (1);
182    }
183
184    # The =for and =begin targets that we accept.
185    $self->accept_targets (qw/man MAN roff ROFF/);
186
187    # Ensure that contiguous blocks of code are merged together.  Otherwise,
188    # some of the guesswork heuristics don't work right.
189    $self->merge_text (1);
190
191    # Pod::Simple doesn't do anything useful with our arguments, but we want
192    # to put them in our object as hash keys and values.  This could cause
193    # problems if we ever clash with Pod::Simple's own internal class
194    # variables.
195    my %opts = @_;
196    my @opts = map { ("opt_$_", $opts{$_}) } keys %opts;
197    %$self = (%$self, @opts);
198
199    # Pod::Simple uses encoding internally, so we need to store it as
200    # ENCODING.  Set the default to UTF-8 if not specified.
201    #
202    # Degrade to the old roff encoding if Encode is not available.
203    #
204    # Suppress the warning message when PERL_CORE is set, indicating this is
205    # running as part of the core Perl build.  Perl builds podlators (and all
206    # pure Perl modules) before Encode and other XS modules, so Encode won't
207    # yet be available.  Rely on the Perl core build to generate man pages
208    # later, after all the modules are available, so that UTF-8 handling will
209    # be correct.
210    my %options = @_;
211    if (defined $self->{opt_encoding}) {
212        $$self{ENCODING} = $self->{opt_encoding};
213    } elsif (ASCII) {
214        $$self{ENCODING} = 'UTF-8';
215    } else {
216        $$self{ENCODING} = 'groff';
217    }
218    if (_needs_encode($$self{ENCODING}) && !$HAS_ENCODE) {
219        if (!$ENV{PERL_CORE}) {
220            carp ('encoding requested but Encode module not available,'
221                    . ' falling back to groff escapes');
222        }
223        $$self{ENCODING} = 'groff';
224    }
225
226    # Send errors to stderr if requested.
227    if ($self->{opt_stderr} and not $self->{opt_errors}) {
228        $self->{opt_errors} = 'stderr';
229    }
230    delete $self->{opt_stderr};
231
232    # Validate the errors parameter and act on it.
233    $self->{opt_errors} //= 'pod';
234    if ($self->{opt_errors} eq 'stderr' || $self->{opt_errors} eq 'die') {
235        $self->no_errata_section (1);
236        $self->complain_stderr (1);
237        if ($self->{opt_errors} eq 'die') {
238            $self->{complain_die} = 1;
239        }
240    } elsif ($self->{opt_errors} eq 'pod') {
241        $self->no_errata_section (0);
242        $self->complain_stderr (0);
243    } elsif ($self->{opt_errors} eq 'none') {
244        $self->no_errata_section (1);
245        $self->no_whining (1);
246    } else {
247        croak (qq(Invalid errors setting: "$self->{opt_errors}"));
248    }
249    delete $self->{opt_errors};
250
251    # Initialize various other internal constants based on our arguments.
252    $self->init_fonts;
253    $self->init_quotes;
254    $self->init_page;
255
256    # Configure guesswork based on options.
257    my $guesswork = $self->{opt_guesswork} || q{};
258    my %guesswork = map { $_ => 1 } split(m{,}xms, $guesswork);
259    if (!%guesswork || $guesswork{all}) {
260        #<<<
261        $$self{GUESSWORK} = {
262            functions => 1,
263            manref    => 1,
264            quoting   => 1,
265            variables => 1,
266        };
267        #>>>
268    } elsif ($guesswork{none}) {
269        $$self{GUESSWORK} = {};
270    } else {
271        $$self{GUESSWORK} = {%guesswork};
272    }
273
274    return $self;
275}
276
277# Translate a font string into an escape.
278sub toescape { (length ($_[0]) > 1 ? '\f(' : '\f') . $_[0] }
279
280# Determine which fonts the user wishes to use and store them in the object.
281# Regular, italic, bold, and bold-italic are constants, but the fixed width
282# fonts may be set by the user.  Sets the internal hash key FONTS which is
283# used to map our internal font escapes to actual *roff sequences later.
284sub init_fonts {
285    my ($self) = @_;
286
287    # Figure out the fixed-width font.  If user-supplied, make sure that they
288    # are the right length.
289    for (qw(fixed fixedbold fixeditalic fixedbolditalic)) {
290        my $font = $self->{"opt_$_"};
291        if (defined($font) && (length($font) < 1 || length($font) > 2)) {
292            croak(qq(roff font should be 1 or 2 chars, not "$font"));
293        }
294    }
295
296    # Set the default fonts.  We can't be sure portably across different
297    # implementations what fixed bold-italic may be called (if it's even
298    # available), so default to just bold.
299    #<<<
300    $self->{opt_fixed}           ||= 'CW';
301    $self->{opt_fixedbold}       ||= 'CB';
302    $self->{opt_fixeditalic}     ||= 'CI';
303    $self->{opt_fixedbolditalic} ||= 'CB';
304    #>>>
305
306    # Set up a table of font escapes.  First number is fixed-width, second is
307    # bold, third is italic.
308    $self->{FONTS} = {
309        '000' => '\fR',
310        '001' => '\fI',
311        '010' => '\fB',
312        '011' => '\f(BI',
313        '100' => toescape($self->{opt_fixed}),
314        '101' => toescape($self->{opt_fixeditalic}),
315        '110' => toescape($self->{opt_fixedbold}),
316        '111' => toescape($self->{opt_fixedbolditalic}),
317    };
318
319    # Precalculate a regex that matches all fixed-width fonts, which will be
320    # used later by switchquotes.
321    my @fixedpat = map { quotemeta($self->{FONTS}{$_}) } qw(100 101 110 111);
322    my $fixedpat = join('|', @fixedpat);
323    $self->{FIXEDPAT} = qr{ $fixedpat }xms;
324}
325
326# Initialize the quotes that we'll be using for C<> text.  This requires some
327# special handling, both to parse the user parameters if given and to make
328# sure that the quotes will be safe against *roff.  Sets the internal hash
329# keys LQUOTE and RQUOTE.
330sub init_quotes {
331    my ($self) = (@_);
332
333    # Handle the quotes option first, which sets both quotes at once.
334    $self->{opt_quotes} ||= '"';
335    if ($self->{opt_quotes} eq 'none') {
336        $$self{LQUOTE} = $$self{RQUOTE} = '';
337    } elsif (length ($self->{opt_quotes}) == 1) {
338        $$self{LQUOTE} = $$self{RQUOTE} = $self->{opt_quotes};
339    } elsif (length ($self->{opt_quotes}) % 2 == 0) {
340        my $length = length ($self->{opt_quotes}) / 2;
341        $$self{LQUOTE} = substr ($self->{opt_quotes}, 0, $length);
342        $$self{RQUOTE} = substr ($self->{opt_quotes}, $length);
343    } else {
344        croak(qq(Invalid quote specification "$self->{opt_quotes}"))
345    }
346
347    # Now handle the lquote and rquote options.
348    if (defined($self->{opt_lquote})) {
349        $self->{opt_lquote} = q{} if $self->{opt_lquote} eq 'none';
350        $$self{LQUOTE} = $self->{opt_lquote};
351    }
352    if (defined $self->{opt_rquote}) {
353        $self->{opt_rquote} = q{} if $self->{opt_rquote} eq 'none';
354        $$self{RQUOTE} = $self->{opt_rquote};
355    }
356}
357
358# Initialize the page title information and indentation from our arguments.
359sub init_page {
360    my ($self) = @_;
361
362    # Get the version from the running Perl.
363    my @version = ($] =~ /^(\d+)\.(\d{3})(\d+)$/);
364    for (@version) { $_ += 0 }
365    my $version = join ('.', @version);
366
367    # Set the defaults for page titles and indentation if the user didn't
368    # override anything.
369    $self->{opt_center}  //= 'User Contributed Perl Documentation';
370    $self->{opt_release} //= 'perl v' . $version;
371    $self->{opt_indent}  //= 4;
372}
373
374##############################################################################
375# Core parsing
376##############################################################################
377
378# This is the glue that connects the code below with Pod::Simple itself.  The
379# goal is to convert the event stream coming from the POD parser into method
380# calls to handlers once the complete content of a tag has been seen.  Each
381# paragraph or POD command will have textual content associated with it, and
382# as soon as all of a paragraph or POD command has been seen, that content
383# will be passed in to the corresponding method for handling that type of
384# object.  The exceptions are handlers for lists, which have opening tag
385# handlers and closing tag handlers that will be called right away.
386#
387# The internal hash key PENDING is used to store the contents of a tag until
388# all of it has been seen.  It holds a stack of open tags, each one
389# represented by a tuple of the attributes hash for the tag, formatting
390# options for the tag (which are inherited), and the contents of the tag.
391
392# Add a block of text to the contents of the current node, formatting it
393# according to the current formatting instructions as we do.
394sub _handle_text {
395    my ($self, $text) = @_;
396    my $tag = $$self{PENDING}[-1];
397    $$tag[2] .= $self->format_text ($$tag[1], $text);
398}
399
400# Given an element name, get the corresponding method name.
401sub method_for_element {
402    my ($self, $element) = @_;
403    $element =~ tr/A-Z-/a-z_/;
404    $element =~ tr/_a-z0-9//cd;
405    return $element;
406}
407
408# Handle the start of a new element.  If cmd_element is defined, assume that
409# we need to collect the entire tree for this element before passing it to the
410# element method, and create a new tree into which we'll collect blocks of
411# text and nested elements.  Otherwise, if start_element is defined, call it.
412sub _handle_element_start {
413    my ($self, $element, $attrs) = @_;
414    my $method = $self->method_for_element ($element);
415
416    # If we have a command handler, we need to accumulate the contents of the
417    # tag before calling it.  Turn off IN_NAME for any command other than
418    # <Para> and the formatting codes so that IN_NAME isn't still set for the
419    # first heading after the NAME heading.
420    if ($self->can ("cmd_$method")) {
421        $$self{IN_NAME} = 0 if ($element ne 'Para' && length ($element) > 1);
422
423        # How we're going to format embedded text blocks depends on the tag
424        # and also depends on our parent tags.  Thankfully, inside tags that
425        # turn off guesswork and reformatting, nothing else can turn it back
426        # on, so this can be strictly inherited.
427        my $formatting = {
428            %{ $$self{PENDING}[-1][1] || $FORMATTING{DEFAULT} },
429            %{ $FORMATTING{$element} || {} },
430        };
431        push (@{ $$self{PENDING} }, [ $attrs, $formatting, '' ]);
432    } elsif (my $start_method = $self->can ("start_$method")) {
433        $self->$start_method ($attrs, '');
434    }
435}
436
437# Handle the end of an element.  If we had a cmd_ method for this element,
438# this is where we pass along the tree that we built.  Otherwise, if we have
439# an end_ method for the element, call that.
440sub _handle_element_end {
441    my ($self, $element) = @_;
442    my $method = $self->method_for_element ($element);
443
444    # If we have a command handler, pull off the pending text and pass it to
445    # the handler along with the saved attribute hash.
446    if (my $cmd_method = $self->can ("cmd_$method")) {
447        my $tag = pop @{ $$self{PENDING} };
448        my $text = $self->$cmd_method ($$tag[0], $$tag[2]);
449        if (defined $text) {
450            if (@{ $$self{PENDING} } > 1) {
451                $$self{PENDING}[-1][2] .= $text;
452            } else {
453                $self->output ($text);
454            }
455        }
456    } elsif (my $end_method = $self->can ("end_$method")) {
457        $self->$end_method ();
458    }
459}
460
461##############################################################################
462# General formatting
463##############################################################################
464
465# Format a text block.  Takes a hash of formatting options and the text to
466# format.  Currently, the only formatting options are guesswork, cleanup, and
467# convert, all of which are boolean.
468sub format_text {
469    my ($self, $options, $text) = @_;
470    my $guesswork = $$options{guesswork} && !$$self{IN_NAME};
471    my $cleanup = $$options{cleanup};
472    my $convert = $$options{convert};
473    my $literal = $$options{literal};
474
475    # Cleanup just tidies up a few things, telling *roff that the hyphens are
476    # hard, putting a bit of space between consecutive underscores, escaping
477    # backslashes, and converting zero-width spaces to zero-width break
478    # points.
479    if ($cleanup) {
480        $text =~ s/\\/\\e/g;
481        $text =~ s/-/\\-/g;
482        $text =~ s/_(?=_)/_\\|/g;
483        $text =~ s/\x{200B}/\\:/g;
484    }
485
486    # Except in <Data> blocks, if groff or roff encoding is requested and
487    # we're in an ASCII environment, do the encoding.  For EBCDIC, we just
488    # write what we get and hope for the best.  Leave non-breaking spaces and
489    # soft hyphens alone; we'll convert those at the last minute.
490    if ($convert) {
491        if (ASCII) {
492            if ($$self{ENCODING} eq 'groff') {
493                $text =~ s{ ([^\x00-\x7F\xA0\xAD]) }{
494                    '\\[u' . sprintf('%04X', ord($1)) . ']'
495                }xmsge;
496            } elsif ($$self{ENCODING} eq 'roff') {
497                $text =~ s/([^\x00-\x7F\xA0\xAD])/$ESCAPES{ord ($1)} || "X"/eg;
498            }
499        }
500    }
501
502    # Ensure that *roff doesn't convert literal quotes to UTF-8 single quotes,
503    # but don't mess up accent escapes.
504    if ($literal) {
505        $text =~ s/(?<!\\\*)\'/\\*\(Aq/g;
506        $text =~ s/(?<!\\\*)\`/\\\`/g;
507    }
508
509    # If guesswork is is viable for this block, do that.
510    if ($guesswork) {
511        $text = $self->guesswork ($text);
512    }
513
514    return $text;
515}
516
517# Handles C<> text, deciding whether to put \*C` around it or not.  This is a
518# whole bunch of messy heuristics to try to avoid overquoting, originally from
519# Barrie Slaymaker.  This largely duplicates similar code in Pod::Text.
520sub quote_literal {
521    my $self = shift;
522    local $_ = shift;
523
524    # If in NAME section, just return an ASCII quoted string to avoid
525    # confusing tools like whatis.
526    if ($$self{IN_NAME}) {
527        return $self->{LQUOTE} . $_ . $self->{RQUOTE};
528    }
529
530    # A regex that matches the portion of a variable reference that's the
531    # array or hash index, separated out just because we want to use it in
532    # several places in the following regex.
533    my $index = '(?: \[[^]]+\] | \{[^}]+\} )?';
534
535    # Check for things that we don't want to quote, and if we find any of
536    # them, return the string with just a font change and no quoting.
537    #
538    # Traditionally, Pod::Man has not quoted Perl variables, functions,
539    # numbers, or hex constants, but this is not always desirable.  Make this
540    # optional on the quoting guesswork flag.
541    my $extra = qr{(?!)}xms;    # never matches
542    if ($$self{GUESSWORK}{quoting}) {
543        $extra = qr{
544             \$+ [\#^]? \S $index                    # special ($^F, $")
545           | [\$\@%&*]+ \#? [:\'\w]+ $index          # plain var or func
546           | [\$\@%&*]* [:\'\w]+
547             (?: \\-> )? \(\s*[^\s,\)]*\s*\)         # 0/1-arg func call
548           | (?: [+] || \\- )? ( \d[\d.]* | \.\d+ )
549             (?: [eE] (?: [+] || \\- )? \d+ )?       # a number
550           | 0x [a-fA-F\d]+                          # a hex constant
551         }xms;
552    }
553    m{
554      ^\s*
555      (?:
556         ( [\'\"] ) .* \1                    # already quoted
557       | \\\*\(Aq .* \\\*\(Aq                # quoted and escaped
558       | \\?\` .* ( \' | \\?\` | \\\*\(Aq )  # `quoted' or `quoted`
559       | $extra
560      )
561      \s*\z
562     }xms and return '\f(FS' . $_ . '\f(FE';
563
564    # If we didn't return, go ahead and quote the text.
565    return '\f(FS\*(C`' . $_ . "\\*(C'\\f(FE";
566}
567
568# Takes a text block to perform guesswork on.  Returns the text block with
569# formatting codes added.  This is the code that marks up various Perl
570# constructs and things commonly used in man pages without requiring the user
571# to add any explicit markup, and is applied to all non-literal text.  Note
572# that the inserted font sequences must be treated later with mapfonts.
573#
574# This method is very fragile, both in the regular expressions it uses and in
575# the ordering of those modifications.  Care and testing is required when
576# modifying it.
577sub guesswork {
578    my $self = shift;
579    local $_ = shift;
580
581    # By the time we reach this point, all hyphens will be escaped by adding a
582    # backslash.  We want to undo that escaping if they're part of regular
583    # words and there's only a single dash, since that's a real hyphen that
584    # *roff gets to consider a possible break point.  Make sure that a dash
585    # after the first character of a word stays non-breaking, however.
586    #
587    # Note that this is not user-controllable; we pretty much have to do this
588    # transformation or *roff will mangle the output in unacceptable ways.
589    s{
590        ( (?:\G|^|\s|$NBSP) [\(\"]* [a-zA-Z] ) ( \\- )?
591        ( (?: [a-zA-Z\']+ \\-)+ )
592        ( [a-zA-Z\']+ ) (?= [\)\".?!,;:]* (?:\s|$NBSP|\Z|\\\ ) )
593        \b
594    } {
595        my ($prefix, $hyphen, $main, $suffix) = ($1, $2, $3, $4);
596        $hyphen ||= '';
597        $main =~ s/\\-/-/g;
598        $prefix . $hyphen . $main . $suffix;
599    }egx;
600
601    # Embolden functions in the form func(), including functions that are in
602    # all capitals, but don't embolden if there's anything inside the parens.
603    # The function must start with an alphabetic character or underscore and
604    # then consist of word characters or colons.
605    if ($$self{GUESSWORK}{functions}) {
606        s{
607            (?<! \\ )
608            \b
609            ( [A-Za-z_] [:\w]+ \(\) )
610        } {
611            '\f(BS' . $1 . '\f(BE'
612        }egx;
613    }
614
615    # Change references to manual pages to put the page name in bold but
616    # the number in the regular font, with a thin space between the name and
617    # the number.  Only recognize func(n) where func starts with an alphabetic
618    # character or underscore and contains only word characters, periods (for
619    # configuration file man pages), or colons, and n is a single digit,
620    # optionally followed by some number of lowercase letters.  Note that this
621    # does not recognize man page references like perl(l) or socket(3SOCKET).
622    if ($$self{GUESSWORK}{manref}) {
623        s{
624            \b
625            (?<! \\ )                                   # rule out \e0(1)
626            ( [A-Za-z_] (?:[.:\w] | \\-)+ )
627            ( \( \d [a-z]* \) )
628        } {
629            '\f(BS' . $1 . '\f(BE\|' . $2
630        }egx;
631    }
632
633    # Convert simple Perl variable references to a fixed-width font.  Be
634    # careful not to convert functions, though; there are too many subtleties
635    # with them to want to perform this transformation.
636    if ($$self{GUESSWORK}{variables}) {
637        s{
638           ( ^ | \s+ )
639           ( [\$\@%] [\w:]+ )
640           (?! \( )
641        } {
642            $1 . '\f(FS' . $2 . '\f(FE'
643        }egx;
644    }
645
646    # Done.
647    return $_;
648}
649
650##############################################################################
651# Output
652##############################################################################
653
654# When building up the *roff code, we don't use real *roff fonts.  Instead, we
655# embed font codes of the form \f(<font>[SE] where <font> is one of B, I, or
656# F, S stands for start, and E stands for end.  This method turns these into
657# the right start and end codes.
658#
659# We add this level of complexity because the old pod2man didn't get code like
660# B<< someI<thing> else>> right.  After I<> it switched back to normal text
661# rather than bold.  We take care of this by using variables that state
662# whether bold, italic, or fixed are turned on as a combined pointer to our
663# current font sequence, and set each to the number of current nestings of
664# start tags for that font.
665#
666# The base font must be either \fP or \fR.  \fP changes to the previous font,
667# but only one previous font is kept.  Unfortunately, there is a bug in
668# Solaris 2.6 nroff (not present in GNU groff) where the sequence
669# \fB\fP\f(CW\fP leaves the font set to B rather than R, presumably because
670# \f(CW doesn't actually do a font change.  Because of this, we prefer to use
671# \fR where possible.
672#
673# Unfortunately, this isn't possible for arguments to heading macros, since
674# there we don't know what the outside level font is.  In that case, arrange
675# things so that the outside font is always the "previous" font and end with
676# \fP instead of \fR.  Idea from Zack Weinberg.
677#
678# This function used to be much simpler outside of macro arguments because it
679# went directly from \fB to \f(CW and relied on \f(CW clearing bold since it
680# wasn't \f(CB.  Unfortunately, while this works for mandoc, this is not how
681# groff works; \fBfoo\f(CWbar still prints bar in bold.  Therefore, we force
682# the font back to the base font before each font change.
683sub mapfonts {
684    my ($self, $text, $base) = @_;
685
686    # The closure used to process each font escape, expected to be called from
687    # the right-hand side of an s/// expression.
688    my ($fixed, $bold, $italic) = (0, 0, 0);
689    my %magic = (F => \$fixed, B => \$bold, I => \$italic);
690    my $last = '\fR';
691    my $process = sub {
692        my ($style, $start_stop) = @_;
693        my $sequence = ($last ne '\fR') ? $base : q{};
694        ${ $magic{$style} } += ($start_stop eq 'S') ? 1 : -1;
695        my $f = $self->{FONTS}{($fixed && 1) . ($bold && 1) . ($italic && 1)};
696        return q{} if ($f eq $last);
697        if ($f ne '\fR') {
698            $sequence .= $f;
699        }
700        $last = $f;
701        return $sequence;
702    };
703
704    # Now, do the actual work.
705    $text =~ s{ \\f\((.)(.) }{$process->($1, $2)}xmsge;
706
707    # We can do a bit of cleanup by collapsing sequences like \fR\fB\fR\fI
708    # into just \fI.
709    $text =~ s{ (?: \\fR )? (?: \\f (.|\(..) \\fR )+ }{\\fR}xms;
710
711    return $text;
712}
713
714# Given a command and a single argument that may or may not contain double
715# quotes and fixed-width text, handle double-quote formatting for it.  If
716# there is no fixed-width text, just return the command followed by the
717# argument with proper quoting.  If there is fixed-width text, work around a
718# Solaris nroff bug with fixed-width fonts by converting fixed-width to
719# regular fonts (nroff sees no difference).
720sub switchquotes {
721    my ($self, $command, $text, $extra) = @_;
722
723    # Separate troff from nroff if there are any fixed-width fonts in use to
724    # work around problems with Solaris nroff.
725    if ($text =~ $self->{FIXEDPAT}) {
726        my $nroff = $text;
727        my $troff = $text;
728
729        # Work around the Solaris nroff bug where \f(CW\fP leaves the font set
730        # to Roman rather than the actual previous font when used in headings.
731        # troff output may still be broken, but at least we can fix nroff by
732        # just switching the font changes to the non-fixed versions.
733        my $font_end = qr{ (?: \\f[PR] | \Q$self->{FONTS}{100}\E ) }xms;
734        $nroff =~ s{\Q$self->{FONTS}{100}\E(.*?)\\f([PR])}{$1}xmsg;
735        $nroff =~ s{\Q$self->{FONTS}{101}\E}{\\fI}xmsg;
736        $nroff =~ s{\Q$self->{FONTS}{110}\E}{\\fB}xmsg;
737        $nroff =~ s{\Q$self->{FONTS}{111}\E}{\\f\(BI}xmsg;
738
739        # We have to deal with \*C` and \*C', which are used to add the quotes
740        # around C<> text, since they may expand to " and if they do this
741        # confuses the .SH macros and the like no end.  Expand them ourselves.
742        my $c_is_quote = index("$self->{LQUOTE}$self->{RQUOTE}", qq(\")) != -1;
743        if ($c_is_quote && $text =~ m{ \\[*]\(C[\'\`] }xms) {
744            $nroff =~ s{ \\[*]\(C\` }{$self->{LQUOTE}}xmsg;
745            $nroff =~ s{ \\[*]\(C\' }{$self->{RQUOTE}}xmsg;
746            $troff =~ s{ \\[*]\(C[\'\`] }{}xmsg;
747        }
748
749        # Now finally output the command.  Bother with .ie only if the nroff
750        # and troff output aren't the same.
751        $nroff = _quote_macro_argument($nroff) . ($extra ? " $extra" : '');
752        $troff = _quote_macro_argument($troff) . ($extra ? " $extra" : '');
753        if ($nroff ne $troff) {
754            return ".ie n $command $nroff\n.el $command $troff\n";
755        } else {
756            return "$command $nroff\n";
757        }
758    } else {
759        $text = _quote_macro_argument($text) . ($extra ? " $extra" : '');
760        return "$command $text\n";
761    }
762}
763
764# Protect leading quotes and periods against interpretation as commands.  Also
765# protect anything starting with a backslash, since it could expand or hide
766# something that *roff would interpret as a command.  This is overkill, but
767# it's much simpler than trying to parse *roff here.
768sub protect {
769    my ($self, $text) = @_;
770    $text =~ s/^([.\'\\])/\\&$1/mg;
771    return $text;
772}
773
774# Make vertical whitespace if NEEDSPACE is set, appropriate to the indentation
775# level the situation.  This function is needed since in *roff one has to
776# create vertical whitespace after paragraphs and between some things, but
777# other macros create their own whitespace.  Also close out a sequence of
778# repeated =items, since calling makespace means we're about to begin the item
779# body.
780sub makespace {
781    my ($self) = @_;
782    $self->output (".PD\n") if $$self{ITEMS} > 1;
783    $$self{ITEMS} = 0;
784    $self->output ($$self{INDENT} > 0 ? ".Sp\n" : ".PP\n")
785        if $$self{NEEDSPACE};
786}
787
788# Output any pending index entries, and optionally an index entry given as an
789# argument.  Support multiple index entries in X<> separated by slashes, and
790# strip special escapes from index entries.
791sub outindex {
792    my ($self, $section, $index) = @_;
793    my @entries = map { split m%\s*/\s*% } @{ $$self{INDEX} };
794    return unless ($section || @entries);
795
796    # We're about to output all pending entries, so clear our pending queue.
797    $$self{INDEX} = [];
798
799    # Build the output.  Regular index entries are marked Xref, and headings
800    # pass in their own section.  Undo some *roff formatting on headings.
801    my @output;
802    if (@entries) {
803        push @output, [ 'Xref', join (' ', @entries) ];
804    }
805    if ($section) {
806        $index =~ s/\\-/-/g;
807        $index =~ s/\\(?:s-?\d|.\(..|.)//g;
808        push @output, [ $section, $index ];
809    }
810
811    # Print out the .IX commands.
812    for (@output) {
813        my ($type, $entry) = @$_;
814        $entry =~ s/\s+/ /g;
815        $entry =~ s/\"/\"\"/g;
816        $entry =~ s/\\/\\\\/g;
817        $self->output (".IX $type " . '"' . $entry . '"' . "\n");
818    }
819}
820
821# Output some text, without any additional changes.
822sub output {
823    my ($self, @text) = @_;
824    my $text = join('', @text);
825    $text =~ s{$NBSP}{\\ }g;
826    $text =~ s{$SHY}{\\%}g;
827
828    if ($$self{ENCODE} && _needs_encode($$self{ENCODING})) {
829        my $check = sub {
830            my ($char) = @_;
831            my $display = '"\x{' . hex($char) . '}"';
832            my $error = "$display does not map to $$self{ENCODING}";
833            $self->whine ($self->line_count(), $error);
834            return Encode::encode ($$self{ENCODING}, chr($char));
835        };
836        my $output = Encode::encode ($$self{ENCODING}, $text, $check);
837        print { $$self{output_fh} } $output;
838    } else {
839        print { $$self{output_fh} } $text;
840    }
841}
842
843##############################################################################
844# Document initialization
845##############################################################################
846
847# Handle the start of the document.  Here we handle empty documents, as well
848# as setting up our basic macros in a preamble and building the page title.
849sub start_document {
850    my ($self, $attrs) = @_;
851    if ($$attrs{contentless} && !$$self{ALWAYS_EMIT_SOMETHING}) {
852        $$self{CONTENTLESS} = 1;
853    } else {
854        delete $$self{CONTENTLESS};
855    }
856
857    # When an encoding is requested, check whether our output file handle
858    # already has a PerlIO encoding layer set.  If it does not, we'll need to
859    # encode our output before printing it (handled in the output() sub).
860    # Wrap the check in an eval to handle versions of Perl without PerlIO.
861    #
862    # PerlIO::get_layers still requires its argument be a glob, so coerce the
863    # file handle to a glob.
864    $$self{ENCODE} = 0;
865    if ($$self{ENCODING}) {
866        $$self{ENCODE} = 1;
867        eval {
868            my @options = (output => 1, details => 1);
869            my @layers = PerlIO::get_layers (*{$$self{output_fh}}, @options);
870            if ($layers[-1] && ($layers[-1] & PerlIO::F_UTF8 ())) {
871                $$self{ENCODE} = 0;
872            }
873        }
874    }
875
876    # Determine information for the preamble and then output it unless the
877    # document was content-free.
878    if (!$$self{CONTENTLESS}) {
879        my ($name, $section);
880        if (defined $self->{opt_name}) {
881            $name = $self->{opt_name};
882            $section = $self->{opt_section} || 1;
883        } else {
884            ($name, $section) = $self->devise_title;
885        }
886        my $date = $self->{opt_date} // $self->devise_date();
887        $self->preamble ($name, $section, $date)
888            unless $self->bare_output;
889    }
890
891    # Initialize a few per-document variables.
892    $$self{INDENT}    = 0;      # Current indentation level.
893    $$self{INDENTS}   = [];     # Stack of indentations.
894    $$self{INDEX}     = [];     # Index keys waiting to be printed.
895    $$self{IN_NAME}   = 0;      # Whether processing the NAME section.
896    $$self{ITEMS}     = 0;      # The number of consecutive =items.
897    $$self{ITEMTYPES} = [];     # Stack of =item types, one per list.
898    $$self{SHIFTWAIT} = 0;      # Whether there is a shift waiting.
899    $$self{SHIFTS}    = [];     # Stack of .RS shifts.
900    $$self{PENDING}   = [[]];   # Pending output.
901}
902
903# Handle the end of the document.  This handles dying on POD errors, since
904# Pod::Parser currently doesn't.  Otherwise, does nothing but print out a
905# final comment at the end of the document under debugging.
906sub end_document {
907    my ($self) = @_;
908    if ($$self{complain_die} && $self->errors_seen) {
909        croak ("POD document had syntax errors");
910    }
911    return if $self->bare_output;
912    return if ($$self{CONTENTLESS} && !$$self{ALWAYS_EMIT_SOMETHING});
913}
914
915# Try to figure out the name and section from the file name and return them as
916# a list, returning an empty name and section 1 if we can't find any better
917# information.  Uses File::Basename and File::Spec as necessary.
918sub devise_title {
919    my ($self) = @_;
920    my $name = $self->source_filename || '';
921    my $section = $self->{opt_section} || 1;
922    $section = 3 if (!$self->{opt_section} && $name =~ /\.pm\z/i);
923    $name =~ s/\.p(od|[lm])\z//i;
924
925    # If Pod::Parser gave us an IO::File reference as the source file name,
926    # convert that to the empty string as well.  Then, if we don't have a
927    # valid name, convert it to STDIN.
928    #
929    # In podlators 4.00 through 4.07, this also produced a warning, but that
930    # was surprising to a lot of programs that had expected to be able to pipe
931    # POD through pod2man without specifying the name.  In the name of
932    # backward compatibility, just quietly set STDIN as the page title.
933    if ($name =~ /^IO::File(?:=\w+)\(0x[\da-f]+\)$/i) {
934        $name = '';
935    }
936    if ($name eq '') {
937        $name = 'STDIN';
938    }
939
940    # If the section isn't 3, then the name defaults to just the basename of
941    # the file.
942    if ($section !~ /^3/) {
943        require File::Basename;
944        $name = uc File::Basename::basename ($name);
945    } else {
946        require File::Spec;
947        my ($volume, $dirs, $file) = File::Spec->splitpath ($name);
948
949        # Otherwise, assume we're dealing with a module.  We want to figure
950        # out the full module name from the path to the file, but we don't
951        # want to include too much of the path into the module name.  Lose
952        # anything up to the first of:
953        #
954        #     */lib/*perl*/         standard or site_perl module
955        #     */*perl*/lib/         from -Dprefix=/opt/perl
956        #     */*perl*/             random module hierarchy
957        #
958        # Also strip off a leading site, site_perl, or vendor_perl component,
959        # any OS-specific component, and any version number component, and
960        # strip off an initial component of "lib" or "blib/lib" since that's
961        # what ExtUtils::MakeMaker creates.
962        #
963        # splitdir requires at least File::Spec 0.8.
964        my @dirs = File::Spec->splitdir ($dirs);
965        if (@dirs) {
966            my $cut = 0;
967            my $i;
968            for ($i = 0; $i < @dirs; $i++) {
969                if ($dirs[$i] =~ /perl/) {
970                    $cut = $i + 1;
971                    $cut++ if ($dirs[$i + 1] && $dirs[$i + 1] eq 'lib');
972                    last;
973                } elsif ($dirs[$i] eq 'lib' && $dirs[$i + 1] && $dirs[0] eq 'ext') {
974                    $cut = $i + 1;
975                }
976            }
977            if ($cut > 0) {
978                splice (@dirs, 0, $cut);
979                shift @dirs if ($dirs[0] =~ /^(site|vendor)(_perl)?$/);
980                shift @dirs if ($dirs[0] =~ /^[\d.]+$/);
981                shift @dirs if ($dirs[0] =~ /^(.*-$^O|$^O-.*|$^O)$/);
982            }
983            shift @dirs if $dirs[0] eq 'lib';
984            splice (@dirs, 0, 2) if ($dirs[0] eq 'blib' && $dirs[1] eq 'lib');
985        }
986
987        # Remove empty directories when building the module name; they
988        # occur too easily on Unix by doubling slashes.
989        $name = join ('::', (grep { $_ ? $_ : () } @dirs), $file);
990    }
991    return ($name, $section);
992}
993
994# Determine the modification date and return that, properly formatted in ISO
995# format.
996#
997# If POD_MAN_DATE is set, that overrides anything else.  This can be used for
998# reproducible generation of the same file even if the input file timestamps
999# are unpredictable or the POD comes from standard input.
1000#
1001# Otherwise, if SOURCE_DATE_EPOCH is set and can be parsed as seconds since
1002# the UNIX epoch, base the timestamp on that.  See
1003# <https://reproducible-builds.org/specs/source-date-epoch/>
1004#
1005# Otherwise, use the modification date of the input if we can stat it.  Be
1006# aware that Pod::Simple returns the stringification of the file handle as
1007# source_filename for input from a file handle, so we'll stat some random ref
1008# string in that case.  If that fails, instead use the current time.
1009#
1010# $self - Pod::Man object, used to get the source file
1011#
1012# Returns: YYYY-MM-DD date suitable for the left-hand footer
1013sub devise_date {
1014    my ($self) = @_;
1015
1016    # If POD_MAN_DATE is set, always use it.
1017    if (defined($ENV{POD_MAN_DATE})) {
1018        return $ENV{POD_MAN_DATE};
1019    }
1020
1021    # If SOURCE_DATE_EPOCH is set and can be parsed, use that.
1022    my $time;
1023    if (defined($ENV{SOURCE_DATE_EPOCH}) && $ENV{SOURCE_DATE_EPOCH} !~ /\D/) {
1024        $time = $ENV{SOURCE_DATE_EPOCH};
1025    }
1026
1027    # Otherwise, get the input filename and try to stat it.  If that fails,
1028    # use the current time.
1029    if (!defined $time) {
1030        my $input = $self->source_filename;
1031        if ($input) {
1032            $time = (stat($input))[9] || time();
1033        } else {
1034            $time = time();
1035        }
1036    }
1037
1038    # Can't use POSIX::strftime(), which uses Fcntl, because MakeMaker uses
1039    # this and it has to work in the core which can't load dynamic libraries.
1040    # Use gmtime instead of localtime so that the generated man page does not
1041    # depend on the local time zone setting and is more reproducible
1042    my ($year, $month, $day) = (gmtime($time))[5,4,3];
1043    return sprintf("%04d-%02d-%02d", $year + 1900, $month + 1, $day);
1044}
1045
1046# Print out the preamble and the title.  The meaning of the arguments to .TH
1047# unfortunately vary by system; some systems consider the fourth argument to
1048# be a "source" and others use it as a version number.  Generally it's just
1049# presented as the left-side footer, though, so it doesn't matter too much if
1050# a particular system gives it another interpretation.
1051#
1052# The order of date and release used to be reversed in older versions of this
1053# module, but this order is correct for both Solaris and Linux.
1054sub preamble {
1055    my ($self, $name, $section, $date) = @_;
1056    my $preamble = $self->preamble_template();
1057
1058    # groff's preconv script will use this line to correctly determine the
1059    # input encoding if the encoding is one of the ones it recognizes.  It
1060    # must be the first or second line.
1061    #
1062    # If the output encoding is some version of Unicode, we could also add a
1063    # Unicode Byte Order Mark to the start of the file, but the BOM is now
1064    # deprecated and I am concerned that may break a *roff implementation that
1065    # might otherwise cope with Unicode.  Revisit this if someone files a bug
1066    # report about it.
1067    if (_needs_encode($$self{ENCODING})) {
1068        my $normalized = lc($$self{ENCODING});
1069        $normalized =~ s{-}{}g;
1070        my $coding = $ENCODINGS{$normalized} || lc($$self{ENCODING});
1071        if ($coding ne 'us-ascii') {
1072            $self->output(qq{.\\\" -*- mode: troff; coding: $coding -*-\n});
1073        }
1074    }
1075
1076    # Substitute into the preamble the configuration options.  Because it's
1077    # used as the argument to defining a string, any leading double quote (but
1078    # no other double quotes) in LQUOTE and RQUOTE has to be doubled.
1079    $preamble =~ s{ [@] CFONT [@] }{$self->{opt_fixed}}xms;
1080    my $lquote = $self->{LQUOTE};
1081    my $rquote = $self->{RQUOTE};
1082    $lquote =~ s{ \A \" }{""}xms;
1083    $rquote =~ s{ \A \" }{""}xms;
1084    $preamble =~ s{ [@] LQUOTE [@] }{$lquote}xms;
1085    $preamble =~ s{ [@] RQUOTE [@] }{$rquote}xms;
1086    chomp($preamble);
1087
1088    # Get the version information.
1089    my $version = $self->version_report();
1090
1091    # Build the index line and make sure that it will be syntactically valid.
1092    my $index = _quote_macro_argument("$name $section");
1093
1094    # Quote the arguments to the .TH macro.  (Section should never require
1095    # this, but we may as well be cautious.)
1096    $name = _quote_macro_argument($name);
1097    $section = _quote_macro_argument($section);
1098    $date = _quote_macro_argument($date);
1099    my $center = _quote_macro_argument($self->{opt_center});
1100    my $release = _quote_macro_argument($self->{opt_release});
1101
1102    # Output the majority of the preamble.
1103    $self->output (<<"----END OF HEADER----");
1104.\\" Automatically generated by $version
1105.\\"
1106.\\" Standard preamble:
1107.\\" ========================================================================
1108$preamble
1109.\\" ========================================================================
1110.\\"
1111.IX Title $index
1112.TH $name $section $date $release $center
1113.\\" For nroff, turn off justification.  Always turn off hyphenation; it makes
1114.\\" way too many mistakes in technical documents.
1115.if n .ad l
1116.nh
1117----END OF HEADER----
1118
1119    # If the language was specified, output the language configuration.
1120    if ($self->{opt_language}) {
1121        $self->output(".mso $self->{opt_language}.tmac\n");
1122        $self->output(".hla $self->{opt_language}\n");
1123    }
1124}
1125
1126##############################################################################
1127# Text blocks
1128##############################################################################
1129
1130# Handle a basic block of text.  The only tricky part of this is if this is
1131# the first paragraph of text after an =over, in which case we have to change
1132# indentations for *roff.
1133sub cmd_para {
1134    my ($self, $attrs, $text) = @_;
1135    my $line = $$attrs{start_line};
1136
1137    # Output the paragraph.  We also have to handle =over without =item.  If
1138    # there's an =over without =item, SHIFTWAIT will be set, and we need to
1139    # handle creation of the indent here.  Add the shift to SHIFTS so that it
1140    # will be cleaned up on =back.
1141    $self->makespace;
1142    if ($$self{SHIFTWAIT}) {
1143        $self->output (".RS $$self{INDENT}\n");
1144        push (@{ $$self{SHIFTS} }, $$self{INDENT});
1145        $$self{SHIFTWAIT} = 0;
1146    }
1147
1148    # Force exactly one newline at the end and strip unwanted trailing
1149    # whitespace at the end, but leave "\ " backslashed space from an S< > at
1150    # the end of a line.  Reverse the text first, to avoid having to scan the
1151    # entire paragraph.
1152    $text = reverse $text;
1153    $text =~ s/\A\s*?(?= \\|\S|\z)/\n/;
1154    $text = reverse $text;
1155
1156    # Output the paragraph.
1157    $self->output($self->protect($self->mapfonts($text, '\fR')));
1158    $self->outindex();
1159    $$self{NEEDSPACE} = 1;
1160    return '';
1161}
1162
1163# Handle a verbatim paragraph.  Put a null token at the beginning of each line
1164# to protect against commands and wrap in .Vb/.Ve (which we define in our
1165# prelude).
1166sub cmd_verbatim {
1167    my ($self, $attrs, $text) = @_;
1168
1169    # Ignore an empty verbatim paragraph.
1170    return if $text !~ m{ \S }xms;
1171
1172    # Force exactly one newline at the end and strip unwanted trailing
1173    # whitespace at the end.
1174    $text =~ s{ \s* \z }{\n}xms;
1175
1176    # Get a count of the number of lines before the first blank line, which
1177    # we'll pass to .Vb as its parameter.  This tells *roff to keep that many
1178    # lines together.  We don't want to tell *roff to keep huge blocks
1179    # together.
1180    my @lines = split (m{ \n }xms, $text);
1181    my $unbroken = 0;
1182    for my $line (@lines) {
1183        last if $line =~ m{ \A \s* \z }xms;
1184        $unbroken++;
1185    }
1186    if ($unbroken > 12) {
1187        $unbroken = 10;
1188    }
1189
1190    # Prepend a null token to each line to preserve indentation.
1191    $text =~ s{ ^ }{\\&}xmsg;
1192
1193    # Output the results.
1194    $self->makespace();
1195    $self->output(".Vb $unbroken\n$text.Ve\n");
1196    $$self{NEEDSPACE} = 1;
1197    return q{};
1198}
1199
1200# Handle literal text (produced by =for and similar constructs).  Just output
1201# it with the minimum of changes.
1202sub cmd_data {
1203    my ($self, $attrs, $text) = @_;
1204    $text =~ s{ \A \n+ }{}xms;
1205    $text =~ s{ \n{0,2} \z }{\n}xms;
1206    $self->output($text);
1207    return q{};
1208}
1209
1210##############################################################################
1211# Headings
1212##############################################################################
1213
1214# Common code for all headings.  This is called before the actual heading is
1215# output.  It returns the cleaned up heading text (putting the heading all on
1216# one line) and may do other things, like closing bad =item blocks.
1217sub heading_common {
1218    my ($self, $text, $line) = @_;
1219    $text =~ s/\s+$//;
1220    $text =~ s/\s*\n\s*/ /g;
1221
1222    # This should never happen; it means that we have a heading after =item
1223    # without an intervening =back.  But just in case, handle it anyway.
1224    if ($$self{ITEMS} > 1) {
1225        $$self{ITEMS} = 0;
1226        $self->output (".PD\n");
1227    }
1228
1229    return $text;
1230}
1231
1232# First level heading.  We can't output .IX in the NAME section due to a bug
1233# in some versions of catman, so don't output a .IX for that section.  .SH
1234# already uses small caps, so remove \s0 and \s-1.  Maintain IN_NAME as
1235# appropriate.
1236sub cmd_head1 {
1237    my ($self, $attrs, $text) = @_;
1238    $text =~ s/\\s-?\d//g;
1239    $text = $self->heading_common ($text, $$attrs{start_line});
1240    my $isname = ($text eq 'NAME' || $text =~ /\(NAME\)/);
1241    $self->output($self->switchquotes('.SH', $self->mapfonts($text, '\fP')));
1242    $self->outindex ('Header', $text) unless $isname;
1243    $$self{NEEDSPACE} = 0;
1244    $$self{IN_NAME} = $isname;
1245    return '';
1246}
1247
1248# Second level heading.
1249sub cmd_head2 {
1250    my ($self, $attrs, $text) = @_;
1251    $text = $self->heading_common ($text, $$attrs{start_line});
1252    $self->output($self->switchquotes('.SS', $self->mapfonts($text, '\fP')));
1253    $self->outindex ('Subsection', $text);
1254    $$self{NEEDSPACE} = 0;
1255    return '';
1256}
1257
1258# Third level heading.  *roff doesn't have this concept, so just put the
1259# heading in italics as a normal paragraph.
1260sub cmd_head3 {
1261    my ($self, $attrs, $text) = @_;
1262    $text = $self->heading_common ($text, $$attrs{start_line});
1263    $self->makespace;
1264    $self->output($self->mapfonts('\f(IS' . $text . '\f(IE', '\fR') . "\n");
1265    $self->outindex ('Subsection', $text);
1266    $$self{NEEDSPACE} = 1;
1267    return '';
1268}
1269
1270# Fourth level heading.  *roff doesn't have this concept, so just put the
1271# heading as a normal paragraph.
1272sub cmd_head4 {
1273    my ($self, $attrs, $text) = @_;
1274    $text = $self->heading_common ($text, $$attrs{start_line});
1275    $self->makespace;
1276    $self->output($self->mapfonts($text, '\fR') . "\n");
1277    $self->outindex ('Subsection', $text);
1278    $$self{NEEDSPACE} = 1;
1279    return '';
1280}
1281
1282##############################################################################
1283# Formatting codes
1284##############################################################################
1285
1286# All of the formatting codes that aren't handled internally by the parser,
1287# other than L<> and X<>.
1288sub cmd_b { return $_[0]->{IN_NAME} ? $_[2] : '\f(BS' . $_[2] . '\f(BE' }
1289sub cmd_i { return $_[0]->{IN_NAME} ? $_[2] : '\f(IS' . $_[2] . '\f(IE' }
1290sub cmd_f { return $_[0]->{IN_NAME} ? $_[2] : '\f(IS' . $_[2] . '\f(IE' }
1291sub cmd_c { return $_[0]->quote_literal ($_[2]) }
1292
1293# Convert all internal whitespace to $NBSP.
1294sub cmd_s {
1295    my ($self, $attrs, $text) = @_;
1296    $text =~ s{ \s }{$NBSP}xmsg;
1297    return $text;
1298}
1299
1300# Index entries are just added to the pending entries.
1301sub cmd_x {
1302    my ($self, $attrs, $text) = @_;
1303    push (@{ $$self{INDEX} }, $text);
1304    return '';
1305}
1306
1307# Links reduce to the text that we're given, wrapped in angle brackets if it's
1308# a URL, followed by the URL.  We take an option to suppress the URL if anchor
1309# text is given.  We need to format the "to" value of the link before
1310# comparing it to the text since we may escape hyphens.
1311sub cmd_l {
1312    my ($self, $attrs, $text) = @_;
1313    if ($$attrs{type} eq 'url') {
1314        my $to = $$attrs{to};
1315        if (defined $to) {
1316            my $tag = $$self{PENDING}[-1];
1317            $to = $self->format_text ($$tag[1], $to);
1318        }
1319        if (not defined ($to) or $to eq $text) {
1320            return "<$text>";
1321        } elsif ($self->{opt_nourls}) {
1322            return $text;
1323        } else {
1324            return "$text <$$attrs{to}>";
1325        }
1326    } else {
1327        return $text;
1328    }
1329}
1330
1331##############################################################################
1332# List handling
1333##############################################################################
1334
1335# Handle the beginning of an =over block.  Takes the type of the block as the
1336# first argument, and then the attr hash.  This is called by the handlers for
1337# the four different types of lists (bullet, number, text, and block).
1338sub over_common_start {
1339    my ($self, $type, $attrs) = @_;
1340    my $line = $$attrs{start_line};
1341    my $indent = $$attrs{indent};
1342
1343    # Find the indentation level.
1344    unless (defined ($indent) && $indent =~ /^[-+]?\d{1,4}\s*$/) {
1345        $indent = $self->{opt_indent};
1346    }
1347
1348    # If we've gotten multiple indentations in a row, we need to emit the
1349    # pending indentation for the last level that we saw and haven't acted on
1350    # yet.  SHIFTS is the stack of indentations that we've actually emitted
1351    # code for.
1352    if (@{ $$self{SHIFTS} } < @{ $$self{INDENTS} }) {
1353        $self->output (".RS $$self{INDENT}\n");
1354        push (@{ $$self{SHIFTS} }, $$self{INDENT});
1355    }
1356
1357    # Now, do record-keeping.  INDENTS is a stack of indentations that we've
1358    # seen so far, and INDENT is the current level of indentation.  ITEMTYPES
1359    # is a stack of list types that we've seen.
1360    push (@{ $$self{INDENTS} }, $$self{INDENT});
1361    push (@{ $$self{ITEMTYPES} }, $type);
1362    $$self{INDENT} = $indent + 0;
1363    $$self{SHIFTWAIT} = 1;
1364}
1365
1366# End an =over block.  Takes no options other than the class pointer.
1367# Normally, once we close a block and therefore remove something from INDENTS,
1368# INDENTS will now be longer than SHIFTS, indicating that we also need to emit
1369# *roff code to close the indent.  This isn't *always* true, depending on the
1370# circumstance.  If we're still inside an indentation, we need to emit another
1371# .RE and then a new .RS to unconfuse *roff.
1372sub over_common_end {
1373    my ($self) = @_;
1374    $$self{INDENT} = pop @{ $$self{INDENTS} };
1375    pop @{ $$self{ITEMTYPES} };
1376
1377    # If we emitted code for that indentation, end it.
1378    if (@{ $$self{SHIFTS} } > @{ $$self{INDENTS} }) {
1379        $self->output (".RE\n");
1380        pop @{ $$self{SHIFTS} };
1381    }
1382
1383    # If we're still in an indentation, *roff will have now lost track of the
1384    # right depth of that indentation, so fix that.
1385    if (@{ $$self{INDENTS} } > 0) {
1386        $self->output (".RE\n");
1387        $self->output (".RS $$self{INDENT}\n");
1388    }
1389    $$self{NEEDSPACE} = 1;
1390    $$self{SHIFTWAIT} = 0;
1391}
1392
1393# Dispatch the start and end calls as appropriate.
1394sub start_over_bullet { my $s = shift; $s->over_common_start ('bullet', @_) }
1395sub start_over_number { my $s = shift; $s->over_common_start ('number', @_) }
1396sub start_over_text   { my $s = shift; $s->over_common_start ('text',   @_) }
1397sub start_over_block  { my $s = shift; $s->over_common_start ('block',  @_) }
1398sub end_over_bullet { $_[0]->over_common_end }
1399sub end_over_number { $_[0]->over_common_end }
1400sub end_over_text   { $_[0]->over_common_end }
1401sub end_over_block  { $_[0]->over_common_end }
1402
1403# The common handler for all item commands.  Takes the type of the item, the
1404# attributes, and then the text of the item.
1405#
1406# Emit an index entry for anything that's interesting, but don't emit index
1407# entries for things like bullets and numbers.  Newlines in an item title are
1408# turned into spaces since *roff can't handle them embedded.
1409sub item_common {
1410    my ($self, $type, $attrs, $text) = @_;
1411    my $line = $$attrs{start_line};
1412
1413    # Clean up the text.  We want to end up with two variables, one ($text)
1414    # which contains any body text after taking out the item portion, and
1415    # another ($item) which contains the actual item text.
1416    $text =~ s/\s+$//;
1417    my ($item, $index);
1418    if ($type eq 'bullet') {
1419        $item = "\\\(bu";
1420        $text =~ s/\n*$/\n/;
1421    } elsif ($type eq 'number') {
1422        $item = $$attrs{number} . '.';
1423    } else {
1424        $item = $text;
1425        $item =~ s/\s*\n\s*/ /g;
1426        $text = '';
1427        $index = $item if ($item =~ /\w/);
1428    }
1429
1430    # Take care of the indentation.  If shifts and indents are equal, close
1431    # the top shift, since we're about to create an indentation with .IP.
1432    # Also output .PD 0 to turn off spacing between items if this item is
1433    # directly following another one.  We only have to do that once for a
1434    # whole chain of items so do it for the second item in the change.  Note
1435    # that makespace is what undoes this.
1436    if (@{ $$self{SHIFTS} } == @{ $$self{INDENTS} }) {
1437        $self->output (".RE\n");
1438        pop @{ $$self{SHIFTS} };
1439    }
1440    $self->output (".PD 0\n") if ($$self{ITEMS} == 1);
1441
1442    # Now, output the item tag itself.
1443    $item = $self->mapfonts($item, '\fR');
1444    $self->output($self->switchquotes('.IP', $item, $$self{INDENT}));
1445    $$self{NEEDSPACE} = 0;
1446    $$self{ITEMS}++;
1447    $$self{SHIFTWAIT} = 0;
1448
1449    # If body text for this item was included, go ahead and output that now.
1450    if ($text) {
1451        $text =~ s/\s*$/\n/;
1452        $self->makespace;
1453        $self->output($self->protect($self->mapfonts($text, '\fR')));
1454        $$self{NEEDSPACE} = 1;
1455    }
1456    $self->outindex ($index ? ('Item', $index) : ());
1457}
1458
1459# Dispatch the item commands to the appropriate place.
1460sub cmd_item_bullet { my $self = shift; $self->item_common ('bullet', @_) }
1461sub cmd_item_number { my $self = shift; $self->item_common ('number', @_) }
1462sub cmd_item_text   { my $self = shift; $self->item_common ('text',   @_) }
1463sub cmd_item_block  { my $self = shift; $self->item_common ('block',  @_) }
1464
1465##############################################################################
1466# Backward compatibility
1467##############################################################################
1468
1469# Reset the underlying Pod::Simple object between calls to parse_from_file so
1470# that the same object can be reused to convert multiple pages.
1471sub parse_from_file {
1472    my $self = shift;
1473    $self->reinit;
1474
1475    # Fake the old cutting option to Pod::Parser.  This fiddles with internal
1476    # Pod::Simple state and is quite ugly; we need a better approach.
1477    if (ref ($_[0]) eq 'HASH') {
1478        my $opts = shift @_;
1479        if (defined ($$opts{-cutting}) && !$$opts{-cutting}) {
1480            $$self{in_pod} = 1;
1481            $$self{last_was_blank} = 1;
1482        }
1483    }
1484
1485    # Do the work.
1486    my $retval = $self->SUPER::parse_from_file (@_);
1487
1488    # Flush output, since Pod::Simple doesn't do this.  Ideally we should also
1489    # close the file descriptor if we had to open one, but we can't easily
1490    # figure this out.
1491    my $fh = $self->output_fh ();
1492    my $oldfh = select $fh;
1493    my $oldflush = $|;
1494    $| = 1;
1495    print $fh '';
1496    $| = $oldflush;
1497    select $oldfh;
1498    return $retval;
1499}
1500
1501# Pod::Simple failed to provide this backward compatibility function, so
1502# implement it ourselves.  File handles are one of the inputs that
1503# parse_from_file supports.
1504sub parse_from_filehandle {
1505    my $self = shift;
1506    return $self->parse_from_file (@_);
1507}
1508
1509# Pod::Simple's parse_file doesn't set output_fh.  Wrap the call and do so
1510# ourself unless it was already set by the caller, since our documentation has
1511# always said that this should work.
1512sub parse_file {
1513    my ($self, $in) = @_;
1514    unless (defined $$self{output_fh}) {
1515        $self->output_fh (\*STDOUT);
1516    }
1517    return $self->SUPER::parse_file ($in);
1518}
1519
1520# Do the same for parse_lines, just to be polite.  Pod::Simple's man page
1521# implies that the caller is responsible for setting this, but I don't see any
1522# reason not to set a default.
1523sub parse_lines {
1524    my ($self, @lines) = @_;
1525    unless (defined $$self{output_fh}) {
1526        $self->output_fh (\*STDOUT);
1527    }
1528    return $self->SUPER::parse_lines (@lines);
1529}
1530
1531# Likewise for parse_string_document.
1532sub parse_string_document {
1533    my ($self, $doc) = @_;
1534    unless (defined $$self{output_fh}) {
1535        $self->output_fh (\*STDOUT);
1536    }
1537    return $self->SUPER::parse_string_document ($doc);
1538}
1539
1540##############################################################################
1541# Premable
1542##############################################################################
1543
1544# The preamble which starts all *roff output we generate.  Most is static
1545# except for the font to use as a fixed-width font (designed by @CFONT@), and
1546# the left and right quotes to use for C<> text (designated by @LQOUTE@ and
1547# @RQUOTE@).  Accent marks are only defined if the output encoding is roff.
1548sub preamble_template {
1549    my ($self) = @_;
1550    my $preamble = <<'----END OF PREAMBLE----';
1551.de Sp \" Vertical space (when we can't use .PP)
1552.if t .sp .5v
1553.if n .sp
1554..
1555.de Vb \" Begin verbatim text
1556.ft @CFONT@
1557.nf
1558.ne \\$1
1559..
1560.de Ve \" End verbatim text
1561.ft R
1562.fi
1563..
1564.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
1565.ie n \{\
1566.    ds C` @LQUOTE@
1567.    ds C' @RQUOTE@
1568'br\}
1569.el\{\
1570.    ds C`
1571.    ds C'
1572'br\}
1573.\"
1574.\" Escape single quotes in literal strings from groff's Unicode transform.
1575.ie \n(.g .ds Aq \(aq
1576.el       .ds Aq '
1577.\"
1578.\" If the F register is >0, we'll generate index entries on stderr for
1579.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
1580.\" entries marked with X<> in POD.  Of course, you'll have to process the
1581.\" output yourself in some meaningful fashion.
1582.\"
1583.\" Avoid warning from groff about undefined register 'F'.
1584.de IX
1585..
1586.nr rF 0
1587.if \n(.g .if rF .nr rF 1
1588.if (\n(rF:(\n(.g==0)) \{\
1589.    if \nF \{\
1590.        de IX
1591.        tm Index:\\$1\t\\n%\t"\\$2"
1592..
1593.        if !\nF==2 \{\
1594.            nr % 0
1595.            nr F 2
1596.        \}
1597.    \}
1598.\}
1599.rr rF
1600----END OF PREAMBLE----
1601#'# for cperl-mode
1602
1603    if ($$self{ENCODING} eq 'roff') {
1604        $preamble .= <<'----END OF PREAMBLE----'
1605.\"
1606.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
1607.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
1608.    \" fudge factors for nroff and troff
1609.if n \{\
1610.    ds #H 0
1611.    ds #V .8m
1612.    ds #F .3m
1613.    ds #[ \f1
1614.    ds #] \fP
1615.\}
1616.if t \{\
1617.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
1618.    ds #V .6m
1619.    ds #F 0
1620.    ds #[ \&
1621.    ds #] \&
1622.\}
1623.    \" simple accents for nroff and troff
1624.if n \{\
1625.    ds ' \&
1626.    ds ` \&
1627.    ds ^ \&
1628.    ds , \&
1629.    ds ~ ~
1630.    ds /
1631.\}
1632.if t \{\
1633.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h'|\\n:u'
1634.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
1635.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
1636.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
1637.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
1638.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
1639.\}
1640.    \" troff and (daisy-wheel) nroff accents
1641.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
1642.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
1643.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
1644.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
1645.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
1646.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
1647.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
1648.ds ae a\h'-(\w'a'u*4/10)'e
1649.ds Ae A\h'-(\w'A'u*4/10)'E
1650.    \" corrections for vroff
1651.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
1652.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
1653.    \" for low resolution devices (crt and lpr)
1654.if \n(.H>23 .if \n(.V>19 \
1655\{\
1656.    ds : e
1657.    ds 8 ss
1658.    ds o a
1659.    ds d- d\h'-1'\(ga
1660.    ds D- D\h'-1'\(hy
1661.    ds th \o'bp'
1662.    ds Th \o'LP'
1663.    ds ae ae
1664.    ds Ae AE
1665.\}
1666.rm #[ #] #H #V #F C
1667----END OF PREAMBLE----
1668#`# for cperl-mode
1669    }
1670    return $preamble;
1671}
1672
1673##############################################################################
1674# Module return value and documentation
1675##############################################################################
1676
16771;
1678__END__
1679
1680=encoding UTF-8
1681
1682=for stopwords
1683en em ALLCAPS teeny fixedbold fixeditalic fixedbolditalic stderr utf8 UTF-8
1684Allbery Sean Burke Ossanna Solaris formatters troff uppercased Christiansen
1685nourls parsers Kernighan lquote rquote unrepresentable mandoc NetBSD PostScript
1686SMP macOS EBCDIC fallbacks manref reflowed reflowing FH overridable
1687
1688=head1 NAME
1689
1690Pod::Man - Convert POD data to formatted *roff input
1691
1692=head1 SYNOPSIS
1693
1694    use Pod::Man;
1695    my $parser = Pod::Man->new (release => $VERSION, section => 8);
1696
1697    # Read POD from STDIN and write to STDOUT.
1698    $parser->parse_file (\*STDIN);
1699
1700    # Read POD from file.pod and write to file.1.
1701    $parser->parse_from_file ('file.pod', 'file.1');
1702
1703=head1 DESCRIPTION
1704
1705Pod::Man is a module to convert documentation in the POD format (the
1706preferred language for documenting Perl) into *roff input using the man
1707macro set.  The resulting *roff code is suitable for display on a terminal
1708using L<nroff(1)>, normally via L<man(1)>, or printing using L<troff(1)>.
1709It is conventionally invoked using the driver script B<pod2man>, but it can
1710also be used directly.
1711
1712By default (on non-EBCDIC systems), Pod::Man outputs UTF-8.  Its output should
1713work with the B<man> program on systems that use B<groff> (most Linux
1714distributions) or B<mandoc> (most BSD variants), but may result in mangled
1715output on older UNIX systems.  To choose a different, possibly more
1716backward-compatible output mangling on such systems, set the C<encoding>
1717option to C<roff> (the default in earlier Pod::Man versions).  See the
1718C<encoding> option and L</ENCODING> for more details.
1719
1720See L</COMPATIBILTY> for the versions of Pod::Man with significant
1721backward-incompatible changes (other than constructor options, whose versions
1722are documented below), and the versions of Perl that included them.
1723
1724=head1 CLASS METHODS
1725
1726=over 4
1727
1728=item new(ARGS)
1729
1730Create a new Pod::Man object.  ARGS should be a list of key/value pairs, where
1731the keys are chosen from the following.  Each option is annotated with the
1732version of Pod::Man in which that option was added with its current meaning.
1733
1734=over 4
1735
1736=item center
1737
1738[1.00] Sets the centered page header for the C<.TH> macro.  The default, if
1739this option is not specified, is C<User Contributed Perl Documentation>.
1740
1741=item date
1742
1743[4.00] Sets the left-hand footer for the C<.TH> macro.  If this option is not
1744set, the contents of the environment variable POD_MAN_DATE, if set, will be
1745used.  Failing that, the value of SOURCE_DATE_EPOCH, the modification date of
1746the input file, or the current time if stat() can't find that file (which will
1747be the case if the input is from C<STDIN>) will be used.  If taken from any
1748source other than POD_MAN_DATE (which is used verbatim), the date will be
1749formatted as C<YYYY-MM-DD> and will be based on UTC (so that the output will
1750be reproducible regardless of local time zone).
1751
1752=item encoding
1753
1754[5.00] Specifies the encoding of the output.  The value must be an encoding
1755recognized by the L<Encode> module (see L<Encode::Supported>), or the special
1756values C<roff> or C<groff>.  The default on non-EBCDIC systems is UTF-8.
1757
1758If the output contains characters that cannot be represented in this encoding,
1759that is an error that will be reported as configured by the C<errors> option.
1760If error handling is other than C<die>, the unrepresentable character will be
1761replaced with the Encode substitution character (normally C<?>).
1762
1763If the C<encoding> option is set to the special value C<groff> (the default on
1764EBCDIC systems), or if the Encode module is not available and the encoding is
1765set to anything other than C<roff>, Pod::Man will translate all non-ASCII
1766characters to C<\[uNNNN]> Unicode escapes.  These are not traditionally part
1767of the *roff language, but are supported by B<groff> and B<mandoc> and thus by
1768the majority of manual page processors in use today.
1769
1770If the C<encoding> option is set to the special value C<roff>, Pod::Man will
1771do its historic transformation of (some) ISO 8859-1 characters into *roff
1772escapes that may be adequate in troff and may be readable (if ugly) in nroff.
1773This was the default behavior of versions of Pod::Man before 5.00.  With this
1774encoding, all other non-ASCII characters will be replaced with C<X>.  It may
1775be required for very old troff and nroff implementations that do not support
1776UTF-8, but its representation of any non-ASCII character is very poor and
1777often specific to European languages.
1778
1779If the output file handle has a PerlIO encoding layer set, setting C<encoding>
1780to anything other than C<groff> or C<roff> will be ignored and no encoding
1781will be done by Pod::Man.  It will instead rely on the encoding layer to make
1782whatever output encoding transformations are desired.
1783
1784WARNING: The input encoding of the POD source is independent from the output
1785encoding, and setting this option does not affect the interpretation of the
1786POD input.  Unless your POD source is US-ASCII, its encoding should be
1787declared with the C<=encoding> command in the source.  If this is not done,
1788Pod::Simple will will attempt to guess the encoding and may be successful if
1789it's Latin-1 or UTF-8, but it will produce warnings.  See L<perlpod(1)> for
1790more information.
1791
1792=item errors
1793
1794[2.27] How to report errors.  C<die> says to throw an exception on any POD
1795formatting error.  C<stderr> says to report errors on standard error, but not
1796to throw an exception.  C<pod> says to include a POD ERRORS section in the
1797resulting documentation summarizing the errors.  C<none> ignores POD errors
1798entirely, as much as possible.
1799
1800The default is C<pod>.
1801
1802=item fixed
1803
1804[1.00] The fixed-width font to use for verbatim text and code.  Defaults to
1805C<CW>.  Some systems prefer C<CR> instead.  Only matters for B<troff> output.
1806
1807=item fixedbold
1808
1809[1.00] Bold version of the fixed-width font.  Defaults to C<CB>.  Only matters
1810for B<troff> output.
1811
1812=item fixeditalic
1813
1814[1.00] Italic version of the fixed-width font (something of a misnomer, since
1815most fixed-width fonts only have an oblique version, not an italic version).
1816Defaults to C<CI>.  Only matters for B<troff> output.
1817
1818=item fixedbolditalic
1819
1820[1.00] Bold italic (in theory, probably oblique in practice) version of the
1821fixed-width font.  Pod::Man doesn't assume you have this, and defaults to
1822C<CB>.  Some systems (such as Solaris) have this font available as C<CX>.
1823Only matters for B<troff> output.
1824
1825=item guesswork
1826
1827[5.00] By default, Pod::Man applies some default formatting rules based on
1828guesswork and regular expressions that are intended to make writing Perl
1829documentation easier and require less explicit markup.  These rules may not
1830always be appropriate, particularly for documentation that isn't about Perl.
1831This option allows turning all or some of it off.
1832
1833The special value C<all> enables all guesswork.  This is also the default for
1834backward compatibility reasons.  The special value C<none> disables all
1835guesswork.  Otherwise, the value of this option should be a comma-separated
1836list of one or more of the following keywords:
1837
1838=over 4
1839
1840=item functions
1841
1842Convert function references like C<foo()> to bold even if they have no markup.
1843The function name accepts valid Perl characters for function names (including
1844C<:>), and the trailing parentheses must be present and empty.
1845
1846=item manref
1847
1848Make the first part (before the parentheses) of manual page references like
1849C<foo(1)> bold even if they have no markup.  The section must be a single
1850number optionally followed by lowercase letters.
1851
1852=item quoting
1853
1854If no guesswork is enabled, any text enclosed in CZ<><> is surrounded by
1855double quotes in nroff (terminal) output unless the contents are already
1856quoted.  When this guesswork is enabled, quote marks will also be suppressed
1857for Perl variables, function names, function calls, numbers, and hex
1858constants.
1859
1860=item variables
1861
1862Convert Perl variable names to a fixed-width font even if they have no markup.
1863This transformation will only be apparent in troff output, or some other
1864output format (unlike nroff terminal output) that supports fixed-width fonts.
1865
1866=back
1867
1868Any unknown guesswork name is silently ignored (for potential future
1869compatibility), so be careful about spelling.
1870
1871=item language
1872
1873[5.00] Add commands telling B<groff> that the input file is in the given
1874language.  The value of this setting must be a language abbreviation for which
1875B<groff> provides supplemental configuration, such as C<ja> (for Japanese) or
1876C<zh> (for Chinese).
1877
1878Specifically, this adds:
1879
1880    .mso <language>.tmac
1881    .hla <language>
1882
1883to the start of the file, which configure correct line breaking for the
1884specified language.  Without these commands, groff may not know how to add
1885proper line breaks for Chinese and Japanese text if the manual page is
1886installed into the normal manual page directory, such as F</usr/share/man>.
1887
1888On many systems, this will be done automatically if the manual page is
1889installed into a language-specific manual page directory, such as
1890F</usr/share/man/zh_CN>.  In that case, this option is not required.
1891
1892Unfortunately, the commands added with this option are specific to B<groff>
1893and will not work with other B<troff> and B<nroff> implementations.
1894
1895=item lquote
1896
1897=item rquote
1898
1899[4.08] Sets the quote marks used to surround CE<lt>> text.  C<lquote> sets the
1900left quote mark and C<rquote> sets the right quote mark.  Either may also be
1901set to the special value C<none>, in which case no quote mark is added on that
1902side of CE<lt>> text (but the font is still changed for troff output).
1903
1904Also see the C<quotes> option, which can be used to set both quotes at once.
1905If both C<quotes> and one of the other options is set, C<lquote> or C<rquote>
1906overrides C<quotes>.
1907
1908=item name
1909
1910[4.08] Set the name of the manual page for the C<.TH> macro.  Without this
1911option, the manual name is set to the uppercased base name of the file being
1912converted unless the manual section is 3, in which case the path is parsed to
1913see if it is a Perl module path.  If it is, a path like C<.../lib/Pod/Man.pm>
1914is converted into a name like C<Pod::Man>.  This option, if given, overrides
1915any automatic determination of the name.
1916
1917If generating a manual page from standard input, the name will be set to
1918C<STDIN> if this option is not provided.  In this case, providing this option
1919is strongly recommended to set a meaningful manual page name.
1920
1921=item nourls
1922
1923[2.27] Normally, LZ<><> formatting codes with a URL but anchor text are
1924formatted to show both the anchor text and the URL.  In other words:
1925
1926    L<foo|http://example.com/>
1927
1928is formatted as:
1929
1930    foo <http://example.com/>
1931
1932This option, if set to a true value, suppresses the URL when anchor text
1933is given, so this example would be formatted as just C<foo>.  This can
1934produce less cluttered output in cases where the URLs are not particularly
1935important.
1936
1937=item quotes
1938
1939[4.00] Sets the quote marks used to surround CE<lt>> text.  If the value is a
1940single character, it is used as both the left and right quote.  Otherwise, it
1941is split in half, and the first half of the string is used as the left quote
1942and the second is used as the right quote.
1943
1944This may also be set to the special value C<none>, in which case no quote
1945marks are added around CE<lt>> text (but the font is still changed for troff
1946output).
1947
1948Also see the C<lquote> and C<rquote> options, which can be used to set the
1949left and right quotes independently.  If both C<quotes> and one of the other
1950options is set, C<lquote> or C<rquote> overrides C<quotes>.
1951
1952=item release
1953
1954[1.00] Set the centered footer for the C<.TH> macro.  By default, this is set
1955to the version of Perl you run Pod::Man under.  Setting this to the empty
1956string will cause some *roff implementations to use the system default value.
1957
1958Note that some system C<an> macro sets assume that the centered footer will be
1959a modification date and will prepend something like C<Last modified: >.  If
1960this is the case for your target system, you may want to set C<release> to the
1961last modified date and C<date> to the version number.
1962
1963=item section
1964
1965[1.00] Set the section for the C<.TH> macro.  The standard section numbering
1966convention is to use 1 for user commands, 2 for system calls, 3 for functions,
19674 for devices, 5 for file formats, 6 for games, 7 for miscellaneous
1968information, and 8 for administrator commands.  There is a lot of variation
1969here, however; some systems (like Solaris) use 4 for file formats, 5 for
1970miscellaneous information, and 7 for devices.  Still others use 1m instead of
19718, or some mix of both.  About the only section numbers that are reliably
1972consistent are 1, 2, and 3.
1973
1974By default, section 1 will be used unless the file ends in C<.pm> in which
1975case section 3 will be selected.
1976
1977=item stderr
1978
1979[2.19] If set to a true value, send error messages about invalid POD to
1980standard error instead of appending a POD ERRORS section to the generated
1981*roff output.  This is equivalent to setting C<errors> to C<stderr> if
1982C<errors> is not already set.
1983
1984This option is for backward compatibility with Pod::Man versions that did not
1985support C<errors>.  Normally, the C<errors> option should be used instead.
1986
1987=item utf8
1988
1989[2.21] This option used to set the output encoding to UTF-8.  Since this is
1990now the default, it is ignored and does nothing.
1991
1992=back
1993
1994=back
1995
1996=head1 INSTANCE METHODS
1997
1998As a derived class from Pod::Simple, Pod::Man supports the same methods and
1999interfaces.  See L<Pod::Simple> for all the details.  This section summarizes
2000the most-frequently-used methods and the ones added by Pod::Man.
2001
2002=over 4
2003
2004=item output_fh(FH)
2005
2006Direct the output from parse_file(), parse_lines(), or parse_string_document()
2007to the file handle FH instead of C<STDOUT>.
2008
2009=item output_string(REF)
2010
2011Direct the output from parse_file(), parse_lines(), or parse_string_document()
2012to the scalar variable pointed to by REF, rather than C<STDOUT>.  For example:
2013
2014    my $man = Pod::Man->new();
2015    my $output;
2016    $man->output_string(\$output);
2017    $man->parse_file('/some/input/file');
2018
2019Be aware that the output in that variable will already be encoded in UTF-8.
2020
2021=item parse_file(PATH)
2022
2023Read the POD source from PATH and format it.  By default, the output is sent
2024to C<STDOUT>, but this can be changed with the output_fh() or output_string()
2025methods.
2026
2027=item parse_from_file(INPUT, OUTPUT)
2028
2029=item parse_from_filehandle(FH, OUTPUT)
2030
2031Read the POD source from INPUT, format it, and output the results to OUTPUT.
2032
2033parse_from_filehandle() is provided for backward compatibility with older
2034versions of Pod::Man.  parse_from_file() should be used instead.
2035
2036=item parse_lines(LINES[, ...[, undef]])
2037
2038Parse the provided lines as POD source, writing the output to either C<STDOUT>
2039or the file handle set with the output_fh() or output_string() methods.  This
2040method can be called repeatedly to provide more input lines.  An explicit
2041C<undef> should be passed to indicate the end of input.
2042
2043This method expects raw bytes, not decoded characters.
2044
2045=item parse_string_document(INPUT)
2046
2047Parse the provided scalar variable as POD source, writing the output to either
2048C<STDOUT> or the file handle set with the output_fh() or output_string()
2049methods.
2050
2051This method expects raw bytes, not decoded characters.
2052
2053=back
2054
2055=head1 ENCODING
2056
2057As of Pod::Man 5.00, the default output encoding for Pod::Man is UTF-8.  This
2058should work correctly on any modern system that uses either B<groff> (most
2059Linux distributions) or B<mandoc> (Alpine Linux and most BSD variants,
2060including macOS).
2061
2062The user will probably have to use a UTF-8 locale to see correct output.  This
2063may be done by default; if not, set the LANG or LC_CTYPE environment variables
2064to an appropriate local.  The locale C<C.UTF-8> is available on most systems
2065if one wants correct output without changing the other things locales affect,
2066such as collation.
2067
2068The backward-compatible output format used in Pod::Man versions before 5.00 is
2069available by setting the C<encoding> option to C<roff>.  This may produce
2070marginally nicer results on older UNIX versions that do not use B<groff> or
2071B<mandoc>, but none of the available options will correctly render Unicode
2072characters on those systems.
2073
2074Below are some additional details about how this choice was made and some
2075discussion of alternatives.
2076
2077=head2 History
2078
2079The default output encoding for Pod::Man has been a long-standing problem.
2080B<troff> and B<nroff> predate Unicode by a significant margin, and their
2081implementations for many UNIX systems reflect that legacy.  It's common for
2082Unicode to not be supported in any form.
2083
2084Because of this, versions of Pod::Man prior to 5.00 maintained the highly
2085conservative output of the original pod2man, which output pure ASCII with
2086complex macros to simulate common western European accented characters when
2087processed with troff.  The nroff output was awkward and sometimes incorrect,
2088and characters not used in western European scripts were replaced with C<X>.
2089This choice maximized backwards compatibility with B<man> and
2090B<nroff>/B<troff> implementations at the cost of incorrect rendering of many
2091POD documents, particularly those containing people's names.
2092
2093The modern implementations, B<groff> (used in most Linux distributions) and
2094B<mandoc> (used by most BSD variants), do now support Unicode.  Other UNIX
2095systems often do not, but they're now a tiny minority of the systems people
2096use on a daily basis.  It's increasingly common (for very good reasons) to use
2097Unicode characters for POD documents rather than using ASCII conversions of
2098people's names or avoiding non-English text, making the limitations in the old
2099output format more apparent.
2100
2101Four options have been proposed to fix this:
2102
2103=over 2
2104
2105=item *
2106
2107Optionally support UTF-8 output but don't change the default.  This is the
2108approach taken since Pod::Man 2.1.0, which added the C<utf8> option.  Some
2109Pod::Man users use this option for better output on platforms known to support
2110Unicode, but since the defaults have not changed, people continued to
2111encounter (and file bug reports about) the poor default rendering.
2112
2113=item *
2114
2115Convert characters to troff C<\(xx> escapes.  This requires maintaining a
2116large translation table and addresses only a tiny part of the problem, since
2117many Unicode characters have no standard troff name.  B<groff> has the largest
2118list, but if one is willing to assume B<groff> is the formatter, the next
2119option is better.
2120
2121=item *
2122
2123Convert characters to groff C<\[uNNNN]> escapes.  This is implemented as the
2124C<groff> encoding for those who want to use it, and is supported by both
2125B<groff> and B<mandoc>.  However, it is no better than UTF-8 output for
2126portability to other implementations.  See L</Testing results> for more
2127details.
2128
2129=item *
2130
2131Change the default output format to UTF-8 and ask those who want maximum
2132backward compatibility to explicitly select the old encoding.  This fixes the
2133issue for most users at the cost of backwards compatibility.  While the
2134rendering of non-ASCII characters is different on older systems that don't
2135support UTF-8, it's not always worse than the old output.
2136
2137=back
2138
2139Pod::Man 5.00 and later makes the last choice.  This arguably produces worse
2140output when manual pages are formatted with B<troff> into PostScript or PDF,
2141but doing this is rare and normally manual, so the encoding can be changed in
2142those cases.  The older output encoding is available by setting C<encoding> to
2143C<roff>.
2144
2145=head2 Testing results
2146
2147Here is the results of testing C<encoding> values of C<utf-8> and C<groff> on
2148various operating systems.  The testing methodology was to create F<man/man1>
2149in the current directory, copy F<encoding.utf8> or F<encoding.groff> from the
2150podlators 5.00 distribution to F<man/man1/encoding.1>, and then run:
2151
2152    LANG=C.UTF-8 MANPATH=$(pwd)/man man 1 encoding
2153
2154If the locale is not explicitly set to one that includes UTF-8, the Unicode
2155characters were usually converted to ASCII (by, for example, dropping an
2156accent) or deleted or replaced with C<< <?> >> if there was no conversion.
2157
2158Tested on 2022-09-25.  Many thanks to the GCC Compile Farm project for access
2159to testing hosts.
2160
2161    OS                   UTF-8      groff
2162    ------------------   -------    -------
2163    AIX 7.1              no [1]     no [2]
2164    Alpine 3.15.0        yes        yes
2165    CentOS 7.9           yes        yes
2166    Debian 7             yes        yes
2167    FreeBSD 13.0         yes        yes
2168    NetBSD 9.2           yes        yes
2169    OpenBSD 7.1          yes        yes
2170    openSUSE Leap 15.4   yes        yes
2171    Solaris 10           yes        no [2]
2172    Solaris 11           no [3]     no [3]
2173
2174I did not have access to a macOS system for testing, but since it uses
2175B<mandoc>, it's behavior is probably the same as the BSD hosts.
2176
2177Notes:
2178
2179=over 4
2180
2181=item [1]
2182
2183Unicode characters were converted to one or two random ASCII characters
2184unrelated to the original character.
2185
2186=item [2]
2187
2188Unicode characters were shown as the body of the groff escape rather than the
2189indicated character (in other words, text like C<[u00EF]>).
2190
2191=item [3]
2192
2193Unicode characters were deleted entirely, as if they weren't there.  Using
2194C<nroff -man> instead of B<man> to format the page showed the same results as
2195Solaris 10.  Using C<groff -k -man -Tutf8> to format the page produced the
2196correct output.
2197
2198=back
2199
2200PostScript and PDF output using groff on a Debian 12 system do not support
2201combining accent marks or SMP characters due to a lack of support in the
2202default output font.
2203
2204Testing on additional platforms is welcome.  Please let the author know if you
2205have additional results.
2206
2207=head1 DIAGNOSTICS
2208
2209=over 4
2210
2211=item roff font should be 1 or 2 chars, not "%s"
2212
2213(F) You specified a *roff font (using C<fixed>, C<fixedbold>, etc.) that
2214wasn't either one or two characters.  Pod::Man doesn't support *roff fonts
2215longer than two characters, although some *roff extensions do (the
2216canonical versions of B<nroff> and B<troff> don't either).
2217
2218=item Invalid errors setting "%s"
2219
2220(F) The C<errors> parameter to the constructor was set to an unknown value.
2221
2222=item Invalid quote specification "%s"
2223
2224(F) The quote specification given (the C<quotes> option to the
2225constructor) was invalid.  A quote specification must be either one
2226character long or an even number (greater than one) characters long.
2227
2228=item POD document had syntax errors
2229
2230(F) The POD document being formatted had syntax errors and the C<errors>
2231option was set to C<die>.
2232
2233=back
2234
2235=head1 ENVIRONMENT
2236
2237=over 4
2238
2239=item PERL_CORE
2240
2241If set and Encode is not available, silently fall back to an encoding of
2242C<groff> without complaining to standard error.  This environment variable is
2243set during Perl core builds, which build Encode after podlators.  Encode is
2244expected to not (yet) be available in that case.
2245
2246=item POD_MAN_DATE
2247
2248If set, this will be used as the value of the left-hand footer unless the
2249C<date> option is explicitly set, overriding the timestamp of the input
2250file or the current time.  This is primarily useful to ensure reproducible
2251builds of the same output file given the same source and Pod::Man version,
2252even when file timestamps may not be consistent.
2253
2254=item SOURCE_DATE_EPOCH
2255
2256If set, and POD_MAN_DATE and the C<date> options are not set, this will be
2257used as the modification time of the source file, overriding the timestamp of
2258the input file or the current time.  It should be set to the desired time in
2259seconds since UNIX epoch.  This is primarily useful to ensure reproducible
2260builds of the same output file given the same source and Pod::Man version,
2261even when file timestamps may not be consistent.  See
2262L<https://reproducible-builds.org/specs/source-date-epoch/> for the full
2263specification.
2264
2265(Arguably, according to the specification, this variable should be used only
2266if the timestamp of the input file is not available and Pod::Man uses the
2267current time.  However, for reproducible builds in Debian, results were more
2268reliable if this variable overrode the timestamp of the input file.)
2269
2270=back
2271
2272=head1 COMPATIBILITY
2273
2274Pod::Man 1.02 (based on L<Pod::Parser>) was the first version included with
2275Perl, in Perl 5.6.0.
2276
2277The current API based on L<Pod::Simple> was added in Pod::Man 2.00.  Pod::Man
22782.04 was included in Perl 5.9.3, the first version of Perl to incorporate
2279those changes.  This is the first version that correctly supports all modern
2280POD syntax.  The parse_from_filehandle() method was re-added for backward
2281compatibility in Pod::Man 2.09, included in Perl 5.9.4.
2282
2283Support for anchor text in LZ<><> links of type URL was added in Pod::Man
22842.23, included in Perl 5.11.5.
2285
2286parse_lines(), parse_string_document(), and parse_file() set a default output
2287file handle of C<STDOUT> if one was not already set as of Pod::Man 2.28,
2288included in Perl 5.19.5.
2289
2290Support for SOURCE_DATE_EPOCH and POD_MAN_DATE was added in Pod::Man 4.00,
2291included in Perl 5.23.7, and generated dates were changed to use UTC instead
2292of the local time zone.  This is also the first release that aligned the
2293module version and the version of the podlators distribution.  All modules
2294included in podlators, and the podlators distribution itself, share the same
2295version number from this point forward.
2296
2297Pod::Man 4.10, included in Perl 5.27.8, changed the formatting for manual page
2298references and function names to bold instead of italic, following the current
2299Linux manual page standard.
2300
2301Pod::Man 5.00 changed the default output encoding to UTF-8, overridable with
2302the new C<encoding> option.  It also fixed problems with bold or italic
2303extending too far when used with CZ<><> escapes, and began converting Unicode
2304zero-width spaces (U+200B) to the C<\:> *roff escape.  It also dropped
2305attempts to add subtle formatting corrections in the output that would only be
2306visible when typeset with B<troff>, which had previously been a significant
2307source of bugs.
2308
2309=head1 BUGS
2310
2311There are numerous bugs and language-specific assumptions in the nroff
2312fallbacks for accented characters in the C<roff> encoding.  Since the point of
2313this encoding is backward compatibility with the output from earlier versions
2314of Pod::Man, and it is deprecated except when necessary to support old
2315systems, those bugs are unlikely to ever be fixed.
2316
2317Pod::Man doesn't handle font names longer than two characters.  Neither do
2318most B<troff> implementations, but groff does as an extension.  It would be
2319nice to support as an option for those who want to use it.
2320
2321=head1 CAVEATS
2322
2323=head2 Sentence spacing
2324
2325Pod::Man copies the input spacing verbatim to the output *roff document.  This
2326means your output will be affected by how B<nroff> generally handles sentence
2327spacing.
2328
2329B<nroff> dates from an era in which it was standard to use two spaces after
2330sentences, and will always add two spaces after a line-ending period (or
2331similar punctuation) when reflowing text.  For example, the following input:
2332
2333    =pod
2334
2335    One sentence.
2336    Another sentence.
2337
2338will result in two spaces after the period when the text is reflowed.  If you
2339use two spaces after sentences anyway, this will be consistent, although you
2340will have to be careful to not end a line with an abbreviation such as C<e.g.>
2341or C<Ms.>.  Output will also be consistent if you use the *roff style guide
2342(and L<XKCD 1285|https://xkcd.com/1285/>) recommendation of putting a line
2343break after each sentence, although that will consistently produce two spaces
2344after each sentence, which may not be what you want.
2345
2346If you prefer one space after sentences (which is the more modern style), you
2347will unfortunately need to ensure that no line in the middle of a paragraph
2348ends in a period or similar sentence-ending paragraph.  Otherwise, B<nroff>
2349will add a two spaces after that sentence when reflowing, and your output
2350document will have inconsistent spacing.
2351
2352=head2 Hyphens
2353
2354The handling of hyphens versus dashes is somewhat fragile, and one may get a
2355the wrong one under some circumstances.  This will normally only matter for
2356line breaking and possibly for troff output.
2357
2358=head1 AUTHOR
2359
2360Written by Russ Allbery <rra@cpan.org>, based on the original B<pod2man> by
2361Tom Christiansen <tchrist@mox.perl.com>.
2362
2363The modifications to work with Pod::Simple instead of Pod::Parser were
2364contributed by Sean Burke <sburke@cpan.org>, but I've since hacked them beyond
2365recognition and all bugs are mine.
2366
2367=head1 COPYRIGHT AND LICENSE
2368
2369Copyright 1999-2010, 2012-2020, 2022 Russ Allbery <rra@cpan.org>
2370
2371Substantial contributions by Sean Burke <sburke@cpan.org>.
2372
2373This program is free software; you may redistribute it and/or modify it
2374under the same terms as Perl itself.
2375
2376=head1 SEE ALSO
2377
2378L<Encode::Supported>, L<Pod::Simple>, L<perlpod(1)>, L<pod2man(1)>,
2379L<nroff(1)>, L<troff(1)>, L<man(1)>, L<man(7)>
2380
2381Ossanna, Joseph F., and Brian W. Kernighan.  "Troff User's Manual,"
2382Computing Science Technical Report No. 54, AT&T Bell Laboratories.  This is
2383the best documentation of standard B<nroff> and B<troff>.  At the time of
2384this writing, it's available at L<http://www.troff.org/54.pdf>.
2385
2386The manual page documenting the man macro set may be L<man(5)> instead of
2387L<man(7)> on your system.
2388
2389See L<perlpodstyle(1)> for documentation on writing manual pages in POD if
2390you've not done it before and aren't familiar with the conventions.
2391
2392The current version of this module is always available from its web site at
2393L<https://www.eyrie.org/~eagle/software/podlators/>.  It is also part of the
2394Perl core distribution as of 5.6.0.
2395
2396=cut
2397
2398# Local Variables:
2399# copyright-at-end-flag: t
2400# End:
2401