make PPPort/harness build on VMS
[p5sagit/p5-mst-13.2.git] / lib / Pod / Html.pm
index 346495f..9586f8e 100644 (file)
@@ -3,16 +3,16 @@ use strict;
 require Exporter;
 
 use vars qw($VERSION @ISA @EXPORT);
-$VERSION = 1.03;
+$VERSION = 1.04;
 @ISA = qw(Exporter);
 @EXPORT = qw(pod2html htmlify);
 
 use Carp;
 use Config;
 use Cwd;
+use File::Spec;
 use File::Spec::Unix;
 use Getopt::Long;
-use Pod::Functions;
 
 use locale;    # make \w work right in non-ASCII lands
 
@@ -44,6 +44,12 @@ Pod::Html takes the following arguments:
 Adds "Back to Top" links in front of every HEAD1 heading (except for
 the first).  By default, no backlink are being generated.
 
+=item cachedir
+
+    --cachedir=name
+
+Creates the item and directory caches in the given directory.
+
 =item css
 
     --css=stylesheet
@@ -195,6 +201,8 @@ This program is distributed under the Artistic License.
 
 =cut
 
+my $cachedir = ".";            # The directory to which item and directory
+                               # caches will be written.
 my $cache_ext = $^O eq 'VMS' ? ".tmp" : ".x~~";
 my $dircache = "pod2htmd$cache_ext";
 my $itemcache = "pod2htmi$cache_ext";
@@ -213,7 +221,7 @@ my $htmlfileurl = "" ;              # The url that other files would use to
                                # other files.
 my $podfile = "";              # read from stdin by default
 my @podpath = ();              # list of directories containing library pods.
-my $podroot = ".";             # filesystem base directory from which all
+my $podroot = File::Spec->curdir;              # filesystem base directory from which all
                                #   relative paths in $podpath stem.
 my $css = '';                   # Cascading style sheet
 my $recurse = 1;               # recurse on subdirectories in $podpath.
@@ -260,7 +268,7 @@ $htmldir = "";              # The directory to which the html pages
 $htmlfile = "";                # write to stdout by default
 $podfile = "";         # read from stdin by default
 @podpath = ();         # list of directories containing library pods.
-$podroot = ".";                # filesystem base directory from which all
+$podroot = File::Spec->curdir;         # filesystem base directory from which all
                                #   relative paths in $podpath stem.
 $css = '';                   # Cascading style sheet
 $recurse = 1;          # recurse on subdirectories in $podpath.
