This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127494] TODO test for $AUTOLOAD being set for DESTROY
[perl5.git] / Porting / corecpan.pl
old mode 100644 (file)
new mode 100755 (executable)
index d035bcd..3a38d11
@@ -44,7 +44,7 @@ our $opt_h and usage;
 our $opt_t;
 
 my @sources = @ARGV ? @ARGV : '.';
-die "Too many directories speficied without -t option\n"
+die "Too many directories specified without -t option\n"
     if @sources != 1 and ! $opt_t;
 
 @sources = map {
@@ -81,19 +81,25 @@ foreach my $source (@sources) {
     for my $dist (sort keys %Modules) {
        next unless $Modules{$dist}{CPAN};
        for my $file (get_module_files($dist)) {
-           next if $file !~ /\.pm\z/ or $file =~ m{^t/} or $file =~ m{/t/};
+           next if $file !~ /(\.pm|_pm.PL)\z/
+                       or $file =~ m{^t/} or $file =~ m{/t/};
            my $vcore = '!EXIST';
            $vcore = MM->parse_version($file) // 'undef' if -f $file;
+
+           # get module name from filename to lookup CPAN version
            my $module = $file;
+           $module =~ s/\_pm.PL\z//;
            $module =~ s/\.pm\z//;
            # some heuristics to figure out the module name from the file name
-           $module =~ s{^(lib|ext)/}{}
-               and $1 eq 'ext'
-               and ( $module =~ s{^(.*)/lib/\1\b}{$1},
-                     $module =~ s{(\w+)/\1\b}{$1},
-                     $module =~ s{^Encode/encoding}{encoding},
-                     $module =~ s{^MIME/Base64/QuotedPrint}{MIME/QuotedPrint},
-                     $module =~ s{^List/Util/lib/Scalar}{Scalar},
+           $module =~ s{^(lib|ext|dist|cpan)/}{}
+               and $1 =~ /(?:ext|dist|cpan)/
+               and (
+                     # ext/Foo-Bar/Bar.pm
+                     $module =~ s{^(\w+)-(\w+)/\2$}{$1/lib/$1/$2},
+                     # ext/Encode/Foo/Foo.pm
+                     $module =~ s{^(Encode)/(\w+)/\2$}{$1/lib/$1/$2},
+                     $module =~ s{^[^/]+/}{},
+                     $module =~ s{^lib/}{},
                    );
            $module =~ s{/}{::}g;
            my $vcpan = $cpanversions{$module} // 'undef';
@@ -149,11 +155,12 @@ if ($opt_t) {
 }
 else {
     for my $dist (sort { lc $a cmp lc $b } keys %results) {
-       print "Module $dist...\n";
+       my $distname_printed = 0;
        for my $file (sort keys %{$results{$dist}}) {
            my ($vcore, $vcpan) = @{$results{$dist}{$file}}{@labels};
            if (our $opt_v or $vcore ne $vcpan) {
-               print "    $file: core=$vcore, cpan=$vcpan\n";
+               print "\n$dist ($Modules{$dist}{MAINTAINER}):\n" unless ($distname_printed++);
+               print "\t$file: core=$vcore, cpan=$vcpan\n";
            }
        }
     }