Upgrade to Time::Local 1.16
[p5sagit/p5-mst-13.2.git] / lib / Pod / Man.pm
index 0ccbfbe..077bd7b 100644 (file)
@@ -1,7 +1,7 @@
 # Pod::Man -- Convert POD data to formatted *roff input.
-# $Id: Man.pm,v 2.4 2005/03/19 19:40:01 eagle Exp $
+# $Id: Man.pm,v 2.12 2006-09-16 20:55:41 eagle Exp $
 #
-# Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
+# Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
 #     Russ Allbery <rra@stanford.edu>
 # Substantial contributions by Sean Burke <sburke@cpan.org>
 #
@@ -40,7 +40,7 @@ use POSIX qw(strftime);
 # Don't use the CVS revision as the version, since this module is also in Perl
 # core and too many things could munge CVS magic revision strings.  This
 # number should ideally be the same as the CVS revision in podlators, however.
-$VERSION = 2.04;
+$VERSION = '2.12';
 
 # Set the debugging level.  If someone has inserted a debug function into this
 # class already, use that.  Otherwise, use any Pod::Simple debug function
@@ -300,7 +300,7 @@ sub _handle_element_end {
         }
     } elsif ($self->can ("end_$method")) {
         my $method = 'end_' . $method;
-        $self->$method;
+        $self->$method ();
     } else {
         DEBUG > 2 and print "No $method end method, skipping\n";
     }
@@ -422,17 +422,17 @@ sub guesswork {
     DEBUG > 5 and print "   Guesswork called on [$_]\n";
 
     # By the time we reach this point, all hypens will be escaped by adding a
-    # backslash.  We want to do that escaping if they're part of regular words
-    # and there's only a single dash, since that's a real hyphen that *roff
-    # gets to consider a possible break point.  Make sure that a dash after
-    # the first character of a word stays non-breaking, however.
+    # backslash.  We want to undo that escaping if they're part of regular
+    # words and there's only a single dash, since that's a real hyphen that
+    # *roff gets to consider a possible break point.  Make sure that a dash
+    # after the first character of a word stays non-breaking, however.
     #
     # Note that this is not user-controllable; we pretty much have to do this
     # transformation or *roff will mangle the output in unacceptable ways.
     s{
-        ( (?:\G|^|\s) [a-zA-Z] ) ( \\- )?
-        ( (?: [a-zA-Z]+ \\-)+ )
-        ( [a-zA-Z]+ ) (?=\s|\Z|\\\ )
+        ( (?:\G|^|\s) [\(\"]* [a-zA-Z] ) ( \\- )?
+        ( (?: [a-zA-Z\']+ \\-)+ )
+        ( [a-zA-Z\']+ ) (?= [\)\".?!,;:]* (?:\s|\Z|\\\ ) )
         \b
     } {
         my ($prefix, $hyphen, $main, $suffix) = ($1, $2, $3, $4);
@@ -819,11 +819,18 @@ sub devise_title {
 
 # Determine the modification date and return that, properly formatted in ISO
 # format.  If we can't get the modification date of the input, instead use the
-# current time.
+# current time.  Pod::Simple returns a completely unuseful stringified file
+# handle as the source_filename for input from a file handle, so we have to
+# deal with that as well.
 sub devise_date {
     my ($self) = @_;
     my $input = $self->source_filename;
-    my $time = ($input ? (stat $input)[9] : time);
+    my $time;
+    if ($input) {
+        $time = (stat $input)[9] || time;
+    } else {
+        $time = time;
+    }
     return strftime ('%Y-%m-%d', localtime $time);
 }
 
@@ -875,6 +882,10 @@ $preamble
 .\\"
 .IX Title "$index"
 .TH $name $section "$date" "$$self{release}" "$$self{center}"
+.\\" For nroff, turn off justification.  Always turn off hyphenation; it makes
+.\\" way too many mistakes in technical documents.
+.if n .ad l
+.nh
 ----END OF HEADER----
     $self->output (".\\\" [End of preamble]\n") if DEBUG;
 }
@@ -1201,6 +1212,50 @@ sub cmd_item_text   { my $self = shift; $self->item_common ('text',   @_) }
 sub cmd_item_block  { my $self = shift; $self->item_common ('block',  @_) }
 
 ##############################################################################
+# Backward compatibility
+##############################################################################
+
+# Reset the underlying Pod::Simple object between calls to parse_from_file so
+# that the same object can be reused to convert multiple pages.
+sub parse_from_file {
+    my $self = shift;
+    $self->reinit;
+
+    # Fake the old cutting option to Pod::Parser.  This fiddings with internal
+    # Pod::Simple state and is quite ugly; we need a better approach.
+    if (ref ($_[0]) eq 'HASH') {
+        my $opts = shift @_;
+        if (defined ($$opts{-cutting}) && !$$opts{-cutting}) {
+            $$self{in_pod} = 1;
+            $$self{last_was_blank} = 1;
+        }
+    }
+
+    # Do the work.
+    my $retval = $self->SUPER::parse_from_file (@_);
+
+    # Flush output, since Pod::Simple doesn't do this.  Ideally we should also
+    # close the file descriptor if we had to open one, but we can't easily
+    # figure this out.
+    my $fh = $self->output_fh ();
+    my $oldfh = select $fh;
+    my $oldflush = $|;
+    $| = 1;
+    print $fh '';
+    $| = $oldflush;
+    select $oldfh;
+    return $retval;
+}
+
+# Pod::Simple failed to provide this backward compatibility function, so
+# implement it ourselves.  File handles are one of the inputs that
+# parse_from_file supports.
+sub parse_from_filehandle {
+    my $self = shift;
+    $self->parse_from_file (@_);
+}
+
+##############################################################################
 # Translation tables
 ##############################################################################
 
@@ -1268,11 +1323,11 @@ sub preamble_template {
 ..
 .\" Set up some character translations and predefined strings.  \*(-- will
 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote.  | will give a
-.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
-.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
-.\" expand to `' in nroff, nothing in troff, for use with C<>.
-.tr \(*W-|\(bv\*(Tr
+.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
+.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
 .ie n \{\
 .    ds -- \(*W-
@@ -1303,11 +1358,6 @@ sub preamble_template {
 .    rr F
 .\}
 .\"
-.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.hy 0
-.if n .na
-.\"
 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
 .    \" fudge factors for nroff and troff
@@ -1607,7 +1657,7 @@ mine).
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
+Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
 by Russ Allbery <rra@stanford.edu>.
 
 This program is free software; you may redistribute it and/or modify it