@@ -301,12 +309,11 @@ $Is83=$^O eq 'dos';
 #
 sub clean_data($){
     my( $dataref ) = @_;
-    my $i;
-    for( $i = 0; $i <= $#$dataref; $i++ ){
+    for my $i ( 0..$#{$dataref} ) {
        ${$dataref}[$i] =~ s/\s+\Z//;
 
         # have a look for all-space lines
-       if( ${$dataref}[$i] =~ /^\s+$/m ){
+      if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
            my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
            splice( @$dataref, $i, 1, @chunks );
        }
@@ -377,7 +384,7 @@ sub pod2html {
     # put a title in the HTML file if one wasn't specified
     if ($title eq '') {
        TITLE_SEARCH: {
-           for (my $i = 0; $i < @poddata; $i++) { 
+           for my $i ( 0..$#poddata ) {
                if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
                    for my $para ( @poddata[$i, $i+1] ) { 
                        last TITLE_SEARCH
@@ -390,7 +397,7 @@ sub pod2html {
     }
     if (!$title and $podfile =~ /\.pod\z/) {
        # probably a split pod so take first =head[12] as title
-       for (my $i = 0; $i < @poddata; $i++) { 
+       for my $i ( 0..$#poddata ) {
            last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
        } 
        warn "adopted '$title' as title for $podfile\n"
@@ -420,7 +427,6 @@ END_OF_BLOCK
 <HTML>
 <HEAD>
 <TITLE>$title</TITLE>$csslink
-<LINK REV="made" HREF="mailto:$Config{perladmin}">
 </HEAD>
 
 <BODY>
@@ -492,6 +498,7 @@ END_OF_HEAD
        else {
            next if $ignore;
            next if @begin_stack && $begin_stack[-1] ne 'html';
+            print HTML and next if @begin_stack && $begin_stack[-1] eq 'html';
            my $text = $_;
            if( $text =~ /\A\s+/ ){
                process_pre( \$text );
@@ -566,9 +573,10 @@ $usage =<<END_OF_USAGE;
 Usage:  $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
            --podpath=<name>:...:<name> --podroot=<name>
            --libpods=<name>:...:<name> --recurse --verbose --index
-           --netscape --norecurse --noindex
+           --netscape --norecurse --noindex --cachedir=<name>
 
   --backlink     - set text for "back to top" links (default: none).
+  --cachedir     - directory for the item and directory cache files.
   --css          - stylesheet URL
   --flush        - flushes the item and directory caches.
   --[no]header   - produce block header/footer (default is no headers).
@@ -601,14 +609,15 @@ Usage:  $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
 END_OF_USAGE
 
 sub parse_command_line {
-    my ($opt_backlink,$opt_css,$opt_flush,$opt_header,$opt_help,$opt_htmldir,
-       $opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,$opt_netscape,
-       $opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,$opt_recurse,
-       $opt_title,$opt_verbose);
+    my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
+       $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
+       $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
+       $opt_recurse,$opt_title,$opt_verbose);
 
     unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
     my $result = GetOptions(
                            'backlink=s' => \$opt_backlink,
+                           'cachedir=s' => \$opt_cachedir,
                            'css=s'      => \$opt_css,
                            'flush'      => \$opt_flush,
                            'header!'    => \$opt_header,
@@ -636,6 +645,7 @@ sub parse_command_line {
     @libpods  = split(":", $opt_libpods) if defined $opt_libpods;
 
     $backlink = $opt_backlink if defined $opt_backlink;
+    $cachedir = $opt_cachedir if defined $opt_cachedir;
     $css      = $opt_css      if defined $opt_css;
     $header   = $opt_header   if defined $opt_header;
     $htmldir  = $opt_htmldir  if defined $opt_htmldir;
@@ -652,6 +662,8 @@ sub parse_command_line {
 
     warn "Flushing item and directory caches\n"
        if $opt_verbose && defined $opt_flush;
+    $dircache = "$cachedir/pod2htmd$cache_ext";
+    $itemcache = "$cachedir/pod2htmi$cache_ext";
     unlink($dircache, $itemcache) if defined $opt_flush;
 }
 
@@ -893,6 +905,10 @@ sub scan_dir {
            $pages{$_}  = "" unless defined $pages{$_};
            $pages{$_} .= "$dir/$_.pod:";
            push(@pods, "$dir/$_.pod");
+       } elsif (/\.html\z/) {                              # .html
+           s/\.html\z//;
+           $pages{$_}  = "" unless defined $pages{$_};
+           $pages{$_} .= "$dir/$_.pod:";
        } elsif (/\.pm\z/) {                                # .pm
            s/\.pm\z//;
            $pages{$_}  = "" unless defined $pages{$_};
@@ -1153,7 +1169,7 @@ sub process_cut {
 }
 
 #
-# process_pod - process a pod pod tag, thus stop ignoring pod directives
+# process_pod - process a pod tag, thus stop ignoring pod directives
 # until we see a corresponding cut.
 #
 sub process_pod {
@@ -1558,7 +1574,7 @@ sub process_text1($$;$$){
             warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
         }
 
-        # now we have an URL or just plain code
+        # now we have a URL or just plain code
         $$rstr = $linktext . '>' . $$rstr;
         if( defined( $url ) ){
             $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
@@ -1676,7 +1692,7 @@ sub dosify {
 }
 
 #
-# page_sect - make an URL from the text of a L<>
+# page_sect - make a URL from the text of a L<>
 #
 sub page_sect($$) {
     my( $page, $section ) = @_;