This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In buildtoc, refactor the code that reads pod.lst, MANIFEST and perl.pod
[perl5.git] / pod / buildtoc
index 24cb47c..6b9e9d6 100644 (file)
@@ -1,9 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use vars qw($masterpodfile %Build %Targets $Verbose $Quiet %Ignore
-           @Master %Readmes %Pods %Aux %Readmepods %Pragmata %Modules
-           %Copies %Generated $Test);
+use vars qw(%Build %Targets %Pragmata %Modules $Verbose $Quiet $Test);
 use File::Spec;
 use File::Find;
 use FindBin;
@@ -15,17 +13,28 @@ use Carp;
 no locale;
 require 5.010;
 
+# Assumption is that we're either already being run from the top level (*nix,
+# VMS), or have absolute paths in @INC (Win32, pod/Makefile)
 {
   my $Top = File::Spec->catdir($FindBin::Bin, File::Spec->updir);
+  chdir $Top or die "Can't chdir to $Top: $!";
+}
 
-  sub abs_from_top {
-    my $path = shift;
-    return File::Spec->catdir($Top, split /\//, $path) if $path =~ s!/\z!!;
-    return File::Spec->catfile($Top, split /\//, $path);
-  }
+# make it clearer when we haven't run to completion, as we can be quite
+# noisy when things are working ok
+
+sub my_die {
+    print STDERR "$0: ", @_;
+    print STDERR "\n" unless $_[-1] =~ /\n\z/;
+    print STDERR "ABORTED\n";
+    exit 255;
 }
 
-$masterpodfile = abs_from_top('pod.lst');
+sub open_or_die {
+    my $filename = shift;
+    open my $fh, '<', $filename or my_die "Can't open $filename: $!";
+    return $fh;
+}
 
 # Generate any/all of these files
 # --verbose gives slightly more output
@@ -50,10 +59,6 @@ $masterpodfile = abs_from_top('pod.lst');
      # TODO: add roffitall
     );
 
-foreach (values %Targets) {
-  $_ = abs_from_top($_);
-}
-
 # process command-line switches
 
 {
@@ -78,205 +83,215 @@ __USAGE__
     }
   }
   if ($showfiles) {
-      print
-         join(" ",
-              sort { lc $a cmp lc $b }
-              map {
-                  my ($v, $d, $f) = File::Spec->splitpath($_);
-                  my @d;
-                  @d = defined $d ? File::Spec->splitdir($d) : ();
-                  shift @d if @d;
-                  File::Spec->catfile(@d ?
-                                      (@d == 1 && $d[0] eq '' ? () : @d)
-                                      : "pod", $f);
-              } @Targets{@files}),
-          "\n";
+      print join(" ", sort { lc $a cmp lc $b } values %Build), "\n";
       exit(0);
   }
 }
 
-# Don't copy these top level READMEs
-%Ignore
-  = (
-     micro => 1,
-#     vms => 1,
-     );
-
 if ($Verbose) {
   print "I will be building $_\n" foreach keys %Build;
 }
 
