From d71a9bd1fa374f9824b18f331ad39c48e25c15fd Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sun, 18 Dec 2011 17:56:45 +0100 Subject: [PATCH] In buildtoc, eliminate @modpods by building %Found directly. 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 | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/pod/buildtoc b/pod/buildtoc index 5fcb938..a8a05ff 100644 --- a/pod/buildtoc +++ b/pod/buildtoc @@ -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 -- 2.7.4