diff options
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Module-Load-Conditional')
9 files changed, 149 insertions, 149 deletions
diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm index 39dccf1ce2b..342371f8794 100644 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm @@ -11,6 +11,8 @@ use File::Spec (); use FileHandle (); use version; +use Module::Metadata (); + use constant ON_VMS => $^O eq 'VMS'; BEGIN { @@ -18,7 +20,7 @@ BEGIN { $FIND_VERSION $ERROR $CHECK_INC_HASH]; use Exporter; @ISA = qw[Exporter]; - $VERSION = '0.46'; + $VERSION = '0.54'; $VERBOSE = 0; $DEPRECATED = 0; $FIND_VERSION = 1; @@ -137,7 +139,7 @@ uptodate will always be true if the module was found. If no parsable version was found in the module, uptodate will also be true, since C<check_install> had no way to verify clearly. -See also C<$Module::Load::Conditional::DEPRECATED>, which affects +See also C<$Module::Load::Conditional::DEPRECATED>, which affects the outcome of this value. =back @@ -168,8 +170,8 @@ sub check_install { } my $file = File::Spec->catfile( split /::/, $args->{module} ) . '.pm'; - my $file_inc = File::Spec::Unix->catfile( - split /::/, $args->{module} + my $file_inc = File::Spec::Unix->catfile( + split /::/, $args->{module} ) . '.pm'; ### where we store the return value ### @@ -178,59 +180,59 @@ sub check_install { version => undef, uptodate => undef, }; - + my $filename; ### check the inc hash if we're allowed to if( $CHECK_INC_HASH ) { - $filename = $href->{'file'} = + $filename = $href->{'file'} = $INC{ $file_inc } if defined $INC{ $file_inc }; ### find the version by inspecting the package if( defined $filename && $FIND_VERSION ) { no strict 'refs'; - $href->{version} = ${ "$args->{module}"."::VERSION" }; + $href->{version} = ${ "$args->{module}"."::VERSION" }; } - } + } ### we didnt find the filename yet by looking in %INC, ### so scan the dirs unless( $filename ) { DIR: for my $dir ( @INC ) { - + my $fh; - + if ( ref $dir ) { ### @INC hook -- we invoke it and get the filehandle back ### this is actually documented behaviour as of 5.8 ;) my $existed_in_inc = $INC{$file_inc}; - + if (UNIVERSAL::isa($dir, 'CODE')) { ($fh) = $dir->($dir, $file); - + } elsif (UNIVERSAL::isa($dir, 'ARRAY')) { ($fh) = $dir->[0]->($dir, $file, @{$dir}{1..$#{$dir}}) - + } elsif (UNIVERSAL::can($dir, 'INC')) { ($fh) = $dir->INC($file); } - + if (!UNIVERSAL::isa($fh, 'GLOB')) { warn loc(q[Cannot open file '%1': %2], $file, $!) if $args->{verbose}; next; } - + $filename = $INC{$file_inc} || $file; delete $INC{$file_inc} if not $existed_in_inc; - + } else { $filename = File::Spec->catfile($dir, $file); next unless -e $filename; - + $fh = new FileHandle; if (!$fh->open($filename)) { warn loc(q[Cannot open file '%1': %2], $file, $!) @@ -238,45 +240,31 @@ sub check_install { next; } } - + ### store the directory we found the file in $href->{dir} = $dir; - + ### files need to be in unix format under vms, ### or they might be loaded twice $href->{file} = ON_VMS ? VMS::Filespec::unixify( $filename ) : $filename; - - ### user wants us to find the version from files - if( $FIND_VERSION ) { - - my $in_pod = 0; - while ( my $line = <$fh> ) { - - ### stolen from EU::MM_Unix->parse_version to address - ### #24062: "Problem with CPANPLUS 0.076 misidentifying - ### versions after installing Text::NSP 1.03" where a - ### VERSION mentioned in the POD was found before - ### the real $VERSION declaration. - $in_pod = $line =~ /^=(?!cut)/ ? 1 : - $line =~ /^=cut/ ? 0 : - $in_pod; - next if $in_pod; - - ### try to find a version declaration in this string. - my $ver = __PACKAGE__->_parse_version( $line ); - - if( defined $ver ) { - $href->{version} = $ver; - - last DIR; - } - } + + ### if we don't need the version, we're done + last DIR unless $FIND_VERSION; + + ### otherwise, the user wants us to find the version from files + my $mod_info = Module::Metadata->new_from_handle( $fh, $filename ); + my $ver = $mod_info->version( $args->{module} ); + + if( defined $ver ) { + $href->{version} = $ver; + + last DIR; } } } - + ### if we couldn't find the file, return undef ### return unless defined $href->{file}; @@ -294,7 +282,7 @@ sub check_install { } else { ### don't warn about the 'not numeric' stuff ### local $^W; - + ### use qv(), as it will deal with developer release number ### ie ones containing _ as well. This addresses bug report ### #29348: Version compare logic doesn't handle alphas? @@ -308,19 +296,19 @@ sub check_install { eval { - $href->{uptodate} = + $href->{uptodate} = version->new( $args->{version} ) <= version->new( $href->{version} ) - ? 1 + ? 1 : 0; }; } - if ( $DEPRECATED and version->new($]) >= version->new('5.011') ) { + if ( $DEPRECATED and "$]" >= 5.011 ) { require Module::CoreList; require Config; - $href->{uptodate} = 0 if + $href->{uptodate} = 0 if exists $Module::CoreList::version{ 0+$] }{ $args->{module} } and Module::CoreList::is_deprecated( $args->{module} ) and $Config::Config{privlibexp} eq $href->{dir}; @@ -329,67 +317,6 @@ sub check_install { return $href; } -sub _parse_version { - my $self = shift; - my $str = shift or return; - my $verbose = shift || 0; - - ### skip lines which doesn't contain VERSION - return unless $str =~ /VERSION/; - - ### skip commented out lines, they won't eval to anything. - return if $str =~ /^\s*#/; - - ### the following regexp & eval statement comes from the - ### ExtUtils::MakeMaker source (EU::MM_Unix->parse_version) - ### Following #18892, which tells us the original - ### regex breaks under -T, we must modify it so - ### it captures the entire expression, and eval /that/ - ### rather than $_, which is insecure. - my $taint_safe_str = do { $str =~ /(^.*$)/sm; $1 }; - - if( $str =~ /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) { - - print "Evaluating: $str\n" if $verbose; - - ### this creates a string to be eval'd, like: - # package Module::Load::Conditional::_version; - # no strict; - # - # local $VERSION; - # $VERSION=undef; do { - # use version; $VERSION = qv('0.0.3'); - # }; $VERSION - - my $eval = qq{ - package Module::Load::Conditional::_version; - no strict; - - local $1$2; - \$$2=undef; do { - $taint_safe_str - }; \$$2 - }; - - print "Evaltext: $eval\n" if $verbose; - - my $result = do { - local $^W = 0; - eval($eval); - }; - - - my $rv = defined $result ? $result : '0.0'; - - print( $@ ? "Error: $@\n" : "Result: $rv\n" ) if $verbose; - - return $rv; - } - - ### unable to find a version in this string - return; -} - =head2 $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL] ) C<can_load> will take a list of modules, optionally with version @@ -475,10 +402,10 @@ sub can_load { ### ### Update from JPeacock: apparently qv() and version->new ### are different things, and we *must* use version->new - ### here, or things like #30056 might start happening + ### here, or things like #30056 might start happening if ( !$args->{nocache} && defined $CACHE->{$mod}->{usable} - && (version->new( $CACHE->{$mod}->{version}||0 ) + && (version->new( $CACHE->{$mod}->{version}||0 ) >= version->new( $href->{$mod} ) ) ) { $error = loc( q[Already tried to use '%1', which was unsuccessful], $mod); @@ -568,7 +495,7 @@ sub requires { } my $lib = join " ", map { qq["-I$_"] } @INC; - my $cmd = qq[$^X $lib -M$who -e"print(join(qq[\\n],keys(%INC)))"]; + my $cmd = qq["$^X" $lib -M$who -e"print(join(qq[\\n],keys(%INC)))"]; return sort grep { !/^$who$/ } @@ -596,12 +523,12 @@ The default is 0; =head2 $Module::Load::Conditional::FIND_VERSION This controls whether Module::Load::Conditional will try to parse -(and eval) the version from the module you're trying to load. +(and eval) the version from the module you're trying to load. If you don't wish to do this, set this variable to C<false>. Understand then that version comparisons are not possible, and Module::Load::Conditional can not tell you what module version you have installed. -This may be desirable from a security or performance point of view. +This may be desirable from a security or performance point of view. Note that C<$FIND_VERSION> code runs safely under C<taint mode>. The default is 1; @@ -631,9 +558,9 @@ C<undef>. =head2 $Module::Load::Conditional::DEPRECATED -This controls whether C<Module::Load::Conditional> checks if +This controls whether C<Module::Load::Conditional> checks if a dual-life core module has been deprecated. If this is set to -true C<check_install> will return false to C<uptodate>, if +true C<check_install> will return false to C<uptodate>, if a dual-life module is found to be loaded from C<$Config{privlibexp}> The default is 0; @@ -652,7 +579,7 @@ This module by Jos Boumans E<lt>kane@cpan.orgE<gt>. =head1 COPYRIGHT -This library is free software; you may redistribute and/or modify it +This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. =cut diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t index 7a51266e6bb..99fa1fe72db 100755 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t @@ -1,15 +1,15 @@ ### Module::Load::Conditional test suite ### ### this should no longer be needed -# BEGIN { +# BEGIN { # if( $ENV{PERL_CORE} ) { -# chdir '../lib/Module/Load/Conditional' +# chdir '../lib/Module/Load/Conditional' # if -d '../lib/Module/Load/Conditional'; # unshift @INC, '../../../..'; -# +# # ### fix perl location too # $^X = '../../../../../t/' . $^X; # } -# } +# } BEGIN { use FindBin; } BEGIN { chdir 't' if -d 't' } @@ -26,7 +26,7 @@ use lib File::Spec->catdir($FindBin::Bin, q[to_load] ); use_ok( 'Module::Load::Conditional' ); ### stupid stupid warnings ### -{ $Module::Load::Conditional::VERBOSE = +{ $Module::Load::Conditional::VERBOSE = $Module::Load::Conditional::VERBOSE = 0; *can_load = *Module::Load::Conditional::can_load @@ -44,10 +44,10 @@ use_ok( 'Module::Load::Conditional' ); ); ok( $rv->{uptodate}, q[Verify self] ); - is( $rv->{version}, $Module::Load::Conditional::VERSION, + is( $rv->{version}, $Module::Load::Conditional::VERSION, q[ Found proper version] ); ok( $rv->{dir}, q[ Found directory information] ); - + { my $dir = File::Spec->canonpath( $rv->{dir} ); ### special rules apply on VMS, as always... @@ -56,8 +56,8 @@ use_ok( 'Module::Load::Conditional' ); $dir = VMS::Filespec::pathify($dir); ### Remove the trailing VMS specific directory delimiter $dir =~ s/\]//; - } - + } + ### quote for Win32 paths, use | to avoid slash confusion my $dir_re = qr|^\Q$dir\E|i; like( File::Spec->canonpath( $rv->{file} ), $dir_re, @@ -70,7 +70,7 @@ use_ok( 'Module::Load::Conditional' ); ### Use the UNIX specific method, as the VMS one currently ### converts the file spec back to VMS format. my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; - + my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); my @path = ($vol, $class->splitdir( $path ), $file ); @@ -78,7 +78,7 @@ use_ok( 'Module::Load::Conditional' ); ### First element could be blank for some system types like VMS shift @path if $vol eq ''; - ### and return it + ### and return it @path; }; my $inc_path = $INC{'Module/Load/Conditional.pm'}; @@ -90,8 +90,8 @@ use_ok( 'Module::Load::Conditional' ); File::Spec::Unix->catfile(@rv_path), q[ Found proper file] ); - - + + } @@ -132,33 +132,72 @@ use_ok( 'Module::Load::Conditional' ); is( $rv->{version}, 2, " Version is correct" ); } +### test that no package statement means $VERSION is $main::VERSION +{ + my $rv = check_install( module => 'NotMain' ); + ok( $rv, 'Testing $VERSION without package' ); + is( $rv->{version}, undef, " No version info returned" ); +} + +### test that the right $VERSION is picked when there are several packages +{ + my $rv = check_install( module => 'NotX' ); + ok( $rv, 'Testing $VERSION with many packages' ); + ok( $rv->{version}, " Version found" ); + is( $rv->{version}, 3, " Version is correct" ); +} + ### test beta/developer release versions { my $test_ver = $Module::Load::Conditional::VERSION; - + ### strip beta tags $test_ver =~ s/_\d+//g; $test_ver .= '_99'; - - my $rv = check_install( - module => 'Module::Load::Conditional', + + my $rv = check_install( + module => 'Module::Load::Conditional', version => $test_ver, ); ok( $rv, "Checking beta versions" ); ok( !$rv->{'uptodate'}, " Beta version is higher" ); - -} + +} ### test $FIND_VERSION -{ local $Module::Load::Conditional::FIND_VERSION = 0; +{ local $Module::Load::Conditional::FIND_VERSION = 0; - + my $rv = check_install( module => 'Module::Load::Conditional' ); ok( $rv, 'Testing $FIND_VERSION' ); is( $rv->{version}, undef, " No version info returned" ); ok( $rv->{uptodate}, " Module marked as uptodate" ); -} +} + +### test that check_install() picks up the first match +{ + my ($dir_a, $dir_b) = map File::Spec->catdir($FindBin::Bin, 'test_lib', $_), + qw[a b]; + my $x_pm = File::Spec->catfile($dir_a, 'X.pm'); + $x_pm = VMS::Filespec::unixify($x_pm) if ON_VMS; + + local @INC = ($dir_a, $dir_b); + + my $rv = check_install( module => 'X' ); + + ok( $rv, 'Testing the file picked by check_install ($FIND_VERSION == 1)' ); + is( $rv->{file}, $x_pm, " First file was picked" ); + is( $rv->{version}, '0.01', " Correct version for first file" ); + + local $Module::Load::Conditional::FIND_VERSION = 0; + + $rv = check_install( module => 'X' ); + + ok( $rv, 'Testing the file picked by check_install ($FIND_VERSION == 0)' ); + is( $rv->{file}, $x_pm, " First file was also picked" ); + is( $rv->{version}, undef, " But its VERSION was not required" ); +} ### test 'can_load' ### @@ -198,11 +237,11 @@ use_ok( 'Module::Load::Conditional' ); ### test 'requires' ### SKIP:{ - skip "Depends on \$^X, which doesn't work well when testing the Perl core", + skip "Depends on \$^X, which doesn't work well when testing the Perl core", 1 if $ENV{PERL_CORE}; my %list = map { $_ => 1 } requires('Carp'); - + my $flag; $flag++ unless delete $list{'Exporter'}; @@ -212,15 +251,15 @@ SKIP:{ ### test using the %INC lookup for check_install { local $Module::Load::Conditional::CHECK_INC_HASH = 1; local $Module::Load::Conditional::CHECK_INC_HASH = 1; - - { package A::B::C::D; - $A::B::C::D::VERSION = $$; + + { package A::B::C::D; + $A::B::C::D::VERSION = $$; $INC{'A/B/C/D.pm'} = $$.$$; - + ### XXX this is no longer needed with M::Load 0.11_01 #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; } - + my $href = check_install( module => 'A::B::C::D', version => 0 ); ok( $href, 'Found package in %INC' ); diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/a/X.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/a/X.pm new file mode 100644 index 00000000000..df7eacc0e86 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/a/X.pm @@ -0,0 +1,5 @@ +package X; + +our $VERSION = '0.01'; + +1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/b/X.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/b/X.pm new file mode 100644 index 00000000000..9591f980299 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/test_lib/b/X.pm @@ -0,0 +1,5 @@ +package X; + +our $VERSION = '0.02'; + +1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/Commented.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/Commented.pm index 2ee302e96c3..e3f516e5ecc 100644 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/Commented.pm +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/Commented.pm @@ -1,3 +1,5 @@ +package Commented; + # $VERSION = 1; $VERSION = 2; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm index 87025e8a512..64517ecf476 100644 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm @@ -1,3 +1,5 @@ +package LoadIt; + $VERSION = 1; 1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm index e6423f3263f..ee857ddf873 100644 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm @@ -1,3 +1,5 @@ +package MustBe::Loaded; + $VERSION = 0.01; 1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotMain.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotMain.pm new file mode 100644 index 00000000000..a88376194ae --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotMain.pm @@ -0,0 +1,3 @@ +$VERSION = 1.23; + +1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotX.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotX.pm new file mode 100644 index 00000000000..ff54409dac7 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotX.pm @@ -0,0 +1,15 @@ +$VERSION = 1; + +package Y; + +$VERSION = 2; + +package NotX; + +$VERSION = 3; + +package X; + +$VERSION = 4; + +1; |