In installman, move the call to File::Find::find() to the top level.
authorNicholas Clark <nick@ccl4.org>
Wed, 21 Dec 2011 09:56:26 +0000 (10:56 +0100)
committerNicholas Clark <nick@ccl4.org>
Wed, 21 Dec 2011 09:56:26 +0000 (10:56 +0100)
The code to recursively scan a directory with File::File::find() is now only
used by one caller of podset(), so move it to the call point, reducing the
amount of conditional code within podset(). The first argument to podset()
is now always a reference to a hash of "work to be done". Add an optional
fourth argument to give the directory name for diagnostics.

installman

index fb43e85..29d73dc 100755 (executable)
@@ -64,22 +64,38 @@ $opts{verbose} ||= $opts{V} || $opts{notify};
 
 $packlist = ExtUtils::Packlist->new("$opts{destdir}$Config{installarchlib}/.packlist");
 
-# manpages not to be installed
-my %do_not_install = map { ($_ => 1) } qw(
-    Pod/Functions.pm
-    XS/APItest.pm
-    XS/Typemap.pm
-);
-
 # Install the main pod pages.
 pod2man({
          map {
              ($_->[0], $_->[1])
          } @{$state->{master}}
-        }, $opts{man1dir}, $opts{man1ext});
+        }, $opts{man1dir}, $opts{man1ext}, 'pod');
 
 # Install the pods for library modules.
-pod2man('lib', $opts{man3dir}, $opts{man3ext});
+{
+    # manpages not to be installed
+    my %do_not_install = map { ($_ => 1) }
+        qw(Pod/Functions.pm XS/APItest.pm XS/Typemap.pm);
+
+    my %modpods;
+    File::Find::find({no_chdir=>1,
+                      wanted => sub {
+                          # $_ is $File::Find::name when using no_chdir
+                          if (-f $_ and /\.p(?:m|od)$/) {
+                              my $pod = $_;
+                              # Skip .pm files that have corresponding .pod files
+                              return if $pod =~ s/\.pm$/.pod/ && -f $pod;
+                              return if m!(?:^|/)t/!;
+                              s!^lib/!!;
+                              return if $do_not_install{$_};
+                              return if is_duplicate_pod($File::Find::name);
+                              $modpods{$_} = $File::Find::name;
+                          }
+                      }},
+                     'lib');
+
+    pod2man(\%modpods, $opts{man3dir}, $opts{man3ext}, 'lib');
+}
 
 # Install the pods embedded in the installed scripts
 my $has_man1dir = $opts{man1dir} ne '' && -d $opts{man1dir};
@@ -106,51 +122,28 @@ while (<UTILS>) {
 }
 
 sub pod2man {
-    my($what, $mandir, $manext) = @_;
+    my($modpods, $mandir, $manext, $where) = @_;
     if ($mandir eq ' ' or $mandir eq '') {
-        if (ref $what) {
+        if ($where) {
+            warn "Skipping installation of $where man pages.\n"
+        } else {
             warn "Skipping installation of $_ man page.\n"
-                foreach values %$what;
-       } else {
-            warn "Skipping installation of $what man pages.\n"
-       }
-       return;
+                foreach values %$modpods;
+        }
+        return;
     }
 
     if ($opts{verbose}) {
-        if (ref $what) {
-            print "installing $_\n"
-                foreach sort keys %$what;
+        if ($where) {
+            print "installing from $where\n";
         } else {
-            print "installing from $what\n";
+            print "installing $_\n"
+                foreach sort keys %$modpods;
         }
     }
 
     mkpath($mandir, $opts{verbose}, 0777) unless $opts{notify};  # In File::Path
 
-    my $modpods;
-    if (ref $what) {
-        $modpods = $what;
-    }
-    else {
-        # Make a list of all the .pm and .pod files in the directory.
-       File::Find::find({no_chdir=>1,
-                          wanted => sub {
-                              # $_ is $File::Find::name when using no_chdir
-                              if (-f $_ and /\.p(?:m|od)$/) {
-                                  my $pod = $_;
-                                  # Skip .pm files that have corresponding .pod files
-                                  return if $pod =~ s/\.pm$/.pod/ && -f $pod;
-                                  return if m!(?:^|/)t/!;
-                                  s!^\Q$what\E/!!;
-                                  return if $do_not_install{$_};
-                                  return if is_duplicate_pod($File::Find::name);
-                                  $modpods->{$_} = $File::Find::name;
-                              }
-                          }},
-                         $what);
-    }
-
     foreach my $manpage (sort keys %$modpods) {
         my $mod = $modpods->{$manpage};