File: splitdoc

package info (click to toggle)
perl 5.24.1-3+deb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,716 kB
  • sloc: perl: 559,611; ansic: 293,886; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (95 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!./perl.static -w

#
# Split POD documentation out of base modules and remove auto-loaded
# subroutines
#

use strict;
use File::Find;
use File::Path;

my @args = @ARGV;
@ARGV = ();
find sub { push @ARGV, $File::Find::name if -f and /\.pm$/ }, @args;
die "$0: no modules under @args?\n" unless @ARGV;

$^I = '';
$/ = '';

my %auto;
my $in_pod;
my $pod;

while (<>)
{
    if ($in_pod ||= /^=\w/)
    {
	unless ($pod)
	{
	    my $file = $ARGV;
	    my $dir;
	    for ($file)
	    {
		s/\.pm$/.pod/;
		s/perl-base/perl-doc/;
		s!/usr/lib/([^/]*/)?perl!/usr/share/perl!;
		($dir) = m!(.*)/!;
	    }

	    mkpath $dir unless -d $dir;
	    open($pod, '>', $file)
		or die "$0: can't create $file ($!)\n";
	}

	if (/^=cut\n/)
	{
	    $in_pod = 0;
	}
	else
	{
	    print $pod $_;
	}
    }
    else
    {
	$auto{$ARGV}++ if /(use|require)\s+AutoLoader\b/;
	print;
    }
}
continue
{
    if (eof)
    {
	close ARGV;
	if ($pod)
	{
	    print $pod "=cut\n";
	    close $pod;
	    undef $pod;
	}

	$in_pod = 0;
    }
}

# strip everyting following __END__ in modules which use AutoLoader
$/ = "\n";
my $end;

exit unless @ARGV = keys %auto;

while (<>)
{
    print unless $end ||= /^__END__$/;
}
continue
{
    if (eof)
    {
	close ARGV;
	$end = 0;
    }
}

exit