Commit | Line | Data |
---|---|---|
cb1a09d0 | 1 | #!/usr/bin/perl |
2 | ||
201e8cd6 | 3 | BEGIN { push @INC, '../lib' } # If you haven't installed perl yet. |
6ec7a3ca | 4 | use Pod::Functions; |
cb1a09d0 | 5 | |
6 | local $/ = ''; | |
7 | ||
8c98129f | 8 | $level = 0; |
9 | ||
cb1a09d0 | 10 | $cur = ''; |
11 | while (<>) { | |
12 | ||
13 | next unless /^=(?!cut)/ .. /^=cut/; | |
14 | ||
8c98129f | 15 | ++$level if /^=over/; |
16 | --$level if /^=back/; | |
17 | ||
18 | # Ignore items that are nested within other items, e.g. don't split on the | |
19 | # items nested within the pack() and sprintf() items in perlfunc.pod. | |
20 | if (/=item (\S+)/ and $level == 1) { | |
279b5f1a | 21 | my $item = $1; |
5b3c99c0 | 22 | s/=item //; |
279b5f1a | 23 | $next{$cur} = $item; |
24 | $cur = $item; | |
cb1a09d0 | 25 | $syn{$cur} .= $_; |
26 | next; | |
27 | } else { | |
cb1a09d0 | 28 | s,L</,L<perlfunc/,g; |
40d50c58 | 29 | push @{$pod{$cur}}, $_ if $cur; |
cb1a09d0 | 30 | } |
31 | } | |
32 | ||
33 | for $f ( keys %syn ) { | |
40d50c58 | 34 | next unless $Type{$f}; |
cb1a09d0 | 35 | $flavor = $Flavor{$f}; |
36 | $orig = $f; | |
37 | ($name = $f) =~ s/\W//g; | |
40d50c58 | 38 | |
39 | # deal with several functions sharing a description | |
40 | $func = $orig; | |
41 | $func = $next{$func} until $pod{$func}; | |
42 | my $body = join "", @{$pod{$func}}; | |
43 | ||
3e3baf6d | 44 | # deal with unbalanced =over and =back cause by the split |
3e3baf6d | 45 | my $has_over = $body =~ /^=over/; |
46 | my $has_back = $body =~ /^=back/; | |
47 | $body =~ s/^=over\s*//m if $has_over and !$has_back; | |
48 | $body =~ s/^=back\s*//m if $has_back and !$has_over; | |
cb1a09d0 | 49 | open (POD, "> $name.pod") || die "can't open $name.pod: $!"; |
50 | print POD <<EOF; | |
201e8cd6 | 51 | \=head1 NAME |
cb1a09d0 | 52 | |
53 | $orig - $flavor | |
54 | ||
201e8cd6 | 55 | \=head1 SYNOPSIS |
cb1a09d0 | 56 | |
57 | $syn{$orig} | |
58 | ||
201e8cd6 | 59 | \=head1 DESCRIPTION |
cb1a09d0 | 60 | |
3e3baf6d | 61 | $body |
cb1a09d0 | 62 | |
63 | EOF | |
64 | ||
65 | close POD; | |
66 | ||
67 | } |