In buildtoc, eliminate @modpods by building %Found directly.
authorNicholas Clark <nick@ccl4.org>
Sun, 18 Dec 2011 16:56:45 +0000 (17:56 +0100)
committerNicholas Clark <nick@ccl4.org>
Mon, 19 Dec 2011 12:55:20 +0000 (13:55 +0100)
There's no need to use an intermediate array to store the results from
calling File::Find::find() as its only use is to build a hash of work to do,
by looping over it once.

Standardise on !! for the regex delimiter, and convert ^ and $ to \A and \z.
The temporary variable $pod can be eliminated, because it doesn't matter
whether $_ ends '.pod' or '.pm' in the code that follows.

pod/buildtoc

index 5fcb938..a8a05ff 100644 (file)
@@ -24,7 +24,7 @@ die "$0: Usage: $0 [--quiet]\n"
 my $state = get_pod_metadata(0, sub { warn @_ if @_ }, 'pod/perltoc.pod');
 
 # Find all the modules
-my @modpods;
+my %done;
 find({no_chdir => 1,
       wanted => sub {
           if (/\.p(od|m)$/) {
@@ -32,26 +32,19 @@ find({no_chdir => 1,
               return if m!(?:^|/)t/!;
               return if m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
               return if m!XS/(?:APItest|Typemap)!;
-              my $pod = $_;
-              return if $pod =~ s/pm$/pod/ && -e $pod;
-              push @modpods, $_;
+              return if s!pm\z!pod! && -e $_;
+              s!\.pod\z!!;
+              s!\Alib/!!;
+              s!/!::!g;
+              my_die("Duplicate files for $_, '$done{$_}' and '$File::Find::name'")
+                  if exists $done{$_};
+
+              $done{$_} = $File::Find::name;
+              $Found{/\A[a-z]/ ? 'PRAGMA' : 'MODULE'}{$_} = $File::Find::name;
           }
       }}, 'lib');
 
-my_die "Can't find any pods!\n" unless @modpods;
-
-my %done;
-for (@modpods) {
-    my $name = $_;
-    $name =~ s/\.p(m|od)$//;
-    $name =~ s-\Alib/--;
-    $name =~ s-/-::-g;
-    my_die("Duplicate files for $name, '$done{$name}' and '$_'")
-        if exists $done{$name};
-    $done{$name} = $_;
-
-    $Found{$name =~ /^[a-z]/ ? 'PRAGMA' : 'MODULE'}{$name} = $_;
-}
+my_die "Can't find any pods!\n" unless %done;
 
 # Accumulating everything into a lexical before writing to disk dates from the
 # time when this script also provided the functionality of regen/pod_rules.pl