diff options
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Module-Metadata')
3 files changed, 97 insertions, 21 deletions
diff --git a/gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm b/gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm index f7017cf90ff..7f49da6d59a 100644 --- a/gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm +++ b/gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm @@ -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.000032-7-gb4e8a3f # 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.000033'; 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.000033 =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 @@ -1049,7 +1070,7 @@ assistance from David Golden (xdg) <dagolden@cpan.org>. =head1 CONTRIBUTORS -=for stopwords Karen Etheridge David Golden Vincent Pit Matt S Trout Chris Nehren Graham Knop Olivier Mengué Tomas Doran Tatsuhiko Miyagawa tokuhirom Peter Rabbitson Steve Hay Josh Jore Craig A. Berry Mitchell Steinbrunner Edward Zborowski Gareth Harper James Raspass Jerry D. Hedden 'BinGOs' Williams Kent Fredric +=for stopwords Karen Etheridge David Golden Vincent Pit Matt S Trout Chris Nehren Graham Knop Olivier Mengué Tomas Doran Tatsuhiko Miyagawa tokuhirom Kent Fredric Peter Rabbitson Steve Hay Jerry D. Hedden Craig A. Berry Mitchell Steinbrunner Edward Zborowski Gareth Harper James Raspass 'BinGOs' Williams Josh Jore =over 4 @@ -1095,6 +1116,10 @@ tokuhirom <tokuhirom@gmail.com> =item * +Kent Fredric <kentnl@cpan.org> + +=item * + Peter Rabbitson <ribasushi@cpan.org> =item * @@ -1103,7 +1128,7 @@ Steve Hay <steve.m.hay@googlemail.com> =item * -Josh Jore <jjore@cpan.org> +Jerry D. Hedden <jdhedden@cpan.org> =item * @@ -1111,6 +1136,10 @@ Craig A. Berry <cberry@cpan.org> =item * +Craig A. Berry <craigberry@mac.com> + +=item * + David Mitchell <davem@iabyn.com> =item * @@ -1131,15 +1160,11 @@ James Raspass <jraspass@gmail.com> =item * -Jerry D. Hedden <jdhedden@cpan.org> - -=item * - Chris 'BinGOs' Williams <chris@bingosnet.co.uk> =item * -Kent Fredric <kentnl@cpan.org> +Josh Jore <jjore@cpan.org> =back diff --git a/gnu/usr.bin/perl/cpan/Module-Metadata/t/contains_pod.t b/gnu/usr.bin/perl/cpan/Module-Metadata/t/contains_pod.t index 016e7844ade..d2b7c501d3d 100644 --- a/gnu/usr.bin/perl/cpan/Module-Metadata/t/contains_pod.t +++ b/gnu/usr.bin/perl/cpan/Module-Metadata/t/contains_pod.t @@ -4,7 +4,7 @@ use Test::More tests => 3; use Module::Metadata; BEGIN { - *fh_from_string = $] < 5.008 + *fh_from_string = "$]" < 5.008 ? require IO::Scalar && sub ($) { IO::Scalar->new(\$_[0]); } diff --git a/gnu/usr.bin/perl/cpan/Module-Metadata/t/metadata.t b/gnu/usr.bin/perl/cpan/Module-Metadata/t/metadata.t index 068a8657b15..5dee700bbc6 100644 --- a/gnu/usr.bin/perl/cpan/Module-Metadata/t/metadata.t +++ b/gnu/usr.bin/perl/cpan/Module-Metadata/t/metadata.t @@ -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->catfile($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'); |