This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
First pass through the changelog to get the perldelta current.
[perl5.git] / pod / splitpod
... / ...
CommitLineData
1#!/usr/bin/perl
2
3BEGIN { push @INC, '../lib' } # If you haven't installed perl yet.
4use Pod::Functions;
5
6local $/ = '';
7
8$level = 0;
9
10$cur = '';
11while (<>) {
12
13 next unless /^=(?!cut)/ .. /^=cut/;
14
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) {
21 my $item = $1;
22 s/=item //;
23 $next{$cur} = $item;
24 $cur = $item;
25 $syn{$cur} .= $_;
26 next;
27 } else {
28 s,L</,L<perlfunc/,g;
29 push @{$pod{$cur}}, $_ if $cur;
30 }
31}
32
33for $f ( keys %syn ) {
34 next unless $Type{$f};
35 $flavor = $Flavor{$f};
36 $orig = $f;
37 ($name = $f) =~ s/\W//g;
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
44 # deal with unbalanced =over and =back cause by the split
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;
49 open (POD, "> $name.pod") || die "can't open $name.pod: $!";
50 print POD <<EOF;
51\=head1 NAME
52
53$orig - $flavor
54
55\=head1 SYNOPSIS
56
57$syn{$orig}
58
59\=head1 DESCRIPTION
60
61$body
62
63EOF
64
65 close POD;
66
67}