7 # make it clearer when we haven't run to completion, as we can be quite
8 # noisy when things are working ok
11 print STDERR "$0: ", @_;
12 print STDERR "\n" unless $_[-1] =~ /\n\z/;
13 print STDERR "ABORTED\n";
19 open my $fh, '<', $filename or my_die "Can't open $filename: $!";
25 my $fh = open_or_die($filename);
29 die "Can't read $filename: $!" unless defined $contents and close $fh;
34 my ($filename, $contents) = @_;
35 open my $fh, '>', $filename or die "Can't open $filename for writing: $!";
37 print $fh $contents or die "Can't write to $filename: $!";
38 close $fh or die "Can't close $filename: $!";
42 # manpages not to be installed
43 my %do_not_install = map { ($_ => 1) }
44 qw(Pod::Functions XS::APItest XS::Typemap);
48 File::Find::find({no_chdir=>1,
55 # $_ is $File::Find::name when using no_chdir
56 return unless m!\.p(?:m|od)\z! && -f $_;
57 return if m!lib/Net/FTP/.+\.pm\z!; # Hi, Graham! :-)
58 # Skip .pm files that have corresponding .pod files
59 return if s!\.pm\z!.pod! && -e $_;
64 my_die("Duplicate files for $_, '$done{$_}' and '$File::Find::name'")
66 $done{$_} = $File::Find::name;
68 return if $do_not_install{$_};
69 return if is_duplicate_pod($File::Find::name);
70 $found{/\A[a-z]/ ? 'PRAGMA' : 'MODULE'}{$_}
77 # Don't copy these top level READMEs
87 sub is_duplicate_pod {
91 # Initialise the list of possible source files on the first call.
93 __prime_state() unless $state{master};
94 foreach (@{$state{master}}) {
95 next unless $_->[2]{dual};
96 # This is a dual-life perl*.pod file, which will have be copied
97 # to lib/ by the build process, and hence also found there.
98 # These are the only pod files that might become duplicated.
99 ++$Lengths{-s $_->[1]};
100 ++$MD5s{md5(slurp_or_die($_->[1]))};
104 # We are a file in lib. Are we a duplicate?
105 # Don't bother calculating the MD5 if there's no interesting file of
107 return $Lengths{-s $file} && $MD5s{md5(slurp_or_die($file))};
112 my $source = 'perldelta.pod';
113 my $filename = "pod/$source";
114 my $contents = slurp_or_die($filename);
116 $contents =~ /perldelta - what is new for perl v(5)\.(\d+)\.(\d+)\n/;
117 die "Can't extract version from $filename" unless @want;
118 my $delta_leaf = join '', 'perl', @want, 'delta';
119 $state{delta_target} = "$delta_leaf.pod";
120 $state{delta_version} = \@want;
122 # This way round so that keys can act as a MANIFEST skip list
123 # Targets will always be in the pod directory. Currently we can only cope
124 # with sources being in the same directory.
125 $state{copies}{$state{delta_target}} = $source;
127 # The default flags if none explicitly set for the current file.
128 my $current_flags = '';
129 my (%flag_set, @paths);
131 my $master = open_or_die('pod/perl.pod');
134 last if /^=begin buildtoc$/;
136 die "Can't find '=begin buildtoc':" if eof $master;
139 next if /^$/ or /^#/;
140 last if /^=end buildtoc/;
141 my ($command, @args) = split ' ';
142 if ($command eq 'flag') {
143 # For the named pods, use these flags, instead of $current_flags
144 my $flags = shift @args;
145 my_die("Malformed flag $flags")
146 unless $flags =~ /\A=([a-z]*)\z/;
147 $flag_set{$_} = $1 foreach @args;
148 } elsif ($command eq 'path') {
149 # If the pod's name matches the regex, prepend the given path.
150 my_die("Malformed path for /$args[0]/")
152 push @paths, [qr/\A$args[0]\z/, $args[1]];
153 } elsif ($command eq 'aux') {
154 # The contents of perltoc.pod's "AUXILIARY DOCUMENTATION" section
155 $state{aux} = [sort @args];
157 my_die("Unknown buildtoc command '$command'");
161 foreach (<$master>) {
162 next if /^$/ or /^#/;
164 last if /^=for buildtoc __END__$/;
166 if (my ($action, $flags) = /^=for buildtoc flag ([-+])([a-z]+)/) {
167 if ($action eq '+') {
168 $current_flags .= $flags;
170 my_die("Attempt to unset [$flags] failed - flags are '$current_flags")
171 unless $current_flags =~ s/[\Q$flags\E]//g;
173 } elsif (my ($leafname, $desc) = /^\s+(\S+)\s+(.*)/) {
174 my $podname = $leafname;
175 my $filename = "pod/$podname.pod";
177 my ($re, $path) = @$_;
178 if ($leafname =~ $re) {
179 $podname = $path . $leafname;
180 $filename = "$podname.pod";
185 # Keep this compatible with pre-5.10
186 my $flags = delete $flag_set{$leafname};
187 $flags = $current_flags unless defined $flags;
190 $flags{toc_omit} = 1 if $flags =~ tr/o//d;
191 $flags{dual} = $podname ne $leafname;
193 $state{generated}{"$podname.pod"}++ if $flags =~ tr/g//d;
195 if ($flags =~ tr/r//d) {
196 my $readme = $podname;
197 $readme =~ s/^perl//;
198 $state{readmes}{$readme} = $desc;
201 $state{pods}{$podname} = $desc;
203 my_die "Unknown flag found in section line: $_" if length $flags;
205 push @{$state{master}},
206 [$leafname, $filename, \%flags];
208 if ($podname eq 'perldelta') {
210 push @{$state{master}},
211 [$delta_leaf, "pod/$state{delta_target}"];
212 $state{pods}{$delta_leaf} = "Perl changes in version @want";
216 my_die("Malformed line: $_");
219 close $master or my_die("close pod/perl.pod: $!");
220 # This has to be special-cased somewhere. Turns out this is cleanest:
221 push @{$state{master}}, ['a2p', 'x2p/a2p.pod', {toc_omit => 1}];
223 my_die("perl.pod sets flags for unknown pods: "
224 . join ' ', sort keys %flag_set)
228 sub get_pod_metadata {
229 # Do we expect to find generated pods on disk?
230 my $permit_missing_generated = shift;
231 # Do they want a consistency report?
232 my $callback = shift;
235 __prime_state() unless $state{master};
236 return \%state unless $callback;
240 foreach my $path (@_) {
241 $path =~ m!([^/]+)$!;
247 my (%disk_pods, %manipods, %manireadmes);
248 my (%cpanpods, %cpanpods_leaf);
251 # There are files that we don't want to list in perl.pod.
252 # Maybe the various stub manpages should be listed there.
253 my %ignoredpods = map { ( "$_.pod" => 1 ) } qw( );
255 # Convert these to a list of filenames.
256 ++$our_pods{"$_.pod"} foreach keys %{$state{pods}};
257 foreach (@{$state{master}}) {
258 ++$our_pods{"$_->[0].pod"}
262 opendir my $dh, 'pod';
263 while (defined ($_ = readdir $dh)) {
264 next unless /\.pod\z/;
268 # Things we copy from won't be in perl.pod
269 # Things we copy to won't be in MANIFEST
271 my $mani = open_or_die('MANIFEST');
275 if (m!^pod/([^.]+\.pod)!i) {
277 } elsif (m!^README\.(\S+)!i) {
278 next if $state{ignore}{$1};
279 ++$manireadmes{"perl$1.pod"};
280 } elsif (exists $our_pods{$_}) {
283 ++$cpanpods_leaf{$1};
288 close $mani or my_die "close MANIFEST: $!\n";
290 # Are we running before known generated files have been generated?
291 # (eg in a clean checkout)
293 if ($permit_missing_generated) {
294 # If so, don't complain if these files aren't yet in place
295 %not_yet_there = (%manireadmes, %{$state{generated}}, %{$state{copies}})
299 foreach my $i (sort keys %disk_pods) {
300 push @inconsistent, "$0: $i exists but is unknown by buildtoc\n"
301 unless $our_pods{$i} || $ignoredpods{$i};
302 push @inconsistent, "$0: $i exists but is unknown by MANIFEST\n"
303 if !$BuildFiles{'MANIFEST'} # Ignore if we're rebuilding MANIFEST
304 && !$manipods{$i} && !$manireadmes{$i} && !$state{copies}{$i}
305 && !$state{generated}{$i} && !$cpanpods{$i};
307 foreach my $i (sort keys %our_pods) {
308 push @inconsistent, "$0: $i is known by buildtoc but does not exist\n"
309 unless $disk_pods{$i} or $BuildFiles{$i} or $not_yet_there{$i};
311 unless ($BuildFiles{'MANIFEST'}) {
312 # Again, ignore these if we're about to rebuild MANIFEST
313 foreach my $i (sort keys %manipods) {
314 push @inconsistent, "$0: $i is known by MANIFEST but does not exist\n"
315 unless $disk_pods{$i};
316 push @inconsistent, "$0: $i is known by MANIFEST but is marked as generated\n"
317 if $state{generated}{$i};
320 &$callback(@inconsistent);
327 # cperl-indent-level: 4
328 # indent-tabs-mode: nil
331 # ex: set ts=8 sts=4 sw=4 et: