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