This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
YA resync with mainstem, including VMS patches from others
[perl5.git] / pod / splitpod
index fd327d8..fd38e51 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
-use PerlDoc::Functions;
+use lib '../lib';  # If you haven't installed perl yet.
+use Pod::Functions;
 
 local $/ = '';
 
@@ -11,21 +12,33 @@ while (<>) {
 
     if (s/=item (\S+)/$1/) {
        #$cur = "POSIX::" . $1;
+       $next{$cur} = $1;
        $cur = $1;
        $syn{$cur} .= $_;
        next;
     } else { 
        #s,L</,L<POSIX/,g;
        s,L</,L<perlfunc/,g;
-       $pod{$cur} .= $_ if $cur;
+       push @{$pod{$cur}}, $_ if $cur;
     }
 } 
 
 for $f ( keys %syn ) {
-    $type = $Type{$f} || next;
+    next unless $Type{$f};
     $flavor = $Flavor{$f};
     $orig = $f;
     ($name = $f) =~ s/\W//g;
+
+    # deal with several functions sharing a description
+    $func = $orig;
+    $func = $next{$func} until $pod{$func};
+    my $body = join "", @{$pod{$func}};
+
+    # deal with unbalanced =over and =back cause by the split
+    my $has_over = $body =~ /^=over/;
+    my $has_back = $body =~ /^=back/;
+    $body =~ s/^=over\s*//m if $has_over and !$has_back;
+    $body =~ s/^=back\s*//m if $has_back and !$has_over;
     open (POD, "> $name.pod") || die "can't open $name.pod: $!";
     print POD <<EOF;
 =head1 NAME
@@ -38,7 +51,7 @@ $syn{$orig}
 
 =head1 DESCRIPTION
 
-$pod{$orig}
+$body
 
 EOF