Upgrade to podlators-1.03 (Pod::Man 1.07 and Pod::Text 2.05),
[p5sagit/p5-mst-13.2.git] / lib / Pod / Man.pm
1 # Pod::Man -- Convert POD data to formatted *roff input.
2 # $Id: Man.pm,v 1.7 2000/09/03 09:22:57 eagle Exp $
3 #
4 # Copyright 1999, 2000 by Russ Allbery <rra@stanford.edu>
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
8 #
9 # This module is intended to be a replacement for the pod2man script
10 # distributed with versions of Perl prior to 5.6, and attempts to match its
11 # output except for some specific circumstances where other decisions seemed
12 # to produce better output.  It uses Pod::Parser and is designed to be easy
13 # to subclass.
14 #
15 # Perl core hackers, please note that this module is also separately
16 # maintained outside of the Perl core as part of the podlators.  Please send
17 # me any patches at the address above in addition to sending them to the
18 # standard Perl mailing lists.
19
20 ############################################################################
21 # Modules and declarations
22 ############################################################################
23
24 package Pod::Man;
25
26 require 5.004;
27
28 use Carp qw(carp croak);
29 use Pod::Parser ();
30
31 use strict;
32 use subs qw(makespace);
33 use vars qw(@ISA %ESCAPES $PREAMBLE $VERSION);
34
35 @ISA = qw(Pod::Parser);
36
37 # Don't use the CVS revision as the version, since this module is also in
38 # Perl core and too many things could munge CVS magic revision strings.
39 # This number should ideally be the same as the CVS revision in podlators,
40 # however.
41 $VERSION = 1.07;
42
43
44 ############################################################################
45 # Preamble and *roff output tables
46 ############################################################################
47
48 # The following is the static preamble which starts all *roff output we
49 # generate.  It's completely static except for the font to use as a
50 # fixed-width font, which is designed by @CFONT@, and the left and right
51 # quotes to use for C<> text, designated by @LQOUTE@ and @RQUOTE@.
52 # $PREAMBLE should therefore be run through s/\@CFONT\@/<font>/g before
53 # output.
54 $PREAMBLE = <<'----END OF PREAMBLE----';
55 .de Sh \" Subsection heading
56 .br
57 .if t .Sp
58 .ne 5
59 .PP
60 \fB\\$1\fR
61 .PP
62 ..
63 .de Sp \" Vertical space (when we can't use .PP)
64 .if t .sp .5v
65 .if n .sp
66 ..
67 .de Ip \" List item
68 .br
69 .ie \\n(.$>=3 .ne \\$3
70 .el .ne 3
71 .IP "\\$1" \\$2
72 ..
73 .de Vb \" Begin verbatim text
74 .ft @CFONT@
75 .nf
76 .ne \\$1
77 ..
78 .de Ve \" End verbatim text
79 .ft R
80
81 .fi
82 ..
83 .\" Set up some character translations and predefined strings.  \*(-- will
84 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
85 .\" double quote, and \*(R" will give a right double quote.  | will give a
86 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used
87 .\" to do unbreakable dashes and therefore won't be available.  \*(C` and
88 .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
89 .tr \(*W-|\(bv\*(Tr
90 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
91 .ie n \{\
92 .    ds -- \(*W-
93 .    ds PI pi
94 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
95 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
96 .    ds L" ""
97 .    ds R" ""
98 .    ds C` @LQUOTE@
99 .    ds C' @RQUOTE@
100 'br\}
101 .el\{\
102 .    ds -- \|\(em\|
103 .    ds PI \(*p
104 .    ds L" ``
105 .    ds R" ''
106 'br\}
107 .\"
108 .\" If the F register is turned on, we'll generate index entries on stderr
109 .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
110 .\" index entries marked with X<> in POD.  Of course, you'll have to process
111 .\" the output yourself in some meaningful fashion.
112 .if \nF \{\
113 .    de IX
114 .    tm Index:\\$1\t\\n%\t"\\$2"
115 ..
116 .    nr % 0
117 .    rr F
118 .\}
119 .\"
120 .\" For nroff, turn off justification.  Always turn off hyphenation; it
121 .\" makes way too many mistakes in technical documents.
122 .hy 0
123 .if n .na
124 .\"
125 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
126 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
127 .bd B 3
128 .    \" fudge factors for nroff and troff
129 .if n \{\
130 .    ds #H 0
131 .    ds #V .8m
132 .    ds #F .3m
133 .    ds #[ \f1
134 .    ds #] \fP
135 .\}
136 .if t \{\
137 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
138 .    ds #V .6m
139 .    ds #F 0
140 .    ds #[ \&
141 .    ds #] \&
142 .\}
143 .    \" simple accents for nroff and troff
144 .if n \{\
145 .    ds ' \&
146 .    ds ` \&
147 .    ds ^ \&
148 .    ds , \&
149 .    ds ~ ~
150 .    ds /
151 .\}
152 .if t \{\
153 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
154 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
155 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
156 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
157 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
158 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
159 .\}
160 .    \" troff and (daisy-wheel) nroff accents
161 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
162 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
163 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
164 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
165 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
166 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
167 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
168 .ds ae a\h'-(\w'a'u*4/10)'e
169 .ds Ae A\h'-(\w'A'u*4/10)'E
170 .    \" corrections for vroff
171 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
172 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
173 .    \" for low resolution devices (crt and lpr)
174 .if \n(.H>23 .if \n(.V>19 \
175 \{\
176 .    ds : e
177 .    ds 8 ss
178 .    ds o a
179 .    ds d- d\h'-1'\(ga
180 .    ds D- D\h'-1'\(hy
181 .    ds th \o'bp'
182 .    ds Th \o'LP'
183 .    ds ae ae
184 .    ds Ae AE
185 .\}
186 .rm #[ #] #H #V #F C
187 ----END OF PREAMBLE----
188                                    
189 # This table is taken nearly verbatim from Tom Christiansen's pod2man.  It
190 # assumes that the standard preamble has already been printed, since that's
191 # what defines all of the accent marks.  Note that some of these are quoted
192 # with double quotes since they contain embedded single quotes, so use \\
193 # uniformly for backslash for readability.
194 %ESCAPES = (
195     'amp'       =>    '&',      # ampersand
196     'lt'        =>    '<',      # left chevron, less-than
197     'gt'        =>    '>',      # right chevron, greater-than
198     'quot'      =>    '"',      # double quote
199     'sol'       =>    '/',      # solidus (forward slash)
200     'verbar'    =>    '|',      # vertical bar
201
202     'Aacute'    =>    "A\\*'",  # capital A, acute accent
203     'aacute'    =>    "a\\*'",  # small a, acute accent
204     'Acirc'     =>    'A\\*^',  # capital A, circumflex accent
205     'acirc'     =>    'a\\*^',  # small a, circumflex accent
206     'AElig'     =>    '\*(AE',  # capital AE diphthong (ligature)
207     'aelig'     =>    '\*(ae',  # small ae diphthong (ligature)
208     'Agrave'    =>    "A\\*`",  # capital A, grave accent
209     'agrave'    =>    "A\\*`",  # small a, grave accent
210     'Aring'     =>    'A\\*o',  # capital A, ring
211     'aring'     =>    'a\\*o',  # small a, ring
212     'Atilde'    =>    'A\\*~',  # capital A, tilde
213     'atilde'    =>    'a\\*~',  # small a, tilde
214     'Auml'      =>    'A\\*:',  # capital A, dieresis or umlaut mark
215     'auml'      =>    'a\\*:',  # small a, dieresis or umlaut mark
216     'Ccedil'    =>    'C\\*,',  # capital C, cedilla
217     'ccedil'    =>    'c\\*,',  # small c, cedilla
218     'Eacute'    =>    "E\\*'",  # capital E, acute accent
219     'eacute'    =>    "e\\*'",  # small e, acute accent
220     'Ecirc'     =>    'E\\*^',  # capital E, circumflex accent
221     'ecirc'     =>    'e\\*^',  # small e, circumflex accent
222     'Egrave'    =>    'E\\*`',  # capital E, grave accent
223     'egrave'    =>    'e\\*`',  # small e, grave accent
224     'ETH'       =>    '\\*(D-', # capital Eth, Icelandic
225     'eth'       =>    '\\*(d-', # small eth, Icelandic
226     'Euml'      =>    'E\\*:',  # capital E, dieresis or umlaut mark
227     'euml'      =>    'e\\*:',  # small e, dieresis or umlaut mark
228     'Iacute'    =>    "I\\*'",  # capital I, acute accent
229     'iacute'    =>    "i\\*'",  # small i, acute accent
230     'Icirc'     =>    'I\\*^',  # capital I, circumflex accent
231     'icirc'     =>    'i\\*^',  # small i, circumflex accent
232     'Igrave'    =>    'I\\*`',  # capital I, grave accent
233     'igrave'    =>    'i\\*`',  # small i, grave accent
234     'Iuml'      =>    'I\\*:',  # capital I, dieresis or umlaut mark
235     'iuml'      =>    'i\\*:',  # small i, dieresis or umlaut mark
236     'Ntilde'    =>    'N\*~',   # capital N, tilde
237     'ntilde'    =>    'n\*~',   # small n, tilde
238     'Oacute'    =>    "O\\*'",  # capital O, acute accent
239     'oacute'    =>    "o\\*'",  # small o, acute accent
240     'Ocirc'     =>    'O\\*^',  # capital O, circumflex accent
241     'ocirc'     =>    'o\\*^',  # small o, circumflex accent
242     'Ograve'    =>    'O\\*`',  # capital O, grave accent
243     'ograve'    =>    'o\\*`',  # small o, grave accent
244     'Oslash'    =>    'O\\*/',  # capital O, slash
245     'oslash'    =>    'o\\*/',  # small o, slash
246     'Otilde'    =>    'O\\*~',  # capital O, tilde
247     'otilde'    =>    'o\\*~',  # small o, tilde
248     'Ouml'      =>    'O\\*:',  # capital O, dieresis or umlaut mark
249     'ouml'      =>    'o\\*:',  # small o, dieresis or umlaut mark
250     'szlig'     =>    '\*8',    # small sharp s, German (sz ligature)
251     'THORN'     =>    '\\*(Th', # capital THORN, Icelandic
252     'thorn'     =>    '\\*(th', # small thorn, Icelandic
253     'Uacute'    =>    "U\\*'",  # capital U, acute accent
254     'uacute'    =>    "u\\*'",  # small u, acute accent
255     'Ucirc'     =>    'U\\*^',  # capital U, circumflex accent
256     'ucirc'     =>    'u\\*^',  # small u, circumflex accent
257     'Ugrave'    =>    'U\\*`',  # capital U, grave accent
258     'ugrave'    =>    'u\\*`',  # small u, grave accent
259     'Uuml'      =>    'U\\*:',  # capital U, dieresis or umlaut mark
260     'uuml'      =>    'u\\*:',  # small u, dieresis or umlaut mark
261     'Yacute'    =>    "Y\\*'",  # capital Y, acute accent
262     'yacute'    =>    "y\\*'",  # small y, acute accent
263     'yuml'      =>    'y\\*:',  # small y, dieresis or umlaut mark
264 );
265
266
267 ############################################################################
268 # Static helper functions
269 ############################################################################
270
271 # Protect leading quotes and periods against interpretation as commands.
272 # Also protect anything starting with a backslash, since it could expand
273 # or hide something that *roff would interpret as a command.  This is
274 # overkill, but it's much simpler than trying to parse *roff here.
275 sub protect {
276     local $_ = shift;
277     s/^([.\'\\])/\\&$1/mg;
278     $_;
279 }
280                     
281 # Given a command and a single argument that may or may not contain double
282 # quotes, handle double-quote formatting for it.  If there are no double
283 # quotes, just return the command followed by the argument in double quotes.
284 # If there are double quotes, use an if statement to test for nroff, and for
285 # nroff output the command followed by the argument in double quotes with
286 # embedded double quotes doubled.  For other formatters, remap paired double
287 # quotes to `` and ''.
288 sub switchquotes {
289     my $command = shift;
290     local $_ = shift;
291     my $extra = shift;
292     s/\\\*\([LR]\"/\"/g;
293     if (/\"/) {
294         s/\"/\"\"/g;
295         my $troff = $_;
296         $troff =~ s/\"\"([^\"]*)\"\"/\`\`$1\'\'/g;
297         s/\"/\"\"/g if $extra;
298         $troff =~ s/\"/\"\"/g if $extra;
299         $_ = qq("$_") . ($extra ? " $extra" : '');
300         $troff = qq("$troff") . ($extra ? " $extra" : '');
301         return ".if n $command $_\n.el $command $troff\n";
302     } else {
303         $_ = qq("$_") . ($extra ? " $extra" : '');
304         return "$command $_\n";
305     }
306 }
307
308 # Translate a font string into an escape.
309 sub toescape { (length ($_[0]) > 1 ? '\f(' : '\f') . $_[0] }
310
311                     
312 ############################################################################
313 # Initialization
314 ############################################################################
315
316 # Initialize the object.  Here, we also process any additional options
317 # passed to the constructor or set up defaults if none were given.  center
318 # is the centered title, release is the version number, and date is the date
319 # for the documentation.  Note that we can't know what file name we're
320 # processing due to the architecture of Pod::Parser, so that *has* to either
321 # be passed to the constructor or set separately with Pod::Man::name().
322 sub initialize {
323     my $self = shift;
324
325     # Figure out the fixed-width font.  If user-supplied, make sure that
326     # they are the right length.
327     for (qw/fixed fixedbold fixeditalic fixedbolditalic/) {
328         if (defined $$self{$_}) {
329             if (length ($$self{$_}) < 1 || length ($$self{$_}) > 2) {
330                 croak qq(roff font should be 1 or 2 chars,)
331                     . qq( not "$$self{$_}");
332             }
333         } else {
334             $$self{$_} = '';
335         }
336     }
337
338     # Set the default fonts.  We can't be sure what fixed bold-italic is
339     # going to be called, so default to just bold.
340     $$self{fixed}           ||= 'CW';
341     $$self{fixedbold}       ||= 'CB';
342     $$self{fixeditalic}     ||= 'CI';
343     $$self{fixedbolditalic} ||= 'CB';
344
345     # Set up a table of font escapes.  First number is fixed-width, second
346     # is bold, third is italic.
347     $$self{FONTS} = { '000' => '\fR', '001' => '\fI',
348                       '010' => '\fB', '011' => '\f(BI',
349                       '100' => toescape ($$self{fixed}),
350                       '101' => toescape ($$self{fixeditalic}),
351                       '110' => toescape ($$self{fixedbold}),
352                       '111' => toescape ($$self{fixedbolditalic})};
353
354     # Extra stuff for page titles.
355     $$self{center} = 'User Contributed Perl Documentation'
356         unless defined $$self{center};
357     $$self{indent}  = 4 unless defined $$self{indent};
358
359     # We used to try first to get the version number from a local binary,
360     # but we shouldn't need that any more.  Get the version from the running
361     # Perl.  Work a little magic to handle subversions correctly under both
362     # the pre-5.6 and the post-5.6 version numbering schemes.
363     if (!defined $$self{release}) {
364         my @version = ($] =~ /^(\d+)\.(\d{3})(\d{0,3})$/);
365         $version[2] ||= 0;
366         $version[2] *= 10 ** (3 - length $version[2]);
367         for (@version) { $_ += 0 }
368         $$self{release} = 'perl v' . join ('.', @version);
369     }
370
371     # Double quotes in things that will be quoted.
372     for (qw/center date release/) {
373         $$self{$_} =~ s/\"/\"\"/g if $$self{$_};
374     }
375
376     # Figure out what quotes we'll be using for C<> text.
377     $$self{quotes} ||= "'";
378     if ($$self{quotes} eq 'none') {
379         $$self{LQUOTE} = $$self{RQUOTE} = '';
380     } elsif (length ($$self{quotes}) == 1) {
381         $$self{LQUOTE} = $$self{RQUOTE} = $$self{quotes};
382     } elsif ($$self{quotes} =~ /^(.)(.)$/
383              || $$self{quotes} =~ /^(..)(..)$/) {
384         $$self{LQUOTE} = $1;
385         $$self{RQUOTE} = $2;
386     } else {
387         croak qq(Invalid quote specification "$$self{quotes}");
388     }
389
390     # Double the first quote; note that this should not be s///g as two
391     # double quotes is represented in *roff as three double quotes, not
392     # four.  Weird, I know.
393     $$self{LQUOTE} =~ s/\"/\"\"/;
394     $$self{RQUOTE} =~ s/\"/\"\"/;
395
396     $$self{INDENT}  = 0;        # Current indentation level.
397     $$self{INDENTS} = [];       # Stack of indentations.
398     $$self{INDEX}   = [];       # Index keys waiting to be printed.
399
400     $self->SUPER::initialize;
401 }
402
403 # For each document we process, output the preamble first.
404 sub begin_pod {
405     my $self = shift;
406
407     # Try to figure out the name and section from the file name.
408     my $section = $$self{section} || 1;
409     my $name = $$self{name};
410     if (!defined $name) {
411         $name = $self->input_file;
412         $section = 3 if (!$$self{section} && $name =~ /\.pm\z/i);
413         $name =~ s/\.p(od|[lm])\z//i;
414         if ($section =~ /^1/) {
415             require File::Basename;
416             $name = uc File::Basename::basename ($name);
417         } else {
418             # Lose everything up to the first of
419             #     */lib/*perl*      standard or site_perl module
420             #     */*perl*/lib      from -D prefix=/opt/perl
421             #     */*perl*/         random module hierarchy
422             # which works.  Should be fixed to use File::Spec.  Also handle
423             # a leading lib/ since that's what ExtUtils::MakeMaker creates.
424             for ($name) {
425                 s%//+%/%g;
426                 if (     s%^.*?/lib/[^/]*perl[^/]*/%%si
427                       or s%^.*?/[^/]*perl[^/]*/(?:lib/)?%%si) {
428                     s%^site(_perl)?/%%s;      # site and site_perl
429                     s%^(.*-$^O|$^O-.*)/%%so;  # arch
430                     s%^\d+\.\d+%%s;           # version
431                 }
432                 s%^lib/%%;
433                 s%/%::%g;
434             }
435         }
436     }
437
438     # Modification date header.  Try to use the modification time of our
439     # input.
440     if (!defined $$self{date}) {
441         my $time = (stat $self->input_file)[9] || time;
442         my ($day, $month, $year) = (localtime $time)[3,4,5];
443         $month++;
444         $year += 1900;
445         $$self{date} = sprintf ('%4d-%02d-%02d', $year, $month, $day);
446     }
447
448     # Now, print out the preamble and the title.
449     local $_ = $PREAMBLE;
450     s/\@CFONT\@/$$self{fixed}/;
451     s/\@LQUOTE\@/$$self{LQUOTE}/;
452     s/\@RQUOTE\@/$$self{RQUOTE}/;
453     chomp $_;
454     print { $self->output_handle } <<"----END OF HEADER----";
455 .\\" Automatically generated by Pod::Man version $VERSION
456 .\\" @{[ scalar localtime ]}
457 .\\"
458 .\\" Standard preamble:
459 .\\" ======================================================================
460 $_
461 .\\" ======================================================================
462 .\\"
463 .IX Title "$name $section"
464 .TH $name $section "$$self{release}" "$$self{date}" "$$self{center}"
465 .UC
466 ----END OF HEADER----
467 #"# for cperl-mode
468
469     # Initialize a few per-file variables.
470     $$self{INDENT} = 0;
471     $$self{NEEDSPACE} = 0;
472 }
473
474
475 ############################################################################
476 # Core overrides
477 ############################################################################
478
479 # Called for each command paragraph.  Gets the command, the associated
480 # paragraph, the line number, and a Pod::Paragraph object.  Just dispatches
481 # the command to a method named the same as the command.  =cut is handled
482 # internally by Pod::Parser.
483 sub command {
484     my $self = shift;
485     my $command = shift;
486     return if $command eq 'pod';
487    return if ($$self{EXCLUDE} && $command ne 'end');
488     if ($self->can ('cmd_' . $command)) {
489         $command = 'cmd_' . $command;
490         $self->$command (@_);
491      } else {
492         my ($text, $line, $paragraph) = @_;
493         my ($file, $line) = $paragraph->file_line;
494         $text =~ s/\n+\z//;
495         $text = " $text" if ($text =~ /^\S/);
496         warn qq($file:$line: Unknown command paragraph "=$command$text"\n);
497         return;
498     }
499 }
500
501 # Called for a verbatim paragraph.  Gets the paragraph, the line number, and
502 # a Pod::Paragraph object.  Rofficate backslashes, untabify, put a
503 # zero-width character at the beginning of each line to protect against
504 # commands, and wrap in .Vb/.Ve.
505 sub verbatim {
506     my $self = shift;
507     return if $$self{EXCLUDE};
508     local $_ = shift;
509     return if /^\s+$/;
510     s/\s+$/\n/;
511     my $lines = tr/\n/\n/;
512     1 while s/^(.*?)(\t+)/$1 . ' ' x (length ($2) * 8 - length ($1) % 8)/me;
513     s/\\/\\e/g;
514     s/^(\s*\S)/'\&' . $1/gme;
515     $self->makespace if $$self{NEEDSPACE};
516     $self->output (".Vb $lines\n$_.Ve\n");
517     $$self{NEEDSPACE} = 0;
518 }
519
520 # Called for a regular text block.  Gets the paragraph, the line number, and
521 # a Pod::Paragraph object.  Perform interpolation and output the results.
522 sub textblock {
523     my $self = shift;
524     return if $$self{EXCLUDE};
525     $self->output ($_[0]), return if $$self{VERBATIM};
526
527     # Perform a little magic to collapse multiple L<> references.  We'll
528     # just rewrite the whole thing into actual text at this part, bypassing
529     # the whole internal sequence parsing thing.
530     my $text = shift;
531     $text =~ s{
532         (L<                     # A link of the form L</something>.
533               /
534               (
535                   [:\w]+        # The item has to be a simple word...
536                   (\(\))?       # ...or simple function.
537               )
538           >
539           (
540               ,?\s+(and\s+)?    # Allow lots of them, conjuncted.
541               L<  
542                   /
543                   ( [:\w]+ ( \(\) )? )
544               >
545           )+
546         )
547     } {
548         local $_ = $1;
549         s{ L< / ( [^>]+ ) > } {$1}xg;
550         my @items = split /(?:,?\s+(?:and\s+)?)/;
551         my $string = 'the ';
552         my $i;
553         for ($i = 0; $i < @items; $i++) {
554             $string .= $items[$i];
555             $string .= ', ' if @items > 2 && $i != $#items;
556             $string .= ' ' if @items == 2 && $i == 2;
557             $string .= 'and ' if ($i == $#items - 1);
558         }
559         $string .= ' entries elsewhere in this document';
560         $string;
561     }gex;
562
563     # Parse the tree and output it.  collapse knows about references to
564     # scalars as well as scalars and does the right thing with them.
565     $text = $self->parse ($text, @_);
566     $text =~ s/\n\s*$/\n/;
567     $self->makespace if $$self{NEEDSPACE};
568     $self->output (protect $self->mapfonts ($text));
569     $self->outindex;
570     $$self{NEEDSPACE} = 1;
571 }
572
573 # Called for an interior sequence.  Takes a Pod::InteriorSequence object and
574 # returns a reference to a scalar.  This scalar is the final formatted text.
575 # It's returned as a reference so that other interior sequences above us
576 # know that the text has already been processed.
577 sub sequence {
578     my ($self, $seq) = @_;
579     my $command = $seq->cmd_name;
580
581     # Zero-width characters.
582     if ($command eq 'Z') {
583         # Workaround to generate a blessable reference, needed by 5.005.
584         my $tmp = '\&';
585         return bless \ "$tmp", 'Pod::Man::String';
586     }
587
588     # C<>, L<>, X<>, and E<> don't apply guesswork to their contents.  C<>
589     # needs some additional special handling.
590     my $literal = ($command =~ /^[CELX]$/);
591     $literal++ if $command eq 'C';
592     local $_ = $self->collapse ($seq->parse_tree, $literal);
593
594     # Handle E<> escapes.
595     if ($command eq 'E') {
596         if (/^\d+$/) {
597             return bless \ chr ($_), 'Pod::Man::String';
598         } elsif (exists $ESCAPES{$_}) {
599             return bless \ "$ESCAPES{$_}", 'Pod::Man::String';
600         } else {
601             carp "Unknown escape E<$1>";
602             return bless \ "E<$_>", 'Pod::Man::String';
603         }
604     }
605
606     # For all the other sequences, empty content produces no output.
607     return '' if $_ eq '';
608
609     # Handle formatting sequences.
610     if ($command eq 'B') {
611         return bless \ ('\f(BS' . $_ . '\f(BE'), 'Pod::Man::String';
612     } elsif ($command eq 'F') {
613         return bless \ ('\f(IS' . $_ . '\f(IE'), 'Pod::Man::String';
614     } elsif ($command eq 'I') {
615         return bless \ ('\f(IS' . $_ . '\f(IE'), 'Pod::Man::String';
616     } elsif ($command eq 'C') {
617         return bless \ ('\f(FS\*(C`' . $_ . "\\*(C'\\f(FE"),
618             'Pod::Man::String';
619     }
620
621     # Handle links.
622     if ($command eq 'L') {
623         # A bug in lvalue subs in 5.6 requires the temporary variable.
624         my $tmp = $self->buildlink ($_);
625         return bless \ "$tmp", 'Pod::Man::String';
626     }
627                          
628     # Whitespace protection replaces whitespace with "\ ".
629     if ($command eq 'S') {
630         s/\s+/\\ /g;
631         return bless \ "$_", 'Pod::Man::String';
632     }
633
634     # Add an index entry to the list of ones waiting to be output.
635     if ($command eq 'X') { push (@{ $$self{INDEX} }, $_); return '' }
636
637     # Anything else is unknown.
638     carp "Unknown sequence $command<$_>";
639 }
640
641
642 ############################################################################
643 # Command paragraphs
644 ############################################################################
645
646 # All command paragraphs take the paragraph and the line number.
647
648 # First level heading.  We can't output .IX in the NAME section due to a bug
649 # in some versions of catman, so don't output a .IX for that section.  .SH
650 # already uses small caps, so remove any E<> sequences that would cause
651 # them.
652 sub cmd_head1 {
653     my $self = shift;
654     local $_ = $self->parse (@_);
655     s/\s+$//;
656     s/\\s-?\d//g;
657     $self->output (switchquotes ('.SH', $self->mapfonts ($_)));
658     $self->outindex (($_ eq 'NAME') ? () : ('Header', $_));
659     $$self{NEEDSPACE} = 0;
660 }
661
662 # Second level heading.
663 sub cmd_head2 {
664     my $self = shift;
665     local $_ = $self->parse (@_);
666     s/\s+$//;
667     $self->output (switchquotes ('.Sh', $self->mapfonts ($_)));
668     $self->outindex ('Subsection', $_);
669     $$self{NEEDSPACE} = 0;
670 }
671
672 # Start a list.  For indents after the first, wrap the outside indent in .RS
673 # so that hanging paragraph tags will be correct.
674 sub cmd_over {
675     my $self = shift;
676     local $_ = shift;
677     unless (/^[-+]?\d+\s+$/) { $_ = $$self{indent} }
678     if (@{ $$self{INDENTS} } > 0) {
679         $self->output (".RS $$self{INDENT}\n");
680     }
681     push (@{ $$self{INDENTS} }, $$self{INDENT});
682     $$self{INDENT} = ($_ + 0);
683 }
684
685 # End a list.  If we've closed an embedded indent, we've mangled the hanging
686 # paragraph indent, so temporarily replace it with .RS and set WEIRDINDENT.
687 # We'll close that .RS at the next =back or =item.
688 sub cmd_back {
689     my $self = shift;
690     $$self{INDENT} = pop @{ $$self{INDENTS} };
691     unless (defined $$self{INDENT}) {
692         carp "Unmatched =back";
693         $$self{INDENT} = 0;
694     }
695     if ($$self{WEIRDINDENT}) {
696         $self->output (".RE\n");
697         $$self{WEIRDINDENT} = 0;
698     }
699     if (@{ $$self{INDENTS} } > 0) {
700         $self->output (".RE\n");
701         $self->output (".RS $$self{INDENT}\n");
702         $$self{WEIRDINDENT} = 1;
703     }
704     $$self{NEEDSPACE} = 1;
705 }
706
707 # An individual list item.  Emit an index entry for anything that's
708 # interesting, but don't emit index entries for things like bullets and
709 # numbers.  rofficate bullets too while we're at it (so for nice output, use
710 # * for your lists rather than o or . or - or some other thing).  Newlines
711 # in an item title are turned into spaces since *roff can't handle them
712 # embedded.
713 sub cmd_item {
714     my $self = shift;
715     local $_ = $self->parse (@_);
716     s/\s+$//;
717     s/\s*\n\s*/ /g;
718     my $index;
719     if (/\w/ && !/^\w[.\)]\s*$/) {
720         $index = $_;
721         $index =~ s/^\s*[-*+o.]?(?:\s+|\Z)//;
722     }
723     s/^\*(\s|\Z)/\\\(bu$1/;
724     if ($$self{WEIRDINDENT}) {
725         $self->output (".RE\n");
726         $$self{WEIRDINDENT} = 0;
727     }
728     $_ = $self->mapfonts ($_);
729     $self->output (switchquotes ('.Ip', $_, $$self{INDENT}));
730     $self->outindex ($index ? ('Item', $index) : ());
731     $$self{NEEDSPACE} = 0;
732 }
733
734 # Begin a block for a particular translator.  Setting VERBATIM triggers
735 # special handling in textblock().
736 sub cmd_begin {
737     my $self = shift;
738     local $_ = shift;
739     my ($kind) = /^(\S+)/ or return;
740     if ($kind eq 'man' || $kind eq 'roff') {
741         $$self{VERBATIM} = 1;
742     } else {
743         $$self{EXCLUDE} = 1;
744     }
745 }
746
747 # End a block for a particular translator.  We assume that all =begin/=end
748 # pairs are properly closed.
749 sub cmd_end {
750     my $self = shift;
751     $$self{EXCLUDE} = 0;
752     $$self{VERBATIM} = 0;
753 }
754
755 # One paragraph for a particular translator.  Ignore it unless it's intended
756 # for man or roff, in which case we output it verbatim.
757 sub cmd_for {
758     my $self = shift;
759     local $_ = shift;
760     return unless s/^(?:man|roff)\b[ \t]*\n?//;
761     $self->output ($_);
762 }
763
764
765 ############################################################################
766 # Link handling
767 ############################################################################
768
769 # Handle links.  We can't actually make real hyperlinks, so this is all to
770 # figure out what text and formatting we print out.
771 sub buildlink {
772     my $self = shift;
773     local $_ = shift;
774
775     # Smash whitespace in case we were split across multiple lines.
776     s/\s+/ /g;
777
778     # If we were given any explicit text, just output it.
779     if (m{ ^ ([^|]+) \| }x) { return $1 }
780
781     # Okay, leading and trailing whitespace isn't important.
782     s/^\s+//;
783     s/\s+$//;
784
785     # Default to using the whole content of the link entry as a section
786     # name.  Note that L<manpage/> forces a manpage interpretation, as does
787     # something looking like L<manpage(section)>.  Do the same thing to
788     # L<manpage(section)> as we would to manpage(section) without the L<>;
789     # see guesswork().  If we've added italics, don't add the "manpage"
790     # text; markup is sufficient.
791     my ($manpage, $section) = ('', $_);
792     if (/^"\s*(.*?)\s*"$/) {
793         $section = '"' . $1 . '"';
794     } elsif (m{ ^ [-:.\w]+ (?: \( \S+ \) )? $ }x) {
795         ($manpage, $section) = ($_, '');
796         $manpage =~ s/^([^\(]+)\(/'\f(IS' . $1 . '\f(IE\|('/e;
797     } elsif (m%/%) {
798         ($manpage, $section) = split (/\s*\/\s*/, $_, 2);
799         if ($manpage =~ /^[-:.\w]+(?:\(\S+\))?$/) {
800             $manpage =~ s/^([^\(]+)\(/'\f(IS' . $1 . '\f(IE\|'/e;
801         }
802         $section =~ s/^\"\s*//;
803         $section =~ s/\s*\"$//;
804     }
805     if ($manpage && $manpage !~ /\\f\(IS/) {
806         $manpage = "the $manpage manpage";
807     }
808
809     # Now build the actual output text.
810     my $text = '';
811     if (!length ($section) && !length ($manpage)) {
812         carp "Invalid link $_";
813     } elsif (!length ($section)) {
814         $text = $manpage;
815     } elsif ($section =~ /^[:\w]+(?:\(\))?/) {
816         $text .= 'the ' . $section . ' entry';
817         $text .= (length $manpage) ? " in $manpage"
818                                    : " elsewhere in this document";
819     } else {
820         if ($section !~ /^".*"$/) { $section = '"' . $section . '"' }
821         $text .= 'the section on ' . $section;
822         $text .= " in $manpage" if length $manpage;
823     }
824     $text;
825 }
826
827
828 ############################################################################
829 # Escaping and fontification
830 ############################################################################
831
832 # At this point, we'll have embedded font codes of the form \f(<font>[SE]
833 # where <font> is one of B, I, or F.  Turn those into the right font start
834 # or end codes.  B<someI<thing> else> should map to \fBsome\f(BIthing\fB
835 # else\fR.  The old pod2man didn't get this right; the second \fB was \fR,
836 # so nested sequences didn't work right.  We take care of this by using
837 # variables as a combined pointer to our current font sequence, and set each
838 # to the number of current nestings of start tags for that font.  Use them
839 # as a vector to look up what font sequence to use.
840 sub mapfonts {
841     my $self = shift;
842     local $_ = shift;
843
844     my ($fixed, $bold, $italic) = (0, 0, 0);
845     my %magic = (F => \$fixed, B => \$bold, I => \$italic);
846     s { \\f\((.)(.) } {
847         ${ $magic{$1} } += ($2 eq 'S') ? 1 : -1;
848         $$self{FONTS}{($fixed && 1) . ($bold && 1) . ($italic && 1)};
849     }gxe;
850     $_;
851 }
852
853
854 ############################################################################
855 # *roff-specific parsing
856 ############################################################################
857
858 # Called instead of parse_text, calls parse_text with the right flags.
859 sub parse {
860     my $self = shift;
861     $self->parse_text ({ -expand_seq   => 'sequence',
862                          -expand_ptree => 'collapse' }, @_);
863 }
864     
865 # Takes a parse tree and a flag saying whether or not to treat it as literal
866 # text (not call guesswork on it), and returns the concatenation of all of
867 # the text strings in that parse tree.  If the literal flag isn't true,
868 # guesswork() will be called on all plain scalars in the parse tree.
869 # Otherwise, just escape backslashes in the normal case.  If collapse is
870 # being called on a C<> sequence, literal is set to 2, and we do some
871 # additional cleanup.  Assumes that everything in the parse tree is either a
872 # scalar or a reference to a scalar.
873 sub collapse {
874     my ($self, $ptree, $literal) = @_;
875     if ($literal) {
876         return join ('', map {
877             if (ref $_) {
878                 $$_;
879             } else {
880                 s/\\/\\e/g;
881                 s/-/\\-/g    if $literal > 1;
882                 s/__/_\\|_/g if $literal > 1;
883                 $_;
884             }
885         } $ptree->children);
886     } else {
887         return join ('', map {
888             ref ($_) ? $$_ : $self->guesswork ($_)
889         } $ptree->children);
890     }
891 }
892
893 # Takes a text block to perform guesswork on; this is guaranteed not to
894 # contain any interior sequences.  Returns the text block with remapping
895 # done.
896 sub guesswork {
897     my $self = shift;
898     local $_ = shift;
899
900     # rofficate backslashes.
901     s/\\/\\e/g;
902
903     # Ensure double underbars have a tiny space between them.
904     s/__/_\\|_/g;
905
906     # Make all caps a little smaller.  Be careful here, since we don't want
907     # to make @ARGV into small caps, nor do we want to fix the MIME in
908     # MIME-Version, since it looks weird with the full-height V.
909     s{
910         ( ^ | [\s\(\"\'\`\[\{<>] )
911         ( [A-Z] [A-Z] [/A-Z+:\d_\$&-]* )
912         (?: (?= [\s>\}\]\)\'\".?!,;:] | -- ) | $ )
913     } { $1 . '\s-1' . $2 . '\s0' }egx;
914
915     # Turn PI into a pretty pi.
916     s{ (?: \\s-1 | \b ) PI (?: \\s0 | \b ) } {\\*\(PI}gx;
917
918     # Italize functions in the form func().
919     s{
920         \b
921         (
922             [:\w]+ (?:\\s-1)? \(\)
923         )
924     } { '\f(IS' . $1 . '\f(IE' }egx;
925
926     # func(n) is a reference to a manual page.  Make it \fIfunc\fR\|(n).
927     s{
928         \b
929         (\w[-:.\w]+ (?:\\s-1)?)
930         (
931             \( [^\)] \)
932         )
933     } { '\f(IS' . $1 . '\f(IE\|' . $2 }egx;
934
935     # Convert simple Perl variable references to a fixed-width font.
936     s{
937         ( \s+ )
938         ( [\$\@%] [\w:]+ )
939         (?! \( )
940     } { $1 . '\f(FS' . $2 . '\f(FE'}egx;
941
942     # Translate -- into a real em dash if it's used like one and fix up
943     # dashes, but keep hyphens hyphens.
944     s{ (\G|^|.) (-+) (\b|.) } {
945         my ($pre, $dash, $post) = ($1, $2, $3);
946         if (length ($dash) == 1) {
947             ($pre =~ /[a-zA-Z]/) ? "$pre-$post" : "$pre\\-$post";
948         } elsif (length ($dash) == 2
949                  && ((!$pre && !$post)
950                      || ($pre =~ /\w/ && !$post)
951                      || ($pre eq ' ' && $post eq ' ')
952                      || ($pre eq '=' && $post ne '=')
953                      || ($pre ne '=' && $post eq '='))) {
954             "$pre\\*(--$post";
955         } else {
956             $pre . ('\-' x length $dash) . $post;
957         }
958     }egxs;
959
960     # Fix up double quotes.
961     s{ \" ([^\"]+) \" } { '\*(L"' . $1 . '\*(R"' }egx;
962
963     # Make C++ into \*(C+, which is a squinched version.
964     s{ \b C\+\+ } {\\*\(C+}gx;
965
966     # All done.
967     $_;
968 }
969
970
971 ############################################################################
972 # Output formatting
973 ############################################################################
974
975 # Make vertical whitespace.
976 sub makespace {
977     my $self = shift;
978     $self->output ($$self{INDENT} > 0 ? ".Sp\n" : ".PP\n");
979 }
980
981 # Output any pending index entries, and optionally an index entry given as
982 # an argument.  Support multiple index entries in X<> separated by slashes,
983 # and strip special escapes from index entries.
984 sub outindex {
985     my ($self, $section, $index) = @_;
986     my @entries = map { split m%\s*/\s*% } @{ $$self{INDEX} };
987     return unless ($section || @entries);
988     $$self{INDEX} = [];
989     my $output;
990     if (@entries) {
991         my $output = '.IX Xref "'
992             . join (' ', map { s/\"/\"\"/; $_ } @entries)
993             . '"' . "\n";
994     }
995     if ($section) {
996         $index =~ s/\"/\"\"/;
997         $index =~ s/\\-/-/g;
998         $index =~ s/\\(?:s-?\d|.\(..|.)//g;
999         $output .= ".IX $section " . '"' . $index . '"' . "\n";
1000     }
1001     $self->output ($output);
1002 }
1003
1004 # Output text to the output device.
1005 sub output { print { $_[0]->output_handle } $_[1] }
1006
1007 __END__
1008
1009 .\" These are some extra bits of roff that I don't want to lose track of
1010 .\" but that have been removed from the preamble to make it a bit shorter
1011 .\" since they're not currently being used.  They're accents and special
1012 .\" characters we don't currently have escapes for.
1013 .if n \{\
1014 .    ds ? ?
1015 .    ds ! !
1016 .    ds q
1017 .\}
1018 .if t \{\
1019 .    ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
1020 .    ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
1021 .    ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
1022 .\}
1023 .ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
1024 .ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
1025 .ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
1026 .ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
1027 .ds oe o\h'-(\w'o'u*4/10)'e
1028 .ds Oe O\h'-(\w'O'u*4/10)'E
1029 .if \n(.H>23 .if \n(.V>19 \
1030 \{\
1031 .    ds v \h'-1'\o'\(aa\(ga'
1032 .    ds _ \h'-1'^
1033 .    ds . \h'-1'.
1034 .    ds 3 3
1035 .    ds oe oe
1036 .    ds Oe OE
1037 .\}
1038
1039 ############################################################################
1040 # Documentation
1041 ############################################################################
1042
1043 =head1 NAME
1044
1045 Pod::Man - Convert POD data to formatted *roff input
1046
1047 =head1 SYNOPSIS
1048
1049     use Pod::Man;
1050     my $parser = Pod::Man->new (release => $VERSION, section => 8);
1051
1052     # Read POD from STDIN and write to STDOUT.
1053     $parser->parse_from_filehandle;
1054
1055     # Read POD from file.pod and write to file.1.
1056     $parser->parse_from_file ('file.pod', 'file.1');
1057
1058 =head1 DESCRIPTION
1059
1060 Pod::Man is a module to convert documentation in the POD format (the
1061 preferred language for documenting Perl) into *roff input using the man
1062 macro set.  The resulting *roff code is suitable for display on a terminal
1063 using nroff(1), normally via man(1), or printing using troff(1).  It is
1064 conventionally invoked using the driver script B<pod2man>, but it can also
1065 be used directly.
1066
1067 As a derived class from Pod::Parser, Pod::Man supports the same methods and
1068 interfaces.  See L<Pod::Parser> for all the details; briefly, one creates a
1069 new parser with C<Pod::Man-E<gt>new()> and then calls either
1070 parse_from_filehandle() or parse_from_file().
1071
1072 new() can take options, in the form of key/value pairs that control the
1073 behavior of the parser.  See below for details.
1074
1075 If no options are given, Pod::Man uses the name of the input file with any
1076 trailing C<.pod>, C<.pm>, or C<.pl> stripped as the man page title, to
1077 section 1 unless the file ended in C<.pm> in which case it defaults to
1078 section 3, to a centered title of "User Contributed Perl Documentation", to
1079 a centered footer of the Perl version it is run with, and to a left-hand
1080 footer of the modification date of its input (or the current date if given
1081 STDIN for input).
1082
1083 Pod::Man assumes that your *roff formatters have a fixed-width font named
1084 CW.  If yours is called something else (like CR), use the C<fixed> option to
1085 specify it.  This generally only matters for troff output for printing.
1086 Similarly, you can set the fonts used for bold, italic, and bold italic
1087 fixed-width output.
1088
1089 Besides the obvious pod conversions, Pod::Man also takes care of formatting
1090 func(), func(n), and simple variable references like $foo or @bar so you
1091 don't have to use code escapes for them; complex expressions like
1092 C<$fred{'stuff'}> will still need to be escaped, though.  It also translates
1093 dashes that aren't used as hyphens into en dashes, makes long dashes--like
1094 this--into proper em dashes, fixes "paired quotes," makes C++ and PI look
1095 right, puts a little space between double underbars, makes ALLCAPS a teeny
1096 bit smaller in troff(1), and escapes stuff that *roff treats as special so
1097 that you don't have to.
1098
1099 The recognized options to new() are as follows.  All options take a single
1100 argument.
1101
1102 =over 4
1103
1104 =item center
1105
1106 Sets the centered page header to use instead of "User Contributed Perl
1107 Documentation".
1108
1109 =item date
1110
1111 Sets the left-hand footer.  By default, the modification date of the input
1112 file will be used, or the current date if stat() can't find that file (the
1113 case if the input is from STDIN), and the date will be formatted as
1114 YYYY-MM-DD.
1115
1116 =item fixed
1117
1118 The fixed-width font to use for vertabim text and code.  Defaults to CW.
1119 Some systems may want CR instead.  Only matters for troff(1) output.
1120
1121 =item fixedbold
1122
1123 Bold version of the fixed-width font.  Defaults to CB.  Only matters for
1124 troff(1) output.
1125
1126 =item fixeditalic
1127
1128 Italic version of the fixed-width font (actually, something of a misnomer,
1129 since most fixed-width fonts only have an oblique version, not an italic
1130 version).  Defaults to CI.  Only matters for troff(1) output.
1131
1132 =item fixedbolditalic
1133
1134 Bold italic (probably actually oblique) version of the fixed-width font.
1135 Pod::Man doesn't assume you have this, and defaults to CB.  Some systems
1136 (such as Solaris) have this font available as CX.  Only matters for troff(1)
1137 output.
1138
1139 =item quotes
1140
1141 Sets the quote marks used to surround CE<lt>> text.  If the value is a
1142 single character, it is used as both the left and right quote; if it is two
1143 characters, the first character is used as the left quote and the second as
1144 the right quoted; and if it is four characters, the first two are used as
1145 the left quote and the second two as the right quote.
1146
1147 This may also be set to the special value C<none>, in which case no quote
1148 marks are added around CE<lt>> text (but the font is still changed for troff
1149 output).
1150
1151 =item release
1152
1153 Set the centered footer.  By default, this is the version of Perl you run
1154 Pod::Man under.  Note that some system an macro sets assume that the
1155 centered footer will be a modification date and will prepend something like
1156 "Last modified: "; if this is the case, you may want to set C<release> to
1157 the last modified date and C<date> to the version number.
1158
1159 =item section
1160
1161 Set the section for the C<.TH> macro.  The standard section numbering
1162 convention is to use 1 for user commands, 2 for system calls, 3 for
1163 functions, 4 for devices, 5 for file formats, 6 for games, 7 for
1164 miscellaneous information, and 8 for administrator commands.  There is a lot
1165 of variation here, however; some systems (like Solaris) use 4 for file
1166 formats, 5 for miscellaneous information, and 7 for devices.  Still others
1167 use 1m instead of 8, or some mix of both.  About the only section numbers
1168 that are reliably consistent are 1, 2, and 3.
1169
1170 By default, section 1 will be used unless the file ends in .pm in which case
1171 section 3 will be selected.
1172
1173 =back
1174
1175 The standard Pod::Parser method parse_from_filehandle() takes up to two
1176 arguments, the first being the file handle to read POD from and the second
1177 being the file handle to write the formatted output to.  The first defaults
1178 to STDIN if not given, and the second defaults to STDOUT.  The method
1179 parse_from_file() is almost identical, except that its two arguments are the
1180 input and output disk files instead.  See L<Pod::Parser> for the specific
1181 details.
1182
1183 =head1 DIAGNOSTICS
1184
1185 =over 4
1186
1187 =item roff font should be 1 or 2 chars, not "%s"
1188
1189 (F) You specified a *roff font (using C<fixed>, C<fixedbold>, etc.) that
1190 wasn't either one or two characters.  Pod::Man doesn't support *roff fonts
1191 longer than two characters, although some *roff extensions do (the canonical
1192 versions of nroff(1) and troff(1) don't either).
1193
1194 =item Invalid link %s
1195
1196 (W) The POD source contained a C<LE<lt>E<gt>> sequence that Pod::Man was
1197 unable to parse.  You should never see this error message; it probably
1198 indicates a bug in Pod::Man.
1199
1200 =item Invalid quote specification "%s"
1201
1202 (F) The quote specification given (the quotes option to the constructor) was
1203 invalid.  A quote specification must be one, two, or four characters long.
1204
1205 =item %s:%d: Unknown command paragraph "%s".
1206
1207 (W) The POD source contained a non-standard command paragraph (something of
1208 the form C<=command args>) that Pod::Man didn't know about.  It was ignored.
1209
1210 =item Unknown escape EE<lt>%sE<gt>
1211
1212 (W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::Man didn't
1213 know about.  C<EE<lt>%sE<gt>> was printed verbatim in the output.
1214
1215 =item Unknown sequence %s
1216
1217 (W) The POD source contained a non-standard interior sequence (something of
1218 the form C<XE<lt>E<gt>>) that Pod::Man didn't know about.  It was ignored.
1219
1220 =item %s: Unknown command paragraph "%s" on line %d.
1221
1222 (W) The POD source contained a non-standard command paragraph (something of
1223 the form C<=command args>) that Pod::Man didn't know about. It was ignored.
1224
1225 =item Unmatched =back
1226
1227 (W) Pod::Man encountered a C<=back> command that didn't correspond to an
1228 C<=over> command.
1229
1230 =back
1231
1232 =head1 BUGS
1233
1234 The lint-like features and strict POD format checking done by B<pod2man> are
1235 not yet implemented and should be, along with the corresponding C<lax>
1236 option.
1237
1238 The NAME section should be recognized specially and index entries emitted
1239 for everything in that section.  This would have to be deferred until the
1240 next section, since extraneous things in NAME tends to confuse various man
1241 page processors.
1242
1243 The handling of hyphens, en dashes, and em dashes is somewhat fragile, and
1244 one may get the wrong one under some circumstances.  This should only matter
1245 for troff(1) output.
1246
1247 When and whether to use small caps is somewhat tricky, and Pod::Man doesn't
1248 necessarily get it right.
1249
1250 Pod::Man doesn't handle font names longer than two characters.  Neither do
1251 most troff(1) implementations, but GNU troff does as an extension.  It would
1252 be nice to support as an option for those who want to use it.
1253
1254 The preamble added to each output file is rather verbose, and most of it is
1255 only necessary in the presence of EE<lt>E<gt> escapes for non-ASCII
1256 characters.  It would ideally be nice if all of those definitions were only
1257 output if needed, perhaps on the fly as the characters are used.
1258
1259 Some of the automagic applied to file names assumes Unix directory
1260 separators.
1261
1262 Pod::Man is excessively slow.
1263
1264 =head1 SEE ALSO
1265
1266 L<Pod::Parser|Pod::Parser>, perlpod(1), pod2man(1), nroff(1), troff(1),
1267 man(1), man(7)
1268
1269 Ossanna, Joseph F., and Brian W. Kernighan.  "Troff User's Manual,"
1270 Computing Science Technical Report No. 54, AT&T Bell Laboratories.  This is
1271 the best documentation of standard nroff(1) and troff(1).  At the time of
1272 this writing, it's available at http://www.cs.bell-labs.com/cm/cs/cstr.html.
1273
1274 The man page documenting the man macro set may be man(5) instead of man(7)
1275 on your system.  Also, please see pod2man(1) for extensive documentation on
1276 writing manual pages if you've not done it before and aren't familiar with
1277 the conventions.
1278
1279 =head1 AUTHOR
1280
1281 Russ Allbery E<lt>rra@stanford.eduE<gt>, based I<very> heavily on the
1282 original B<pod2man> by Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>.
1283
1284 =cut