This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
upgrade Module-Metadata to 1.000032
authorKaren Etheridge <ether@cpan.org>
Mon, 16 May 2016 02:19:01 +0000 (19:19 -0700)
committerJames E Keenan <jkeenan@cpan.org>
Mon, 16 May 2016 10:09:59 +0000 (06:09 -0400)
Porting/Maintainers.pl
cpan/Module-Metadata/lib/Module/Metadata.pm
cpan/Module-Metadata/t/extract-package.t
cpan/Module-Metadata/t/extract-version.t
cpan/Module-Metadata/t/metadata.t

index c581008..e3c102d 100755 (executable)
@@ -854,7 +854,7 @@ use File::Glob qw(:case);
     },
 
     'Module::Metadata' => {
-        'DISTRIBUTION' => 'ETHER/Module-Metadata-1.000031-TRIAL.tar.gz',
+        'DISTRIBUTION' => 'ETHER/Module-Metadata-1.000032-TRIAL.tar.gz',
         'FILES'        => q[cpan/Module-Metadata],
         'EXCLUDED'     => [
             qw(t/00-report-prereqs.t),
index f7017cf..e8c2b25 100644 (file)
@@ -1,6 +1,6 @@
 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
-# vim:ts=8:sw=2:et:sta:sts=2
-package Module::Metadata; # git description: v1.000030-2-g52f466c
+# vim:ts=8:sw=2:et:sta:sts=2:tw=78
+package Module::Metadata; # git description: v1.000031-13-g7c061c9
 # ABSTRACT: Gather package and POD information from perl module files
 
 # Adapted from Perl-licensed code originally distributed with
@@ -14,7 +14,7 @@ sub __clean_eval { eval $_[0] }
 use strict;
 use warnings;
 
-our $VERSION = '1.000031'; # TRIAL
+our $VERSION = '1.000032'; # TRIAL
 
 use Carp qw/croak/;
 use File::Spec;
@@ -411,15 +411,29 @@ sub _init {
   }
   $self->_parse_fh($handle);
 
+  @{$self->{packages}} = __uniq(@{$self->{packages}});
+
   unless($self->{module} and length($self->{module})) {
-    my ($v, $d, $f) = File::Spec->splitpath($self->{filename});
-    if($f =~ /\.pm$/) {
+    # CAVEAT (possible TODO): .pmc files not treated the same as .pm
+    if ($self->{filename} =~ /\.pm$/) {
+      my ($v, $d, $f) = File::Spec->splitpath($self->{filename});
       $f =~ s/\..+$//;
-      my @candidates = grep /$f$/, @{$self->{packages}};
-      $self->{module} = shift(@candidates); # punt
+      my @candidates = grep /(^|::)$f$/, @{$self->{packages}};
+      $self->{module} = shift(@candidates); # this may be undef
     }
     else {
-      $self->{module} = 'main';
+      # this seems like an atrocious heuristic, albeit marginally better than
+      # what was here before. It should be rewritten entirely to be more like
+      # "if it's not a .pm file, it's not require()able as a name, therefore
+      # name() should be undef."
+      if ((grep /main/, @{$self->{packages}})
+          or (grep /main/, keys %{$self->{versions}})) {
+        $self->{module} = 'main';
+      }
+      else {
+        # TODO: this should maybe default to undef instead
+        $self->{module} = $self->{packages}[0] || '';
+      }
     }
   }
 
@@ -440,6 +454,7 @@ sub _do_find_module {
     my $testfile = File::Spec->catfile($dir, $file);
     return [ File::Spec->rel2abs( $testfile ), $dir ]
       if -e $testfile and !-d _;  # For stuff like ExtUtils::xsubpp
+    # CAVEAT (possible TODO): .pmc files are not discoverable here
     $testfile .= '.pm';
     return [ File::Spec->rel2abs( $testfile ), $dir ]
       if -e $testfile;
@@ -649,6 +664,12 @@ sub _parse_fh {
   $self->{pod_headings} = \@pod;
 }
 
+sub __uniq (@)
+{
+    my (%seen, $key);
+    grep { not $seen{ $key = $_ }++ } @_;
+}
+
 {
 my $pn = 0;
 sub _evaluate_version_line {
@@ -820,7 +841,7 @@ Module::Metadata - Gather package and POD information from perl module files
 
 =head1 VERSION
 
-version 1.000031
+version 1.000032
 
 =head1 SYNOPSIS
 
@@ -1037,7 +1058,7 @@ There is also a mailing list available for users of this distribution, at
 L<http://lists.perl.org/list/cpan-workers.html>.
 
 There is also an irc channel available for users of this distribution, at
-L<irc://irc.perl.org/#toolchain>.
+L<C<#toolchain> on C<irc.perl.org>|irc://irc.perl.org/#toolchain>.
 
 =head1 AUTHOR
 
index 640b239..db99dae 100644 (file)
@@ -107,6 +107,26 @@ package Simple;
 $Foo::Bar::VERSION = '1.23';
 ---
 },
+{
+  name => 'script 7 from t/metadata.t', # TODO merge these
+  package => [ '_private', 'main' ],
+  TODO => '$::VERSION indicates main namespace is referenced',
+  code => <<'---',
+package _private;
+$::VERSION = 0.01;
+$VERSION = '999';
+---
+},
+{
+  name => 'script 8 from t/metadata.t', # TODO merge these
+  package => [ '_private', 'main' ],
+  TODO => '$::VERSION indicates main namespace is referenced',
+  code => <<'---',
+package _private;
+$VERSION = '999';
+$::VERSION = 0.01;
+---
+},
 );
 
 my $test_num = 0;
@@ -118,7 +138,6 @@ foreach my $test_case (@pkg_names) {
     note $test_case->{name};
     my $code = $test_case->{code};
     my $expected_name = $test_case->{package};
-    local $TODO = $test_case->{TODO};
 
     my $warnings = '';
     local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
@@ -133,9 +152,12 @@ foreach my $test_case (@pkg_names) {
     # Test::Builder will prematurely numify objects, so use this form
     my $errs;
     my @got = $pm_info->packages_inside();
+  {
+    local $TODO = $test_case->{TODO};
     is_deeply( \@got, $expected_name,
                "case $test_case->{name}: correct package names (expected '" . join(', ', @$expected_name) . "')" )
             or $errs++;
+  }
     is( $warnings, '', "case $test_case->{name}: no warnings from parsing" ) or $errs++;
     diag "Got: '" . join(', ', @got) . "'\nModule contents:\n$code" if $errs;
 }
index 278a602..16266e8 100644 (file)
@@ -3,7 +3,6 @@ use warnings;
 # vim:ts=8:sw=2:et:sta:sts=2
 
 use Test::More 0.82;
-use Data::Dumper;
 use Module::Metadata;
 
 use lib 't/lib';
@@ -602,6 +601,16 @@ $Foo::Bar::VERSION = '1.23';
   vers => undef,
   all_versions => { 'Foo::Bar' => '1.23' },
 },
+{
+  name => 'package statement that does not quite match the filename',
+  filename => 'Simple.pm',
+  code => <<'---',
+package ThisIsNotSimple;
+our $VERSION = '1.23';
+---
+  vers => $undef,
+  all_versions => { 'ThisIsNotSimple' => '1.23' },
+},
 );
 
 my $test_num = 0;
@@ -639,8 +648,8 @@ foreach my $test_case (@modules) {
     # We want to ensure we preserve the original, as long as it's legal, so we
     # explicitly check the stringified form.
     {
-      local $TODO = $test_case->{TODO_got_version};
-      isa_ok($got, 'version') if defined $expected_version;
+      local $TODO = !defined($got) && ($test_case->{TODO_code_sub} || $test_case->{TODO_scalar});
+      isa_ok($got, 'version') or $errs++ if defined $expected_version;
     }
 
     if (ref($expected_version) eq 'CODE') {
@@ -669,19 +678,19 @@ foreach my $test_case (@modules) {
         ok(
           $test_case->{all_versions}->($pm_info->{versions}),
           "case '$test_case->{name}': all extracted versions passes match sub"
-        );
+        ) or $errs++;
       }
       else {
         is_deeply(
           $pm_info->{versions},
           $test_case->{all_versions},
           'correctly found all $VERSIONs',
-        );
+        ) or $errs++;
       }
     }
 
     is( $warnings, '', "case '$test_case->{name}': no warnings from parsing" ) or $errs++;
-    diag 'extracted versions: ', explain({ got => $pm_info->{versions}, module_contents => $code }) if !$ENV{PERL_CORE} && $errs;
+    diag 'parsed module: ', explain($pm_info) if !$ENV{PERL_CORE} && $errs;
   }
 }
 continue {
index 068a865..8135773 100644 (file)
@@ -10,9 +10,8 @@ use File::Temp;
 use File::Basename;
 use Cwd ();
 use File::Path;
-use Data::Dumper;
 
-plan tests => 61;
+plan tests => 70;
 
 require_ok('Module::Metadata');
 
@@ -205,12 +204,17 @@ $::VERSION = 0.01;
 
 my ( $i, $n ) = ( 1, scalar( @scripts ) );
 foreach my $script ( @scripts ) {
+  note '-------';
+  my $errs;
   my $file = File::Spec->catfile('bin', 'simple.plx');
   my ($dist_name, $dist_dir) = new_dist(files => { $file => $script } );
   my $pm_info = Module::Metadata->new_from_file( $file );
 
-  is( $pm_info->version, '0.01', "correct script version ($i of $n)" );
+  is( $pm_info->name, 'main', 'name for script is always main');
+  is( $pm_info->version, '0.01', "correct script version ($i of $n)" ) or $errs++;
   $i++;
+
+  diag 'parsed module: ', explain($pm_info) if !$ENV{PERL_CORE} && $errs;
 }
 
 {
@@ -324,6 +328,53 @@ our $VERSION = '1.23';
   is( $pm_info->version, '1.23', 'version for default package' );
 }
 
+my $tmpdir = GeneratePackage::tmpdir();
+my $undef;
+my $test_num = 0;
+use lib 't/lib';
+use GeneratePackage;
+
+{
+  # and now a real pod file
+  # (this test case is ready to be rolled into a corpus loop, later)
+  my $test_case = {
+    name => 'file only contains pod',
+    filename => 'Simple/Documentation.pod',
+    code => <<'---',
+# PODNAME: Simple::Documentation
+# ABSTRACT: My documentation
+
+=pod
+
+Hello, this is pod.
+
+=cut
+---
+    module => '', # TODO: should probably be $undef actually
+    all_versions => { },
+  };
+
+  note $test_case->{name};
+  my $code = $test_case->{code};
+  my $expected_name = $test_case->{module};
+  local $TODO = $test_case->{TODO};
+
+  my $errs;
+
+  my ($vol, $dir, $basename) = File::Spec->splitpath(File::Spec->catdir($tmpdir, "Simple${test_num}", ($test_case->{filename} || 'Simple.pm')));
+  my $pm_info = Module::Metadata->new_from_file(generate_file($dir, $basename, $code));
+
+  my $got_name = $pm_info->name;
+  is(
+    $got_name,
+    $expected_name,
+    "case '$test_case->{name}': module name matches",
+  )
+  or $errs++;
+
+  diag 'parsed module: ', explain($pm_info) if !$ENV{PERL_CORE} && $errs;
+}
+
 {
   # Make sure processing stops after __DATA__
   my $file = File::Spec->catfile('lib', 'Simple.pm');