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