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