2 # Generates info for Module::CoreList from this perl tree
3 # run this from the root of a perl tree, using the perl built in that tree.
7 # With an optional arg specifying the root of a CPAN mirror, outputs the
8 # %upstream and %bug_tracker hashes too.
10 use 5.010001; # needs Parse::CPAN::Meta
15 use ExtUtils::MM_Unix;
17 use Maintainers qw(%Modules files_to_modules);
25 die "usage: $0 [ cpan-mirror/ ]\n" unless @ARGV <= 1;
28 if (! -f 'MANIFEST') {
29 die "Must be run from the root of a clean perl tree\n"
34 = File::Spec->catfile($cpan, 'modules', '02packages.details.txt');
35 open my $fh, '<', $modlistfile or die "Couldn't open $modlistfile: $!";
39 die "Incompatible modlist format"
40 unless <$fh> =~ /^Columns: +package name, version, path/m;
43 # Converting the file to a hash is about 5 times faster than a regexp flat
46 next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/;
52 /(\.pm|_pm\.PL)$/ or return;
53 /PPPort\.pm$/ and return;
54 my $module = $File::Find::name;
55 $module =~ /\b(demo|t|private)\b/ and return; # demo or test modules
56 my $version = MM->parse_version($_);
57 defined $version or $version = 'undef';
58 $version =~ /\d/ and $version = "'$version'";
59 # some heuristics to figure out the module name from the file name
60 $module =~ s{^(lib|(win32/|vms/|symbian/)?ext)/}{}
62 and ( $module =~ s{\b(\w+)/\1\b}{$1},
63 $module =~ s{^B/O}{O},
64 $module =~ s{^Devel-PPPort}{Devel},
65 $module =~ s{^Encode/encoding}{encoding},
66 $module =~ s{^IPC-SysV/}{IPC/},
67 $module =~ s{^MIME-Base64/QuotedPrint}{MIME/QuotedPrint},
68 $module =~ s{^(?:DynaLoader|Errno|Opcode)/}{},
72 $module =~ s{^.*::lib::}{};
73 $module =~ s/(\.pm|_pm\.PL)$//;
74 $lines{$module} = $version;
75 $module_to_file{$module} = $File::Find::name;
76 }, 'lib', 'ext', 'vms/ext', 'symbian/ext');
78 -e 'configpm' and $lines{Config} = 'undef';
80 if (open my $ucdv, "<", "lib/unicore/version") {
81 chomp (my $ucd = <$ucdv>);
82 $lines{Unicode} = "'$ucd'";
91 printf "\t%-24s=> $lines{$_},\n", "'$_'" foreach sort keys %lines;
96 # We have to go through this two stage lookup, given how Maintainers.pl keys its
97 # data by "Module", which is really a dist.
98 my $file_to_M = files_to_modules(values %module_to_file);
100 my %module_to_upstream;
102 my %dist_to_meta_YAML;
103 while (my ($module, $file) = each %module_to_file) {
104 my $M = $file_to_M->{$file};
106 next if $Modules{$M}{MAINTAINER} eq 'p5p';
107 $module_to_upstream{$module} = $Modules{$M}{UPSTREAM};
108 next if defined $module_to_upstream{$module} &&
109 $module_to_upstream{$module} =~ /^(?:blead|first-come)$/;
110 my $dist = $modlist{$module};
112 warn "Can't find a distribution for $module";
115 $module_to_dist{$module} = $dist;
117 next if exists $dist_to_meta_YAML{$dist};
119 $dist_to_meta_YAML{$dist} = undef;
121 # Like it or lump it, this has to be Unix format.
122 my $meta_YAML_path = "$cpan/authors/id/$dist";
123 $meta_YAML_path =~ s/(?:tar\.gz|zip)$/meta/ or die "$meta_YAML_path";
124 unless (-e $meta_YAML_path) {
125 warn "$meta_YAML_path does not exist for $module";
126 # I tried code to open the tarballs with Archive::Tar to find and
127 # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one,
128 # so it's not worth including.
131 require Parse::CPAN::Meta;
132 $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile($meta_YAML_path);
135 print "\n%upstream = (\n";
136 foreach my $module (sort keys %module_to_upstream) {
137 my $upstream = defined $module_to_upstream{$module}
138 ? "'$module_to_upstream{$module}'" : 'undef';
139 printf " %-24s=> $upstream,\n", "'$module'";
143 print "\n%bug_tracker = (\n";
144 foreach my $module (sort keys %module_to_upstream) {
145 my $upstream = defined $module_to_upstream{$module};
146 next if defined $upstream
147 and $upstream eq 'blead' || $upstream eq 'first-come';
151 my $dist = $module_to_dist{$module};
152 $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker}
155 $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef';
156 next if $bug_tracker eq "'http://rt.perl.org/perlbug/'";
157 printf " %-24s=> $bug_tracker,\n", "'$module'";