+sub get_pod_metadata {
+    my %BuildFiles;
 
-# process pod.lst
-
-open my $master, '<', $masterpodfile or die "$0: Can't open $masterpodfile: $!";
-
-my ($delta_source, $delta_target);
+    foreach my $path (@_) {
+        $path =~ m!([^/]+)$!;
+        ++$BuildFiles{$1};
+    }
 
-foreach (<$master>) {
-  next if /^\#/;
+    my %state =
+        (
+         # Don't copy these top level READMEs
+         ignore =>
+         {
+          micro => 1,
+          # vms => 1,
+         },
+     );
 
-  # At least one upper case letter somewhere in the first group
-  if (/^(\S+)\s(.*)/ && $1 =~ tr/h//) {
-    # it's a heading
-    my $flags = $1;
-    $flags =~ tr/h//d;
-    my %flags = (header => 1);
-    $flags{toc_omit} = 1 if $flags =~ tr/o//d;
-    $flags{aux} = 1 if $flags =~ tr/a//d;
-    die "$0: Unknown flag found in heading line: $_" if length $flags;
-    push @Master, [\%flags, $2];
+    my $source = 'perldelta.pod';
+    my $filename = "pod/$source";
+    my $fh = open_or_die($filename);
+    my $contents = do {local $/; <$fh>};
+    my @want =
+        $contents =~ /perldelta - what is new for perl v5\.(\d+)\.(\d+)\n/;
+    die "Can't extract version from $filename" unless @want;
+    $state{delta_target} = "perl5$want[0]$want[1]delta.pod";
 
-  } elsif (/^(\S*)\s+(\S+)\s+(.*)/) {
-    # it's a section
-    my ($flags, $filename, $desc) = ($1, $2, $3);
+    # This way round so that keys can act as a MANIFEST skip list
+    # Targets will always be in the pod directory. Currently we can only cope
+    # with sources being in the same directory.
+    $state{copies}{$state{delta_target}} = $source;
+
+
+    # process pod.lst
+    my %Readmepods;
+    my $master = open_or_die('pod.lst');
+
+    foreach (<$master>) {
+        next if /^\#/;
+
+        # At least one upper case letter somewhere in the first group
+        if (/^(\S+)\s(.*)/ && $1 =~ tr/h//) {
+            # it's a heading
+            my $flags = $1;
+            $flags =~ tr/h//d;
+            my %flags = (header => 1);
+            $flags{toc_omit} = 1 if $flags =~ tr/o//d;
+            $flags{aux} = 1 if $flags =~ tr/a//d;
+            my_die "Unknown flag found in heading line: $_" if length $flags;
+
+            push @{$state{master}}, [\%flags, $2];
+        } elsif (/^(\S*)\s+(\S+)\s+(.*)/) {
+            # it's a section
+            my ($flags, $podname, $desc) = ($1, $2, $3);
+            my $filename = "${podname}.pod";
+            $filename = "pod/${filename}" if $filename !~ m{/};
+
+            my %flags = (indent => 0);
+            $flags{indent} = $1 if $flags =~ s/(\d+)//;
+            $flags{toc_omit} = 1 if $flags =~ tr/o//d;
+            $flags{aux} = 1 if $flags =~ tr/a//d;
+            $flags{perlpod_omit} = "$podname.pod" eq $state{delta_target};
+
+            $state{generated}{"$podname.pod"}++ if $flags =~ tr/g//d;
+
+            if ($flags =~ tr/r//d) {
+                my $readme = $podname;
+                $readme =~ s/^perl//;
+                $Readmepods{$podname} = $state{readmes}{$readme} = $desc;
+                $flags{readme} = 1;
+            } elsif ($flags{aux}) {
+                $state{aux}{$podname} = $desc;
+            } else {
+                $state{pods}{$podname} = $desc;
+            }
+            my_die "Unknown flag found in section line: $_" if length $flags;
+            my $shortname = $podname =~ s{.*/}{}r;
+            push @{$state{master}},
+                [\%flags, $podname, $filename, $desc, $shortname];
+        } elsif (/^$/) {
+            push @{$state{master}}, undef;
+        } else {
+            my_die "Malformed line: $_" if $1 =~ tr/A-Z//;
+        }
+    }
+    close $master or my_die "close pod.lst: $!";
+
+    # Sanity cross check
+
+    my (%disk_pods, @disk_pods);
+    my (@manipods, %manipods);
+    my (@manireadmes, %manireadmes);
+    my (@perlpods, %perlpods);
+    my (@cpanpods, %cpanpods, %cpanpods_short);
+    my (%our_pods);
+
+    # These are stub files for deleted documents. We don't want them to show up
+    # in perl.pod, they just exist so that if someone types "perldoc perltoot"
+    # they get some sort of pointer to the new docs.
+    my %ignoredpods
+        = map { ( "$_.pod" => 1 ) } qw( perlboot perlbot perltooc perltoot );
+
+    # Convert these to a list of filenames.
+    foreach (keys %{$state{pods}}, keys %Readmepods) {
+        $our_pods{"$_.pod"}++;
+    }
 
-    my %flags = (indent => 0);
-    $flags{indent} = $1 if $flags =~ s/(\d+)//;
-    $flags{toc_omit} = 1 if $flags =~ tr/o//d; 
-    $flags{aux} = 1 if $flags =~ tr/a//d;
+    opendir my $dh, 'pod';
+    while (defined ($_ = readdir $dh)) {
+        next unless /\.pod\z/;
+        push @disk_pods, $_;
+        ++$disk_pods{$_};
+    }
 
-    if ($flags =~ tr/D//d) {
-      $flags{manifest_omit} = 1;
-      $delta_source = "$filename.pod";
+    # Things we copy from won't be in perl.pod
+    # Things we copy to won't be in MANIFEST
+
+    my $mani = open_or_die('MANIFEST');
+    while (<$mani>) {
+        chomp;
+        s/\s+.*$//;
+        if (m!^pod/([^.]+\.pod)!i) {
+            push @manipods, $1;
+        } elsif (m!^README\.(\S+)!i) {
+            next if $state{ignore}{$1};
+            push @manireadmes, "perl$1.pod";
+        } elsif (exists $our_pods{$_}) {
+            push @cpanpods, $_;
+            $disk_pods{$_}++
+                if -e $_;
+        }
     }
-    if ($flags =~ tr/d//d) {
-      $flags{perlpod_omit} = 1;
-      $delta_target = "$filename.pod";
+    close $mani or my_die "close MANIFEST: $!\n";
+
+    @manipods{@manipods} = @manipods;
+    @manireadmes{@manireadmes} = @manireadmes;
+    @cpanpods{@cpanpods} = map { s/.*\///r } @cpanpods;
+    %cpanpods_short = reverse %cpanpods;
+
+    my $perlpod = open_or_die('pod/perl.pod');
+    while (<$perlpod>) {
+        if (/^For ease of access, /../^\(If you're intending /) {
+            if (/^\s+(perl\S*)\s+\w/) {
+                push @perlpods, "$1.pod";
+            }
+        }
     }
-    $Generated{"$filename.pod"}++ if $flags =~ tr/g//d;
-
-    if ($flags =~ tr/r//d) {
-      my $readme = $filename;
-      $readme =~ s/^perl//;
-      $Readmepods{$filename} = $Readmes{$readme} = $desc;
-      $flags{readme} = 1;
-    } elsif ($flags{aux}) {
-      $Aux{$filename} = $desc;
-    } else {
-      $Pods{$filename} = $desc;
+    close $perlpod or my_die "close perlpod: $!\n";
+    my_die "could not find the pod listing of perl.pod\n"
+        unless @perlpods;
+    @perlpods{@perlpods} = @perlpods;
+
+    my @inconsistent;
+    foreach my $i (sort keys %disk_pods) {
+        push @inconsistent, "$0: $i exists but is unknown by buildtoc\n"
+            unless $our_pods{$i};
+        push @inconsistent, "$0: $i exists but is unknown by MANIFEST\n"
+            if !$manipods{$i} && !$manireadmes{$i} && !$state{copies}{$i}
+                && !$state{generated}{$i} && !$cpanpods{$i};
+        push @inconsistent, "$0: $i exists but is unknown by perl.pod\n"
+            if !$perlpods{$i} && !exists $state{copies}{$i} && !$cpanpods{$i} && !$ignoredpods{$i};
     }
-    die "$0: Unknown flag found in section line: $_" if length $flags;
-    push @Master, [\%flags, $filename, $desc];
-  } elsif (/^$/) {
-    push @Master, undef;
-  } else {
-    die "$0: Malformed line: $_" if $1 =~ tr/A-Z//;
-  }
-}
-if (defined $delta_source) {
-  if (defined $delta_target) {
-    # This way round so that keys can act as a MANIFEST skip list
-    # Targets will aways be in the pod directory. Currently we can only cope
-    # with sources being in the same directory.
-    $Copies{$delta_target} = $delta_source;
-  } else {
-    die "$0: delta source defined but not target";
-  }
-} elsif (defined $delta_target) {
-  die "$0: delta target defined but not source";
-}
-
-close $master;
-
-# Sanity cross check
-{
-  my (%disk_pods, @disk_pods);
-  my (@manipods, %manipods);
-  my (@manireadmes, %manireadmes);
-  my (@perlpods, %perlpods);
-  my (%our_pods);
-
-  # Convert these to a list of filenames.
-  foreach (keys %Pods, keys %Readmepods) {
-    $our_pods{"$_.pod"}++;
-  }
-
-  opendir my $dh, abs_from_top('pod/');
-  while (defined ($_ = readdir $dh)) {
-    next unless /\.pod\z/;
-    push @disk_pods, $_;
-    ++$disk_pods{$_};
-  }
-
-  # Things we copy from won't be in perl.pod
-  # Things we copy to won't be in MANIFEST
-
-  my $filename = abs_from_top('MANIFEST');
-  open my $mani, '<', $filename or die "$0: opening $filename failed: $!";
-  while (<$mani>) {
-    if (m!^pod/([^.]+\.pod)\s+!i) {
-      push @manipods, $1;
-    } elsif (m!^README\.(\S+)\s+!i) {
-      next if $Ignore{$1};
-      push @manireadmes, "perl$1.pod";
+    foreach my $i (sort keys %our_pods) {
+        push @inconsistent, "$0: $i is known by buildtoc but does not exist\n"
+            unless $disk_pods{$i} or $BuildFiles{$i};
     }
-  }
-  close $mani or die $!;
-  @manipods{@manipods} = @manipods;
-  @manireadmes{@manireadmes} = @manireadmes;
-
-  $filename = abs_from_top('pod/perl.pod');
-  open my $perlpod, '<', $filename or die "$0: opening $filename failed: $!\n";
-  while (<$perlpod>) {
-    if (/^For ease of access, /../^\(If you're intending /) {
-      if (/^\s+(perl\S*)\s+\w/) {
-       push @perlpods, "$1.pod";
-      }
+    foreach my $i (sort keys %manipods) {
+        push @inconsistent, "$0: $i is known by MANIFEST but does not exist\n"
+            unless $disk_pods{$i};
+        push @inconsistent, "$0: $i is known by MANIFEST but is marked as generated\n"
+            if $state{generated}{$i};
     }
-  }
-  close $perlpod or die $!;
-  die "$0: could not find the pod listing of perl.pod\n"
-    unless @perlpods;
-  @perlpods{@perlpods} = @perlpods;
-
-  my @inconsistent;
-  foreach my $i (sort keys %disk_pods) {
-    push @inconsistent, "$0: $i exists but is unknown by buildtoc\n"
-      unless $our_pods{$i};
-    push @inconsistent, "$0: $i exists but is unknown by ../MANIFEST\n"
-      if !$manipods{$i} && !$manireadmes{$i} && !$Copies{$i} && !$Generated{$i};
-    push @inconsistent, "$0: $i exists but is unknown by perl.pod\n"
-       if !$perlpods{$i} && !exists $Copies{$i};
-  }
-  my %BuildFiles;
-  foreach my $path (values %Build) {
-    (undef, undef, my $file) = File::Spec->splitpath($path);
-    ++$BuildFiles{$file}
-  }
+    foreach my $i (sort keys %perlpods) {
+        push @inconsistent, "$0: $i is known by perl.pod but does not exist\n"
+            unless $disk_pods{$i} or $BuildFiles{$i} or $cpanpods_short{$i};
+    }
+    $state{inconsistent} = \@inconsistent;
+    return \%state;
+}
 
-  foreach my $i (sort keys %our_pods) {
-    push @inconsistent, "$0: $i is known by buildtoc but does not exist\n"
-      unless $disk_pods{$i} or $BuildFiles{$i};
-  }
-  foreach my $i (sort keys %manipods) {
-    push @inconsistent, "$0: $i is known by ../MANIFEST but does not exist\n"
-      unless $disk_pods{$i};
-    push @inconsistent, "$0: $i is known by ../MANIFEST but is marked as generated\n"
-      if $Generated{$i};
-  }
-  foreach my $i (sort keys %perlpods) {
-    push @inconsistent, "$0: $i is known by perl.pod but does not exist\n"
-      unless $disk_pods{$i} or $BuildFiles{$i};
-  }
-  if ($Test) {
+my $state = get_pod_metadata(values %Build);
+
+if ($Test) {
     delete $Build{toc};
     printf "1..%d\n", 1 + scalar keys %Build;
-    if (@inconsistent) {
-      print "not ok 1\n";
-      die @inconsistent
+    if (@{$state->{inconsistent}}) {
+        print "not ok 1\n";
+        die @{$state->{inconsistent}};
     }
     print "ok 1\n";
-  }
-  else {
-    warn @inconsistent if @inconsistent;
-  }
 }
+else {
+    warn @{$state->{inconsistent}} if @{$state->{inconsistent}};
+}
+
 
 # Find all the modules
 if ($Build{toc}) {
   my @modpods;
-  find \&getpods => abs_from_top('lib/');
+  find \&getpods => 'lib';
 
   sub getpods {
     if (/\.p(od|m)$/) {
@@ -307,7 +322,7 @@ if ($Build{toc}) {
     }
   }
 
-  die "$0: no pods" unless @modpods;
+  my_die "Can't find any pods!\n" unless @modpods;
 
   my %done;
   for (@modpods) {
@@ -355,8 +370,8 @@ EOPOD2B
 #' make emacs happy
 
   # All the things in the master list that happen to be pod filenames
-  foreach (grep {defined $_ && @$_ == 3 && !$_->[0]{toc_omit}} @Master) {
-    podset($_->[1], abs_from_top("pod/$_->[1].pod"));
+  foreach (grep {defined $_ && @$_ == 3 && !$_->[0]{toc_omit}} @{$state->{master}}) {
+    podset(@$_);
   }
 
 
@@ -396,7 +411,7 @@ EOPOD2B
 
 EOPOD2B
 
-  $_ .=  join "\n", map {"\t=item $_\n"} sort keys %Aux;
+  $_ .=  join "\n", map {"\t=item $_\n"} sort keys %{$state->{aux}};
   $_ .= <<"EOPOD2B" ;
 
        =back
@@ -429,7 +444,7 @@ sub podset {
 
     local $/ = '';
 
-    open my $fh, '<', $file or die "Can't open file '$file' for $pod: $!";
+    open my $fh, '<', $file or my_die "Can't open file '$file' for $pod: $!";
 
     while(<$fh>) {
        tr/\015//d;
@@ -507,7 +522,7 @@ sub unitem {
 sub generate_perlpod {
   my @output;
   my $maxlength = 0;
-  foreach (@Master) {
+  foreach (@{$state->{master}}) {
     my $flags = $_->[0];
     next if $flags->{aux};
     next if $flags->{perlpod_omit};
@@ -515,16 +530,16 @@ sub generate_perlpod {
     if (@$_ == 2) {
       # Heading
       push @output, "=head2 $_->[1]\n";
-    } elsif (@$_ == 3) {
+    } elsif (@$_ == 5) {
       # Section
-      my $start = " " x (4 + $flags->{indent}) . $_->[1];
+      my $start = " " x (4 + $flags->{indent}) . $_->[4];
       $maxlength = length $start if length ($start) > $maxlength;
-      push @output, [$start, $_->[2]];
+      push @output, [$start, $_->[3]];
     } elsif (@$_ == 0) {
       # blank line
       push @output, "\n";
     } else {
-      die "$0: Illegal length " . scalar @$_;
+      my_die "Illegal length " . scalar @$_;
     }
   }
   # want at least 2 spaces padding
@@ -544,19 +559,21 @@ sub generate_manifest {
   map {s/ \t/\t\t/g; $_} @temp;
 }
 sub generate_manifest_pod {
-  generate_manifest map {["pod/$_.pod", $Pods{$_}]}
-    sort grep {!$Copies{"$_.pod"}} grep {!$Generated{"$_.pod"}} keys %Pods;
+  generate_manifest map {["pod/$_.pod", $state->{pods}{$_}]}
+    sort grep {
+        !$state->{copies}{"$_.pod"} && !$state->{generated}{"$_.pod"} && !-e "$_.pod"
+    } keys %{$state->{pods}};
 }
 sub generate_manifest_readme {
   generate_manifest sort {$a->[0] cmp $b->[0]}
     ["README.vms", "Notes about installing the VMS port"],
-      map {["README.$_", $Readmes{$_}]} keys %Readmes;
+      map {["README.$_", $state->{readmes}{$_}]} keys %{$state->{readmes}};
 }
 
 sub generate_roffitall {
-  (map ({"\t\$maindir/$_.1\t\\"}sort keys %Pods),
+  (map ({"\t\$maindir/$_.1\t\\"}sort keys %{$state->{pods}}),
    "\t\t\\",
-   map ({"\t\$maindir/$_.1\t\\"}sort keys %Aux),
+   map ({"\t\$maindir/$_.1\t\\"}sort keys %{$state->{aux}}),
    "\t\t\\",
    map ({"\t\$libdir/$_.3\t\\"}sort keys %Pragmata),
    "\t\t\\",
@@ -564,29 +581,11 @@ sub generate_roffitall {
   )
 }
 
-sub generate_descrip_mms_1 {
-  local $Text::Wrap::columns = 150;
-  my $count = 0;
-  my @lines = map {"pod" . $count++ . " = $_"}
-    split /\n/, wrap('', '', join " ", map "[.lib.pods]$_.pod",
-                    sort keys %Pods, keys %Readmepods);
-  @lines, "pod = " . join ' ', map {"\$(pod$_)"} 0 .. $count - 1;
-}
-
-sub generate_descrip_mms_2 {
-  map {<<"SNIP"}
-[.lib.pods]$_.pod : [.pod]$_.pod
-       \@ If F\$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
-       Copy/NoConfirm/Log \$(MMS\$SOURCE) [.lib.pods]
-SNIP
-   sort keys %Pods, keys %Readmepods;
-}
-
 sub generate_nmake_1 {
   # XXX Fix this with File::Spec
   (map {sprintf "\tcopy ..\\README.%-8s ..\\pod\\perl$_.pod\n", $_}
-    sort keys %Readmes),
-      (map {"\tcopy ..\\pod\\$Copies{$_} ..\\pod\\$_\n"} sort keys %Copies);
+    sort keys %{$state->{readmes}}),
+      (map {"\tcopy ..\\pod\\$state->{copies}{$_} ..\\pod\\$_\n"} sort keys %{$state->{copies}});
 }
 
 # This doesn't have a trailing newline
@@ -594,8 +593,8 @@ sub generate_nmake_2 {
   # Spot the special case
   local $Text::Wrap::columns = 76;
   my $line = wrap ("\t    ", "\t    ",
-                  join " ", sort keys %Copies, keys %Generated,
-                                 map {"perl$_.pod"} keys %Readmes);
+                   join " ", sort keys %{$state->{copies}}, keys %{$state->{generated}},
+                                  map {"perl$_.pod"} keys %{$state->{readmes}});
   $line =~ s/$/ \\/mg;
   $line =~ s/ \\$//;
   $line;
@@ -604,8 +603,8 @@ sub generate_nmake_2 {
 sub generate_pod_mak {
   my $variable = shift;
   my @lines;
-  my $line = join "\\\n", "\U$variable = ",
-    map {"\t$_.$variable\t"} sort keys %Pods;
+  my $line = "\U$variable = " . join "\t\\\n\t",
+    map {"$_.$variable"} sort grep { $_ !~ m{/} } keys %{$state->{pods}};
   # Special case
   $line =~ s/.*perltoc.html.*\n//m;
   $line;
@@ -622,7 +621,7 @@ sub do_manifest {
   my ($name, $prev) = @_;
   my @manifest =
     grep {! m!^pod/[^.]+\.pod.*!}
-      grep {! m!^README\.(\S+)! || $Ignore{$1}} split "\n", $prev;
+      grep {! m!^README\.(\S+)! || $state->{ignore}{$1}} split "\n", $prev;
   join "\n", (
              # Dictionary order - fold and handle non-word chars as nothing
              map  { $_->[0] }
@@ -659,7 +658,7 @@ sub do_perlpod {
                   )+
                  }
          {$1 . join "", &generate_perlpod}mxe) {
-    die "$0: Failed to insert amendments in do_perlpod";
+    my_die "Failed to insert amendments in do_perlpod";
   }
   $pod;
 }
@@ -667,7 +666,7 @@ sub do_perlpod {
 sub do_podmak {
   my ($name, $body) = @_;
   foreach my $variable (qw(pod man html tex)) {
-    die "$0: could not find $variable in $name"
+    my_die "could not find $variable in $name"
       unless $body =~ s{\n\U$variable\E = (?:[^\n]*\\\n)*[^\n]*}
        {"\n" . generate_pod_mak ($variable)}se;
   }
@@ -676,11 +675,6 @@ sub do_podmak {
 
 sub do_vms {
   my ($name, $makefile) = @_;
-  $makefile =~ s/\npod\d* =[^\n]*/\0/gs;
-  verify_contiguous($name, $makefile, 'pod assignments');
-  $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_1/se;
-
-  die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
 
 # Looking for the macro defining the current perldelta:
 #PERLDELTA_CURRENT = [.pod]perl5139delta.pod
@@ -688,19 +682,7 @@ sub do_vms {
   $makefile =~ s/\nPERLDELTA_CURRENT\s+=\s+\Q[.pod]perl\E\d+delta\.pod\n
                    /\0/sx;
   verify_contiguous($name, $makefile, 'current perldelta macro');
-  $makefile =~ s/\0+/join "\n", '', "PERLDELTA_CURRENT = [.pod]$delta_target", ''/se;
-
-# Looking for rules like this
-# [.lib.pods]perl.pod : [.pod]perl.pod
-#      @ If F$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
-#      Copy/NoConfirm/Log $(MMS$SOURCE) [.lib.pods]
-
-  $makefile =~ s/\n\Q[.lib.pods]\Eperl[^\n\.]*\.pod[^\n]+\n
-                [^\n]+\n       # Another line
-                [^\n]+\Q[.lib.pods]\E\n                # ends [.lib.pods]
-                   /\0/gsx;
-  verify_contiguous($name, $makefile, 'copy rules');
-  $makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_2/se;
+  $makefile =~ s/\0+/join "\n", '', "PERLDELTA_CURRENT = [.pod]$state->{delta_target}", ''/se;
 
   $makefile;
 }
@@ -710,7 +692,7 @@ sub do_unix {
 
   $makefile_SH =~ s{^(perltoc_pod_prereqs = extra.pods).*}
                   {join ' ', $1, map "pod/$_",
-                       sort keys %Copies, grep {!/perltoc/} keys %Generated
+                        sort keys %{$state->{copies}}, grep {!/perltoc/} keys %{$state->{generated}}
                    }mge;
 
 # pod/perl511delta.pod: pod/perldelta.pod
@@ -724,9 +706,9 @@ pod/perl[a-z0-9_]+\.pod: pod/perl[a-z0-9_]+\.pod
   verify_contiguous($name, $makefile_SH, 'copy rules');
 
   my @copy_rules = map "
-pod/$_: pod/$Copies{$_}
-       \$(LNS) $Copies{$_} pod/$_
-", keys %Copies;
+pod/$_: pod/$state->{copies}{$_}
+       \$(LNS) $state->{copies}{$_} pod/$_
+", keys %{$state->{copies}};
 
   $makefile_SH =~ s/\0+/join '', @copy_rules/se;
   $makefile_SH;
@@ -744,10 +726,10 @@ while (my ($target, $name) = each %Targets) {
   print "Now processing $name\n" if $Verbose;
   if ($target ne "toc") {
     local $/;
-    open my $thing, '<', $name or die "Can't open $name: $!";
+    my $thing = open_or_die($name);
     binmode $thing;
     $orig = <$thing>;
-    die "$0: $name contains NUL bytes" if $orig =~ /\0/;
+    my_die "$name contains NUL bytes" if $orig =~ /\0/;
   }
 
   my $new = do {
@@ -767,16 +749,16 @@ while (my ($target, $name) = each %Targets) {
       printf "not ok %d # $name is up to date\n", $built + 1;
       next;
     }
-    $mode = (stat $name)[2] // die "$0: Can't stat $name: $!";
-    rename $name, "$name.old" or die "$0: Can't rename $name to $name.old: $!";
+    $mode = (stat $name)[2] // my_die "Can't stat $name: $!";
+    rename $name, "$name.old" or my_die "Can't rename $name to $name.old: $!";
   }
 
-  open my $thing, '>', $name or die "$0: Can't open $name for writing: $!";
+  open my $thing, '>', $name or my_die "Can't open $name for writing: $!";
   binmode $thing;
-  print $thing $new or die "$0: print to $name failed: $!";
-  close $thing or die "$0: close $name failed: $!";
+  print $thing $new or my_die "print to $name failed: $!";
+  close $thing or my_die "close $name failed: $!";
   if (defined $mode) {
-    chmod $mode & 0777, $name or die "$0: can't chmod $mode $name: $!";
+    chmod $mode & 0777, $name or my_die "can't chmod $mode $name: $!";
   }
 }