Skip to content

Commit

Permalink
Move the common Pod scanning code from installman and buildtoc to pod…
Browse files Browse the repository at this point in the history
…_lib.pl

The unified code to scan lib/ for Pod is now in pods_to_install().
It returns found Pods partitioned into 'MODULE' and 'PRAGMA', as buildtoc
needs this distinction. installman installs Pods in the same order as before,
as 'PRAGMA' sort lexically after 'MODULE'.
  • Loading branch information
nwc10 committed Dec 24, 2011
1 parent 3bf2933 commit 9bbb230
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 57 deletions.
31 changes: 31 additions & 0 deletions Porting/pod_lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use strict;
use Digest::MD5 'md5';
use File::Find;

# make it clearer when we haven't run to completion, as we can be quite
# noisy when things are working ok
Expand Down Expand Up @@ -37,6 +38,36 @@ sub write_or_die {
close $fh or die "Can't close $filename: $!";
}

sub pods_to_install {
# manpages not to be installed
my %do_not_install = map { ($_ => 1) }
qw(Pod::Functions XS::APItest XS::Typemap);

my (%done, %found);

File::Find::find({no_chdir=>1,
wanted => sub {
# $_ is $File::Find::name when using no_chdir
return unless m!\.p(?:m|od)\z! && -f $_;
return if m!(?:^|/)t/!;
return if m!lib/Net/FTP/.+\.pm\z!; # Hi, Graham! :-)
# Skip .pm files that have corresponding .pod files
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;

return if $do_not_install{$_};
return if is_duplicate_pod($File::Find::name);
$found{/\A[a-z]/ ? 'PRAGMA' : 'MODULE'}{$_}
= $File::Find::name;
}}, 'lib');
return \%found;
}

my %state = (
# Don't copy these top level READMEs
Expand Down
29 changes: 3 additions & 26 deletions installman
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ BEGIN {
use strict;

use Getopt::Long;
use File::Find;
use File::Path qw(mkpath);
use ExtUtils::Packlist;
use Pod::Man;
Expand Down Expand Up @@ -73,31 +72,9 @@ pod2man({

# Install the pods for library modules.
{
# manpages not to be installed
my %do_not_install = map { ($_ => 1) }
qw(Pod::Functions XS::APItest XS::Typemap);

my %modpods;
File::Find::find({no_chdir=>1,
wanted => sub {
# $_ is $File::Find::name when using no_chdir
if (-f $_ and /\.p(?:m|od)$/) {
return if m!(?:^|/)t/!;
return if m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
# Skip .pm files that have corresponding .pod files
return if s!\.pm\z!.pod! && -e $_;
s!\.pod\z!!;
s!\Alib/!!;
s!/!::!g;
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');
my $found = pods_to_install();
pod2man($found->{$_}, $opts{man3dir}, $opts{man3ext}, 'lib')
foreach qw(MODULE PRAGMA);
}

# Install the pods embedded in the installed scripts
Expand Down
37 changes: 6 additions & 31 deletions pod/buildtoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/perl -w

use strict;
use vars qw(%Found $Quiet);
use vars qw($Quiet);
use File::Spec;
use File::Find;
use FindBin;
use Text::Wrap;
use Getopt::Long;
Expand All @@ -23,33 +22,9 @@ die "$0: Usage: $0 [--quiet]\n"

my $state = get_pod_metadata(0, sub { warn @_ if @_ }, 'pod/perltoc.pod');

# Find all the modules
# manpages not to be installed
my %do_not_install = map { ($_ => 1) }
qw(Pod::Functions XS::APItest XS::Typemap);

my %done;
find({no_chdir => 1,
wanted => sub {
if (/\.p(od|m)$/) {
return if m!(?:^|/)t/!;
return if m!lib/Net/FTP/.+\.pm!; # Hi, Graham! :-)
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;

return if $do_not_install{$_};
return if is_duplicate_pod($File::Find::name);

$Found{/\A[a-z]/ ? 'PRAGMA' : 'MODULE'}{$_} = $File::Find::name;
}
}}, 'lib');

my_die "Can't find any pods!\n" unless %done;
my $found = pods_to_install();

my_die "Can't find any pods!\n" unless %$found;

# 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
Expand Down Expand Up @@ -95,9 +70,9 @@ foreach my $type (qw(PRAGMA MODULE)) {
EOPOD2B

foreach my $name (sort keys %{$Found{$type}}) {
foreach my $name (sort keys %{$found->{$type}}) {
$roffitall .= " \$libdir/$name.3 \\\n";
podset($name, $Found{$type}{$name});
podset($name, $found->{$type}{$name});
}
}

Expand Down

0 comments on commit 9bbb230

Please sign in to comment.