5 # make it clearer when we haven't run to completion, as we can be quite
6 # noisy when things are working ok
9 print STDERR "$0: ", @_;
10 print STDERR "\n" unless $_[-1] =~ /\n\z/;
11 print STDERR "ABORTED\n";
17 open my $fh, '<', $filename or my_die "Can't open $filename: $!";
23 my $fh = open_or_die($filename);
27 die "Can't read $filename: $!" unless defined $contents and close $fh;
32 my ($filename, $contents) = @_;
33 open my $fh, '>', $filename or die "Can't open $filename for writing: $!";
35 print $fh $contents or die "Can't write to $filename: $!";
36 close $fh or die "Can't close $filename: $!";
39 sub get_pod_metadata {
40 # Do we expect to find generated pods on disk?
41 my $permit_missing_generated = shift;
44 foreach my $path (@_) {
51 # Don't copy these top level READMEs
59 my $source = 'perldelta.pod';
60 my $filename = "pod/$source";
61 my $fh = open_or_die($filename);
62 my $contents = do {local $/; <$fh>};
64 $contents =~ /perldelta - what is new for perl v(5)\.(\d+)\.(\d+)\n/;
65 die "Can't extract version from $filename" unless @want;
66 $state{delta_target} = join '', 'perl', @want, 'delta.pod';
67 $state{delta_version} = \@want;
69 # This way round so that keys can act as a MANIFEST skip list
70 # Targets will always be in the pod directory. Currently we can only cope
71 # with sources being in the same directory.
72 $state{copies}{$state{delta_target}} = $source;
77 my $master = open_or_die('pod.lst');
82 # At least one upper case letter somewhere in the first group
83 if (/^(\S+)\s(.*)/ && $1 =~ tr/h//) {
87 my %flags = (header => 1);
88 $flags{toc_omit} = 1 if $flags =~ tr/o//d;
89 $flags{aux} = 1 if $flags =~ tr/a//d;
90 my_die "Unknown flag found in heading line: $_" if length $flags;
92 push @{$state{master}}, [\%flags, $2];
93 } elsif (/^(\S*)\s+(\S+)\s+(.*)/) {
95 my ($flags, $podname, $desc) = ($1, $2, $3);
96 my $filename = "${podname}.pod";
97 $filename = "pod/${filename}" if $filename !~ m{/};
99 my %flags = (indent => 0);
100 $flags{indent} = $1 if $flags =~ s/(\d+)//;
101 $flags{toc_omit} = 1 if $flags =~ tr/o//d;
102 $flags{aux} = 1 if $flags =~ tr/a//d;
103 $flags{perlpod_omit} = "$podname.pod" eq $state{delta_target};
105 $state{generated}{"$podname.pod"}++ if $flags =~ tr/g//d;
107 if ($flags =~ tr/r//d) {
108 my $readme = $podname;
109 $readme =~ s/^perl//;
110 $Readmepods{$podname} = $state{readmes}{$readme} = $desc;
112 } elsif ($flags{aux}) {
113 $state{aux}{$podname} = $desc;
115 $state{pods}{$podname} = $desc;
117 my_die "Unknown flag found in section line: $_" if length $flags;
118 my ($leafname) = $podname =~ m!([^/]+)$!;
119 push @{$state{master}},
120 [\%flags, $podname, $filename, $desc, $leafname];
122 push @{$state{master}}, undef;
124 my_die "Malformed line: $_" if $1 =~ tr/A-Z//;
127 close $master or my_die "close pod.lst: $!";
131 my (%disk_pods, %manipods, %manireadmes, %perlpods);
132 my (%cpanpods, %cpanpods_leaf);
135 # These are stub files for deleted documents. We don't want them to show up
136 # in perl.pod, they just exist so that if someone types "perldoc perltoot"
137 # they get some sort of pointer to the new docs.
139 = map { ( "$_.pod" => 1 ) } qw( perlboot perlbot perltooc perltoot );
141 # Convert these to a list of filenames.
142 foreach (keys %{$state{pods}}, keys %Readmepods) {
143 $our_pods{"$_.pod"}++;
146 opendir my $dh, 'pod';
147 while (defined ($_ = readdir $dh)) {
148 next unless /\.pod\z/;
152 # Things we copy from won't be in perl.pod
153 # Things we copy to won't be in MANIFEST
155 my $mani = open_or_die('MANIFEST');
159 if (m!^pod/([^.]+\.pod)!i) {
161 } elsif (m!^README\.(\S+)!i) {
162 next if $state{ignore}{$1};
163 ++$manireadmes{"perl$1.pod"};
164 } elsif (exists $our_pods{$_}) {
167 ++$cpanpods_leaf{$1};
172 close $mani or my_die "close MANIFEST: $!\n";
174 my $perlpod = open_or_die('pod/perl.pod');
176 if (/^For ease of access, /../^\(If you're intending /) {
177 if (/^\s+(perl\S*)\s+\w/) {
178 ++$perlpods{"$1.pod"};
182 close $perlpod or my_die "close perlpod: $!\n";
183 my_die "could not find the pod listing of perl.pod\n"
186 # Are we running before known generated files have been generated?
187 # (eg in a clean checkout)
189 if ($permit_missing_generated) {
190 # If so, don't complain if these files aren't yet in place
191 %not_yet_there = (%manireadmes, %{$state{generated}}, %{$state{copies}})
195 foreach my $i (sort keys %disk_pods) {
196 push @inconsistent, "$0: $i exists but is unknown by buildtoc\n"
197 unless $our_pods{$i};
198 push @inconsistent, "$0: $i exists but is unknown by MANIFEST\n"
199 if !$BuildFiles{'MANIFEST'} # Ignore if we're rebuilding MANIFEST
200 && !$manipods{$i} && !$manireadmes{$i} && !$state{copies}{$i}
201 && !$state{generated}{$i} && !$cpanpods{$i};
202 push @inconsistent, "$0: $i exists but is unknown by perl.pod\n"
203 if !$BuildFiles{'perl.pod'} # Ignore if we're rebuilding perl.pod
204 && !$perlpods{$i} && !exists $state{copies}{$i}
205 && !$cpanpods{$i} && !$ignoredpods{$i};
207 foreach my $i (sort keys %our_pods) {
208 push @inconsistent, "$0: $i is known by buildtoc but does not exist\n"
209 unless $disk_pods{$i} or $BuildFiles{$i} or $not_yet_there{$i};
211 unless ($BuildFiles{'MANIFEST'}) {
212 # Again, ignore these if we're about to rebuild MANIFEST
213 foreach my $i (sort keys %manipods) {
214 push @inconsistent, "$0: $i is known by MANIFEST but does not exist\n"
215 unless $disk_pods{$i};
216 push @inconsistent, "$0: $i is known by MANIFEST but is marked as generated\n"
217 if $state{generated}{$i};
220 unless ($BuildFiles{'perl.pod'}) {
221 # Again, ignore these if we're about to rebuild perl.pod
222 foreach my $i (sort keys %perlpods) {
223 push @inconsistent, "$0: $i is known by perl.pod but does not exist\n"
224 unless $disk_pods{$i} or $BuildFiles{$i} or $cpanpods_leaf{$i}
225 or $not_yet_there{$i};
228 $state{inconsistent} = \@inconsistent;
235 # cperl-indent-level: 4
236 # indent-tabs-mode: nil
239 # ex: set ts=8 sts=4 sw=4 et: