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.
14 use ExtUtils::MM_Unix;
17 use Maintainers qw(%Modules files_to_modules);
19 use Parse::CPAN::Meta;
20 use IPC::Cmd 'can_run';
22 use IO::Uncompress::Gunzip;
24 my $corelist_file = 'dist/Module-CoreList/lib/Module/CoreList.pm';
30 die "usage: $0 [ cpan-mirror/ ] [ 5.x.y] \n" unless @ARGV <= 2;
32 my $raw_version = shift || $];
33 my $perl_version = version->parse("$raw_version");
34 my $perl_vnum = $perl_version->numify;
35 my $perl_vstring = $perl_version->normal; # how do we get version.pm to not give us leading v?
36 $perl_vstring =~ s/^v//;
38 if ( !-f 'MANIFEST' ) {
39 die "Must be run from the root of a clean perl tree\n";
42 open( my $corelist_fh, '<', $corelist_file );
43 my $corelist = join( '', <$corelist_fh> );
46 my $modlistfile = File::Spec->catfile( $cpan, 'modules', '02packages.details.txt' );
50 if ( -e $modlistfile ) {
51 warn "Reading the module list from $modlistfile";
52 open $fh, '<', $modlistfile;
53 } elsif ( -e $modlistfile . ".gz" ) {
54 my $zcat = can_run('gzcat') || can_run('zcat') or die "Can't find gzcat or zcat";
55 warn "Reading the module list from $modlistfile.gz";
56 open $fh, '-|', "$zcat $modlistfile.gz";
58 warn "About to fetch 02packages from ftp.funet.fi. This may take a few minutes\n";
59 my $gzipped_content = fetch_url('http://ftp.funet.fi/pub/CPAN/modules/02packages.details.txt.gz');
60 unless ($gzipped_content) {
61 die "Unable to read 02packages.details.txt from either your CPAN mirror or ftp.funet.fi";
63 IO::Uncompress::Gunzip::gunzip(\$gzipped_content, \$content, Transparent => 0)
64 or die "Can't gunzip content: $IO::Uncompress::Gunzip::GunzipError";
67 if ( $fh and !$content ) {
69 $content = join( '', <$fh> );
72 die "Incompatible modlist format"
73 unless $content =~ /^Columns: +package name, version, path/m;
75 # Converting the file to a hash is about 5 times faster than a regexp flat
77 for ( split( qr/\n/, $content ) ) {
78 next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/;
85 /(\.pm|_pm\.PL)$/ or return;
86 /PPPort\.pm$/ and return;
87 my $module = $File::Find::name;
88 $module =~ /\b(demo|t|private)\b/ and return; # demo or test modules
89 my $version = MM->parse_version($_);
90 defined $version or $version = 'undef';
91 $version =~ /\d/ and $version = "'$version'";
93 # some heuristics to figure out the module name from the file name
94 $module =~ s{^(lib|cpan|dist|(?:symbian/)?ext)/}{}
97 $module =~ s{\b(\w+)/\1\b}{$1},
98 $module =~ s{^B/O}{O},
99 $module =~ s{^Devel-PPPort}{Devel},
100 $module =~ s{^libnet/}{},
101 $module =~ s{^Encode/encoding}{encoding},
102 $module =~ s{^IPC-SysV/}{IPC/},
103 $module =~ s{^MIME-Base64/QuotedPrint}{MIME/QuotedPrint},
104 $module =~ s{^(?:DynaLoader|Errno|Opcode|XSLoader)/}{},
105 $module =~ s{^Sys-Syslog/win32}{Sys-Syslog},
106 $module =~ s{^Time-Piece/Seconds}{Time/Seconds},
108 $module =~ s{^vms/ext}{VMS};
109 $module =~ s{^lib/}{}g;
110 $module =~ s{/}{::}g;
111 $module =~ s{-}{::}g;
112 $module =~ s{^.*::lib::}{}; # turns Foo/lib/Foo.pm into Foo.pm
113 $module =~ s/(\.pm|_pm\.PL)$//;
114 $lines{$module} = $version;
115 $module_to_file{$module} = $File::Find::name;
125 -e 'configpm' and $lines{Config} = 'undef';
127 if ( open my $ucdv, "<", "lib/unicore/version" ) {
128 chomp( my $ucd = <$ucdv> );
129 $lines{Unicode} = "'$ucd'";
133 my $versions_in_release = " " . $perl_vnum . " => {\n";
134 foreach my $key ( sort keys %lines ) {
135 $versions_in_release .= sprintf "\t%-24s=> %s,\n", "'$key'", $lines{$key};
137 $versions_in_release .= " },\n";
139 $corelist =~ s/^(%version\s*=\s*.*?)(^\);)$/$1$versions_in_release$2/xism;
141 exit unless %modlist;
143 # We have to go through this two stage lookup, given how Maintainers.pl keys its
144 # data by "Module", which is really a dist.
145 my $file_to_M = files_to_modules( values %module_to_file );
147 my %module_to_upstream;
149 my %dist_to_meta_YAML;
150 my %module_to_deprecated;
151 while ( my ( $module, $file ) = each %module_to_file ) {
152 my $M = $file_to_M->{$file};
154 next if $Modules{$M}{MAINTAINER} eq 'p5p';
155 $module_to_upstream{$module} = $Modules{$M}{UPSTREAM};
156 $module_to_deprecated{$module} = 1 if $Modules{$M}{DEPRECATED};
158 if defined $module_to_upstream{$module}
159 && $module_to_upstream{$module} =~ /^(?:blead|first-come)$/;
160 my $dist = $modlist{$module};
162 warn "Can't find a distribution for $module\n";
165 $module_to_dist{$module} = $dist;
167 next if exists $dist_to_meta_YAML{$dist};
169 $dist_to_meta_YAML{$dist} = undef;
171 # Like it or lump it, this has to be Unix format.
172 my $meta_YAML_path = "authors/id/$dist";
173 $meta_YAML_path =~ s/(?:tar\.gz|tar\.bz2|zip)$/meta/ or die "$meta_YAML_path";
174 my $meta_YAML_url = 'http://ftp.funet.fi/pub/CPAN/' . $meta_YAML_path;
176 if ( -e "$cpan/$meta_YAML_path" ) {
177 $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile( $cpan . "/" . $meta_YAML_path );
178 } elsif ( my $content = fetch_url($meta_YAML_url) ) {
180 warn "Failed to fetch $meta_YAML_url\n";
183 eval { $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::Load($content); };
184 if ( my $err = $@ ) {
185 warn "$meta_YAML_path: ".$err;
189 warn "$meta_YAML_path does not exist for $module\n";
191 # I tried code to open the tarballs with Archive::Tar to find and
192 # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one,
193 # so it's not worth including.
198 my $upstream_stanza = "%upstream = (\n";
199 foreach my $module ( sort keys %module_to_upstream ) {
200 my $upstream = defined $module_to_upstream{$module} ? "'$module_to_upstream{$module}'" : 'undef';
201 $upstream_stanza .= sprintf " %-24s=> %s,\n", "'$module'", $upstream;
203 $upstream_stanza .= ");";
205 $corelist =~ s/^%upstream .*? ;$/$upstream_stanza/ismx;
207 # Deprecation generation
208 my $deprecated_stanza = " " . $perl_vnum . " => {\n";
209 foreach my $module ( sort keys %module_to_deprecated ) {
210 my $deprecated = defined $module_to_deprecated{$module} ? "'$module_to_deprecated{$module}'" : 'undef';
211 $deprecated_stanza .= sprintf "\t%-24s=> %s,\n", "'$module'", $deprecated;
213 $deprecated_stanza .= " },\n";
214 $corelist =~ s/^(%deprecated\s*=\s*.*?)(^\);)$/$1$deprecated_stanza$2/xism;
216 my $tracker = "%bug_tracker = (\n";
217 foreach my $module ( sort keys %module_to_upstream ) {
218 my $upstream = defined $module_to_upstream{$module};
221 and $upstream eq 'blead' || $upstream eq 'first-come';
225 my $dist = $module_to_dist{$module};
226 $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker}
229 $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef';
230 next if $bug_tracker eq "'http://rt.perl.org/perlbug/'";
231 $tracker .= sprintf " %-24s=> %s,\n", "'$module'", $bug_tracker;
235 $corelist =~ s/^%bug_tracker .*? ;/$tracker/eismx;
237 unless ( $corelist =~ /and $perl_vstring releases of perl/ ) {
238 warn "Adding $perl_vstring to the list of perl versions covered by Module::CoreList\n";
239 $corelist =~ s/(currently covers (?:.*?))\s*and (.*?) releases of perl/$1, $2 and $perl_vstring releases of perl/ism;
243 $corelist =~ /^%released \s* = \s* \(
249 warn "Adding $perl_vnum to the list of released perl versions. Please consider adding a release date.\n";
250 $corelist =~ s/^(%released \s* = \s* .*?) ( \) )
251 /$1 $perl_vnum => '????-??-??',\n $2/ismx;
254 write_corelist($corelist);
256 warn "All done. Please check over $corelist_file carefully before committing. Thanks!\n";
261 open (my $clfh, ">", $corelist_file);
262 print $clfh $content;
268 my $http = HTTP::Tiny->new;
269 my $response = $http->get($url);
270 if ($response->{success}) {
271 return $response->{content};
273 warn "Error fetching $url: $response->{status} $response->{reason}\n";