2 # Generates info for Module::CoreList from this perl tree
3 # run this from the root of a perl tree
7 # With an optional arg specifying the root of a CPAN mirror, outputs the
8 # %upstream and %bug_tracker hashes too.
13 use ExtUtils::MM_Unix;
16 use Maintainers qw(%Modules files_to_modules);
18 use Parse::CPAN::Meta;
19 use IPC::Cmd 'can_run';
21 my $corelist_file = 'dist/Module-CoreList/lib/Module/CoreList.pm';
27 die "usage: $0 [ cpan-mirror/ ] [ 5.x.y] \n" unless @ARGV <= 2;
29 my $raw_version = shift || $];
30 my $perl_version = version->parse("$raw_version");
31 my $perl_vnum = $perl_version->numify;
32 my $perl_vstring = $perl_version->normal; # how do we get version.pm to not give us leading v?
33 $perl_vstring =~ s/^v//;
35 if ( !-f 'MANIFEST' ) {
36 die "Must be run from the root of a clean perl tree\n";
39 open( my $corelist_fh, '<', $corelist_file ) || die "Could not open $corelist_file: $!";
40 my $corelist = join( '', <$corelist_fh> );
43 my $modlistfile = File::Spec->catfile( $cpan, 'modules', '02packages.details.txt' );
47 if ( -e $modlistfile ) {
48 warn "Reading the module list from $modlistfile";
49 open $fh, '<', $modlistfile or die "Couldn't open $modlistfile: $!";
50 } elsif ( -e $modlistfile . ".gz" ) {
51 my $zcat = can_run('gzcat') || can_run('zcat') or die "Can't find gzcat or zcat";
52 warn "Reading the module list from $modlistfile.gz";
53 open $fh, '-|', "$zcat $modlistfile.gz" or die "Couldn't zcat $modlistfile.gz: $!";
55 warn "About to fetch 02packages from ftp.funet.fi. This may take a few minutes\n";
56 $content = fetch_url('http://ftp.funet.fi/pub/CPAN/modules/02packages.details.txt');
58 die "Unable to read 02packages.details.txt from either your CPAN mirror or ftp.funet.fi";
62 if ( $fh and !$content ) {
64 $content = join( '', <$fh> );
67 die "Incompatible modlist format"
68 unless $content =~ /^Columns: +package name, version, path/m;
70 # Converting the file to a hash is about 5 times faster than a regexp flat
72 for ( split( qr/\n/, $content ) ) {
73 next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/;
80 /(\.pm|_pm\.PL)$/ or return;
81 /PPPort\.pm$/ and return;
82 my $module = $File::Find::name;
83 $module =~ /\b(demo|t|private)\b/ and return; # demo or test modules
84 my $version = MM->parse_version($_);
85 defined $version or $version = 'undef';
86 $version =~ /\d/ and $version = "'$version'";
88 # some heuristics to figure out the module name from the file name
89 $module =~ s{^(lib|cpan|dist|(?:vms/|symbian/)?ext)/}{}
92 $module =~ s{\b(\w+)/\1\b}{$1},
93 $module =~ s{^B/O}{O},
94 $module =~ s{^Devel-PPPort}{Devel},
95 $module =~ s{^libnet/}{},
96 $module =~ s{^Encode/encoding}{encoding},
97 $module =~ s{^IPC-SysV/}{IPC/},
98 $module =~ s{^MIME-Base64/QuotedPrint}{MIME/QuotedPrint},
99 $module =~ s{^(?:DynaLoader|Errno|Opcode)/}{},
101 $module =~ s{^lib/}{}g;
102 $module =~ s{/}{::}g;
103 $module =~ s{-}{::}g;
104 $module =~ s{^.*::lib::}{}; # turns Foo/lib/Foo.pm into Foo.pm
105 $module =~ s/(\.pm|_pm\.PL)$//;
106 $lines{$module} = $version;
107 $module_to_file{$module} = $File::Find::name;
117 -e 'configpm' and $lines{Config} = 'undef';
119 if ( open my $ucdv, "<", "lib/unicore/version" ) {
120 chomp( my $ucd = <$ucdv> );
121 $lines{Unicode} = "'$ucd'";
125 my $versions_in_release = " " . $perl_vnum . " => {\n";
126 foreach my $key ( sort keys %lines ) {
127 $versions_in_release .= sprintf "\t%-24s=> %s,\n", "'$key'", $lines{$key};
129 $versions_in_release .= " },\n";
131 $corelist =~ s/^(%version\s*=\s*.*?)(^\);)$/$1$versions_in_release$2/xism;
133 exit unless %modlist;
135 # We have to go through this two stage lookup, given how Maintainers.pl keys its
136 # data by "Module", which is really a dist.
137 my $file_to_M = files_to_modules( values %module_to_file );
139 my %module_to_upstream;
141 my %dist_to_meta_YAML;
142 my %module_to_deprecated;
143 while ( my ( $module, $file ) = each %module_to_file ) {
144 my $M = $file_to_M->{$file};
146 next if $Modules{$M}{MAINTAINER} eq 'p5p';
147 $module_to_upstream{$module} = $Modules{$M}{UPSTREAM};
148 $module_to_deprecated{$module} = 1 if $Modules{$M}{DEPRECATED};
150 if defined $module_to_upstream{$module}
151 && $module_to_upstream{$module} =~ /^(?:blead|first-come)$/;
152 my $dist = $modlist{$module};
154 warn "Can't find a distribution for $module\n";
157 $module_to_dist{$module} = $dist;
159 next if exists $dist_to_meta_YAML{$dist};
161 $dist_to_meta_YAML{$dist} = undef;
163 # Like it or lump it, this has to be Unix format.
164 my $meta_YAML_path = "authors/id/$dist";
165 $meta_YAML_path =~ s/(?:tar\.gz|tar\.bz2|zip)$/meta/ or die "$meta_YAML_path";
166 my $meta_YAML_url = 'http://ftp.funet.fi/pub/CPAN/' . $meta_YAML_path;
168 if ( -e "$cpan/$meta_YAML_path" ) {
169 $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile( $cpan . "/" . $meta_YAML_path );
170 } elsif ( my $content = fetch_url($meta_YAML_url) ) {
172 warn "Failed to fetch $meta_YAML_url\n";
175 eval { $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::Load($content); };
176 if ( my $err = $@ ) {
177 warn "$meta_YAML_path: ".$err;
181 warn "$meta_YAML_path does not exist for $module\n";
183 # I tried code to open the tarballs with Archive::Tar to find and
184 # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one,
185 # so it's not worth including.
190 my $upstream_stanza = "%upstream = (\n";
191 foreach my $module ( sort keys %module_to_upstream ) {
192 my $upstream = defined $module_to_upstream{$module} ? "'$module_to_upstream{$module}'" : 'undef';
193 $upstream_stanza .= sprintf " %-24s=> %s,\n", "'$module'", $upstream;
195 $upstream_stanza .= ");";
197 $corelist =~ s/^%upstream .*? ;$/$upstream_stanza/ismx;
199 # Deprecation generation
200 my $deprecated_stanza = " " . $perl_vnum . " => {\n";
201 foreach my $module ( sort keys %module_to_deprecated ) {
202 my $deprecated = defined $module_to_deprecated{$module} ? "'$module_to_deprecated{$module}'" : 'undef';
203 $deprecated_stanza .= sprintf "\t%-24s=> %s,\n", "'$module'", $deprecated;
205 $deprecated_stanza .= " },\n";
206 $corelist =~ s/^(%deprecated\s*=\s*.*?)(^\);)$/$1$deprecated_stanza$2/xism;
208 my $tracker = "%bug_tracker = (\n";
209 foreach my $module ( sort keys %module_to_upstream ) {
210 my $upstream = defined $module_to_upstream{$module};
213 and $upstream eq 'blead' || $upstream eq 'first-come';
217 my $dist = $module_to_dist{$module};
218 $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker}
221 $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef';
222 next if $bug_tracker eq "'http://rt.perl.org/perlbug/'";
223 $tracker .= sprintf " %-24s=> %s,\n", "'$module'", $bug_tracker;
227 $corelist =~ s/^%bug_tracker .*? ;/$tracker/eismx;
229 unless ( $corelist =~ /and $perl_vstring releases of perl/ ) {
230 warn "Adding $perl_vstring to the list of perl versions covered by Module::CoreList\n";
231 $corelist =~ s/\s*and (.*?) releases of perl/, $1 and $perl_vstring releases of perl/ism;
235 $corelist =~ /^%released \s* = \s* \(
241 warn "Adding $perl_vnum to the list of released perl versions. Please consider adding a release date.\n";
242 $corelist =~ s/^(%released \s* = \s* .*?) ( \) )
243 /$1 $perl_vnum => '????-??-??',\n $2/ismx;
246 write_corelist($corelist);
248 warn "All done. Please check over $corelist_file carefully before committing. Thanks!\n";
253 open (my $clfh, ">", $corelist_file) || die "Failed to open $corelist_file for writing: $!";
254 print $clfh $content || die "Failed to write the new CoreList.pm: $!";
260 eval { require LWP::Simple };
261 if ( LWP::Simple->can('get') ) {
262 return LWP::Simple->get($url);
263 } elsif (`which curl`) {
264 return `curl -s $url`;
265 } elsif (`which wget`) {
266 return `wget -q -O - $url`;