Pod::Man should strip leading lib/ for module manpages (from
[p5sagit/p5-mst-13.2.git] / lib / Pod / Html.pm
index 9c7aab7..89e3d0f 100644 (file)
@@ -342,7 +342,7 @@ sub pod2html {
     } 
     $htmlfile = "-" unless $htmlfile;  # stdout
     $htmlroot = "" if $htmlroot eq "/";        # so we don't get a //
-    $htmldir =~ s#/$## ;                # so we don't get a //
+    $htmldir =~ s#/\z## ;               # so we don't get a //
     if (  $htmlroot eq ''
        && defined( $htmldir ) 
        && $htmldir ne ''
@@ -388,7 +388,7 @@ sub pod2html {
            } 
        }
     }
-    if (!$title and $podfile =~ /\.pod$/) {
+    if (!$title and $podfile =~ /\.pod\z/) {
        # probably a split pod so take first =head[12] as title
        for (my $i = 0; $i < @poddata; $i++) { 
            last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
@@ -400,7 +400,7 @@ sub pod2html {
        $title =~ s/\s*\(.*\)//;
     } else {
        warn "$0: no title for $podfile" unless $quiet;
-       $podfile =~ /^(.*)(\.[^.\/]+)?$/;
+       $podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
        $title = ($podfile eq "-" ? 'No Title' : $1);
        warn "using $title" if $verbose;
     }
@@ -802,7 +802,7 @@ sub scan_podpath {
            $dirname = $1;
            opendir(DIR, $dirname) ||
                die "$0: error opening directory $dirname: $!\n";
-           @files = grep(/(\.pod|\.pm)$/ && ! -d $_, readdir(DIR));
+           @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
            closedir(DIR);
 
            # scan each .pod and .pm file for =item directives
@@ -888,13 +888,13 @@ sub scan_dir {
            $pages{$_}  = "" unless defined $pages{$_};
            $pages{$_} .= "$dir/$_:";
            push(@subdirs, $_);
-       } elsif (/\.pod$/) {                                # .pod
-           s/\.pod$//;
+       } elsif (/\.pod\z/) {                               # .pod
+           s/\.pod\z//;
            $pages{$_}  = "" unless defined $pages{$_};
            $pages{$_} .= "$dir/$_.pod:";
            push(@pods, "$dir/$_.pod");
-       } elsif (/\.pm$/) {                                 # .pm
-           s/\.pm$//;
+       } elsif (/\.pm\z/) {                                # .pm
+           s/\.pm\z//;
            $pages{$_}  = "" unless defined $pages{$_};
            $pages{$_} .= "$dir/$_.pm:";
            push(@pods, "$dir/$_.pm");
@@ -974,7 +974,7 @@ sub scan_items {
     my($i, $item);
     local $_;
 
-    $pod =~ s/\.pod$//;
+    $pod =~ s/\.pod\z//;
     $pod .= ".html" if $pod;
 
     foreach $i (0..$#poddata) {
@@ -1351,17 +1351,19 @@ sub process_puretext {
        # skip space runs
        next if $word =~ /^\s*$/;
        # see if we can infer a link
-       if( $notinIS && $word =~ /^(\w+)\((.*)\)\W*$/ ) {
+       if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
            # has parenthesis so should have been a C<> ref
             ## try for a pagename (perlXXX(1))?
-            if( $2 =~ /^\d+$/ ){
+            my( $func, $args ) = ( $1, $2 );
+            if( $args =~ /^\d+$/ ){
                 my $url = page_sect( $word, '' );
                 if( defined $url ){
                     $word = "<A HREF=\"$url\">the $word manpage</A>";
                     next;
                 }
             }
-           $word = emit_C( $word );
+            ## try function name for a link, append tt'ed argument list
+            $word = emit_C( $func, '', "($args)");
 
 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
 ##      } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
@@ -1410,10 +1412,13 @@ sub process_text {
 
 sub process_text1($$;$$){
     my( $lev, $rstr, $func, $closing ) = @_;
-    $lev++ unless defined $func;
     my $res = '';
 
-    $func ||= '';
+    unless (defined $func) {
+       $func = '';
+       $lev++;
+    }
+
     if( $func eq 'B' ){
        # B<text> - boldface
        $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
@@ -1584,8 +1589,7 @@ sub process_text1($$;$$){
            return $res if !$3 && $lev > 1;
             if( $3 ){
                $res .= process_text1( $lev, $rstr, $3, closing $4 );
-           }
-
+           }
        }
        if( $lev == 1 ){
            $res .= pure_text( $$rstr );
@@ -1622,13 +1626,14 @@ sub go_ahead($$$){
 # emit_C - output result of C<text>
 #    $text is the depod-ed text
 #
-sub emit_C($;$){
-    my( $text, $nocode ) = @_;
+sub emit_C($;$$){
+    my( $text, $nocode, $args ) = @_;
+    $args = '' unless defined $args;
     my $res;
     my( $url, $fid ) = coderef( undef(), $text );
 
     # need HTML-safe text
-    my $linktext = html_escape( $text );
+    my $linktext = html_escape( "$text$args" );
 
     if( defined( $url ) &&
         (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
@@ -1693,7 +1698,7 @@ sub page_sect($$) {
        # this will only find one page. A better solution might be to produce
        # an intermediate page that is an index to all such pages.
        my $page_name = $page ;
-       $page_name =~ s,^.*/,, ;
+       $page_name =~ s,^.*/,,s ;
        if ( defined( $pages{ $page_name } ) && 
             $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/ 
           ) {
@@ -1752,7 +1757,7 @@ sub page_sect($$) {
        # for other kinds of links, like file:, ftp:, etc.
         my $url ;
         if (  $htmlfileurl ne '' ) {
-            $link = "$htmldir$link" if $link =~ m{^/};
+            $link = "$htmldir$link" if $link =~ m{^/}s;
             $url = relativize_url( $link, $htmlfileurl );
 # print( "  b: [$link,$htmlfileurl,$url]\n" );
        }
@@ -1930,7 +1935,7 @@ sub depod1($;$$){
       # skip to next begin of an interior sequence
       while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
          # recurse into its text
-         $res .= $1 . depod1( $rstr, $2, closing $3);
+         $res .= $1 . depod1( $rstr, $2, closing $3);
       }
       $res .= $$rstr;
   } elsif( $func eq 'E' ){
@@ -1946,7 +1951,7 @@ sub depod1($;$$){
   } else {
       # all others: either recurse into new function or
       # terminate at closing angle bracket
-      my $term = pattern $closing; 
+      my $term = pattern $closing;
       while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
          $res .= $1;
          last unless $3;