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;
20 my $corelist_file = 'dist/Module-CoreList/lib/Module/CoreList.pm';
26 die "usage: $0 [ cpan-mirror/ ] [ 5.x.y] \n" unless @ARGV <= 2;
28 my $raw_version = shift || $];
29 my $perl_version = version->parse("$raw_version");
30 my $perl_vnum = $perl_version->numify;
31 my $perl_vstring = $perl_version->normal; # how do we get version.pm to not give us leading v?
32 $perl_vstring =~ s/^v//;
34 if ( !-f 'MANIFEST' ) {
35 die "Must be run from the root of a clean perl tree\n";
38 open( my $corelist_fh, '<', $corelist_file ) || die "Could not open $corelist_file: $!";
39 my $corelist = join( '', <$corelist_fh> );
42 my $modlistfile = File::Spec->catfile( $cpan, 'modules', '02packages.details.txt' );
46 if ( -e $modlistfile ) {
47 warn "Reading the module list from $modlistfile";
48 open $fh, '<', $modlistfile or die "Couldn't open $modlistfile: $!";
49 } elsif ( -e $modlistfile . ".gz" ) {
50 warn "Reading the module list from $modlistfile.gz";
51 open $fh, '-|', "gzcat $modlistfile.gz" or die "Couldn't zcat $modlistfile.gz: $!";
53 warn "About to fetch 02packages from ftp.funet.fi. This may take a few minutes\n";
54 $content = fetch_url('http://ftp.funet.fi/pub/CPAN/modules/02packages.details.txt');
56 die "Unable to read 02packages.details.txt from either your CPAN mirror or ftp.funet.fi";
60 if ( $fh and !$content ) {
62 $content = join( '', <$fh> );
65 die "Incompatible modlist format"
66 unless $content =~ /^Columns: +package name, version, path/m;
68 # Converting the file to a hash is about 5 times faster than a regexp flat
70 for ( split( qr/\n/, $content ) ) {
71 next unless /^([A-Za-z_:0-9]+) +[-0-9.undefHASHVERSIONvsetwhenloadingbogus]+ +(\S+)/;
78 /(\.pm|_pm\.PL)$/ or return;
79 /PPPort\.pm$/ and return;
80 my $module = $File::Find::name;
82 $module =~ /\b(demo|t|private)\b/ and return; # demo or test modules
83 my $version = MM->parse_version($_);
84 defined $version or $version = 'undef';
85 $version =~ /\d/ and $version = "'$version'";
87 # some heuristics to figure out the module name from the file name
88 $module =~ s{^(lib|dist|(win32/|vms/|symbian/)?ext)/}{}
91 $module =~ s{\b(\w+)/\1\b}{$1},
92 $module =~ s{^B/O}{O},
93 $module =~ s{^Devel-PPPort}{Devel},
94 $module =~ s{^Encode/encoding}{encoding},
95 $module =~ s{^IPC-SysV/}{IPC/},
96 $module =~ s{^MIME-Base64/QuotedPrint}{MIME/QuotedPrint},
97 $module =~ s{^(?:DynaLoader|Errno|Opcode)/}{},
100 $module =~ s{-}{::}g;
101 $module =~ s{^.*::lib::}{};
102 $module =~ s/(\.pm|_pm\.PL)$//;
103 $lines{$module} = $version;
104 $module_to_file{$module} = $File::Find::name;
113 -e 'configpm' and $lines{Config} = 'undef';
115 if ( open my $ucdv, "<", "lib/unicore/version" ) {
116 chomp( my $ucd = <$ucdv> );
117 $lines{Unicode} = "'$ucd'";
121 my $versions_in_release = " " . $perl_vnum . " => {\n";
122 foreach my $key ( sort keys %lines ) {
123 $versions_in_release .= sprintf "\t%-24s=> %s,\n", "'$key'", $lines{$key};
125 $versions_in_release .= " },\n";
127 $corelist =~ s/^(%version\s*=\s*.*?)(^\);)$/$1$versions_in_release$2/xism;
129 exit unless %modlist;
131 # We have to go through this two stage lookup, given how Maintainers.pl keys its
132 # data by "Module", which is really a dist.
133 my $file_to_M = files_to_modules( values %module_to_file );
135 my %module_to_upstream;
137 my %dist_to_meta_YAML;
138 while ( my ( $module, $file ) = each %module_to_file ) {
139 my $M = $file_to_M->{$file};
141 next if $Modules{$M}{MAINTAINER} eq 'p5p';
142 $module_to_upstream{$module} = $Modules{$M}{UPSTREAM};
144 if defined $module_to_upstream{$module}
145 && $module_to_upstream{$module} =~ /^(?:blead|first-come)$/;
146 my $dist = $modlist{$module};
148 warn "Can't find a distribution for $module\n";
151 $module_to_dist{$module} = $dist;
153 next if exists $dist_to_meta_YAML{$dist};
155 $dist_to_meta_YAML{$dist} = undef;
157 # Like it or lump it, this has to be Unix format.
158 my $meta_YAML_path = "authors/id/$dist";
159 $meta_YAML_path =~ s/(?:tar\.gz|zip)$/meta/ or die "$meta_YAML_path";
160 my $meta_YAML_url = 'http://ftp.funet.fi/pub/CPAN/' . $meta_YAML_path;
162 if ( -e "$cpan/$meta_YAML_path" ) {
163 $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::LoadFile( $cpan . "/" . $meta_YAML_path );
164 } elsif ( my $content = fetch_url($meta_YAML_url) ) {
166 warn "Failed to fetch $meta_YAML_url\n";
169 eval { $dist_to_meta_YAML{$dist} = Parse::CPAN::Meta::Load($content); };
170 if ( my $err = $@ ) {
171 warn "$meta_YAML_path: ".$err;
175 warn "$meta_YAML_path does not exist for $module\n";
177 # I tried code to open the tarballs with Archive::Tar to find and
178 # extract META.yml, but only Text-Tabs+Wrap-2006.1117.tar.gz had one,
179 # so it's not worth including.
184 my $upstream_stanza = "%upstream = (\n";
185 foreach my $module ( sort keys %module_to_upstream ) {
186 my $upstream = defined $module_to_upstream{$module} ? "'$module_to_upstream{$module}'" : 'undef';
187 $upstream_stanza .= sprintf " %-24s=> %s,\n", "'$module'", $upstream;
189 $upstream_stanza .= ");";
191 $corelist =~ s/^%upstream .*? ;$/$upstream_stanza/ismx;
193 my $tracker = "%bug_tracker = (\n";
194 foreach my $module ( sort keys %module_to_upstream ) {
195 my $upstream = defined $module_to_upstream{$module};
198 and $upstream eq 'blead' || $upstream eq 'first-come';
202 my $dist = $module_to_dist{$module};
203 $bug_tracker = $dist_to_meta_YAML{$dist}->{resources}{bugtracker}
206 $bug_tracker = defined $bug_tracker ? "'$bug_tracker'" : 'undef';
207 next if $bug_tracker eq "'http://rt.perl.org/perlbug/'";
208 $tracker .= sprintf " %-24s=> %s,\n", "'$module'", $bug_tracker;
212 $corelist =~ s/^%bug_tracker .*? ;/$tracker/eismx;
214 unless ( $corelist =~ /and $perl_vstring releases of perl/ ) {
215 warn "Adding $perl_vstring to the list of perl versions covered by Module::CoreList\n";
216 $corelist =~ s/\s*and (.*?) releases of perl/, $1 and $perl_vstring releases of perl/ism;
220 $corelist =~ /^%released \s* = \s* \(
226 warn "Adding $perl_vnum to the list of released perl versions. Please consider adding a release date.\n";
227 $corelist =~ s/^(%released \s* = \s* .*?) ( \) )
228 /$1 $perl_vnum => '????-??-??',\n $2/ismx;
231 write_corelist($corelist);
233 warn "All done. Please check over $corelist_file carefully before committing. Thanks!\n";
238 open (my $clfh, ">", $corelist_file) || die "Failed to open $corelist_file for writing: $!";
239 print $clfh $content || die "Failed to write the new CoreList.pm: $!";
245 eval { require LWP::Simple };
246 if ( LWP::Simple->can('get') ) {
247 return LWP::Simple->get($url);
248 } elsif (`which curl`) {
249 return `curl -s $url`;
250 } elsif (`which wget`) {
251 return `wget -q -O - $url`;