summaryrefslogtreecommitdiff
path: root/cpan/Module-Load-Conditional
diff options
context:
space:
mode:
authorSteve Hay <steve.m.hay@googlemail.com>2012-08-09 08:18:27 +0100
committerSteve Hay <steve.m.hay@googlemail.com>2012-08-09 08:18:27 +0100
commit201db1c76dc6bb7834b23f3a56ca9a0499470bf9 (patch)
treedf244ca3ce9f4106ef1db1433088a931498066ad /cpan/Module-Load-Conditional
parent7ef3083086f16586f909089ba7d9cc1468ffe2c5 (diff)
downloadperl-201db1c76dc6bb7834b23f3a56ca9a0499470bf9.tar.gz
Upgrade Module-Load-Conditional to 0.52
Diffstat (limited to 'cpan/Module-Load-Conditional')
-rw-r--r--cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm97
-rw-r--r--cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t40
-rw-r--r--cpan/Module-Load-Conditional/t/02_Parse_Version.t99
-rw-r--r--cpan/Module-Load-Conditional/t/test_lib/a/X.pm5
-rw-r--r--cpan/Module-Load-Conditional/t/test_lib/b/X.pm5
-rw-r--r--cpan/Module-Load-Conditional/t/to_load/Commented.pm2
-rw-r--r--cpan/Module-Load-Conditional/t/to_load/LoadIt.pm2
-rw-r--r--cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm2
-rw-r--r--cpan/Module-Load-Conditional/t/to_load/NotMain.pm3
-rw-r--r--cpan/Module-Load-Conditional/t/to_load/NotX.pm15
10 files changed, 85 insertions, 185 deletions
diff --git a/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm b/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm
index 09ddeaed18..0470f47df4 100644
--- a/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm
+++ b/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.50';
+ $VERSION = '0.52';
$VERBOSE = 0;
$DEPRECATED = 0;
$FIND_VERSION = 1;
@@ -248,34 +250,17 @@ sub check_install {
? VMS::Filespec::unixify( $filename )
: $filename;
- ### user wants us to find the version from files
- if( $FIND_VERSION ) {
-
- my $in_pod = 0;
- my $line;
- while ( $line = <$fh> ) {
-
- ### #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.
- if( $line =~ /^=(.{0,3})/ ) {
- $in_pod = $1 ne 'cut';
- }
- next if $in_pod;
+ ### if we don't need the version, we're done
+ last DIR unless $FIND_VERSION;
- ### skip lines which doesn't contain VERSION
- next unless $line =~ /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} );
- ### try to find a version declaration in this string.
- my $ver = __PACKAGE__->_parse_version( $line );
+ if( defined $ver ) {
+ $href->{version} = $ver;
- if( defined $ver ) {
- $href->{version} = $ver;
-
- last DIR;
- }
- }
+ last DIR;
}
}
}
@@ -319,7 +304,7 @@ sub check_install {
};
}
- if ( $DEPRECATED and version->new($]) >= version->new('5.011') ) {
+ if ( $DEPRECATED and "$]" >= 5.011 ) {
require Module::CoreList;
require Config;
@@ -332,64 +317,6 @@ sub check_install {
return $href;
}
-sub _parse_version {
- my $self = shift;
- my $str = shift or return;
- my $verbose = shift || 0;
-
- ### 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
diff --git a/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t b/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t
index c846e0dd8f..ee5d59ea36 100644
--- a/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t
+++ b/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t
@@ -132,6 +132,21 @@ 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;
@@ -150,7 +165,7 @@ use_ok( 'Module::Load::Conditional' );
}
### 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' );
@@ -160,6 +175,29 @@ use_ok( 'Module::Load::Conditional' );
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');
+
+ 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' ###
{
diff --git a/cpan/Module-Load-Conditional/t/02_Parse_Version.t b/cpan/Module-Load-Conditional/t/02_Parse_Version.t
deleted file mode 100644
index fb95df7371..0000000000
--- a/cpan/Module-Load-Conditional/t/02_Parse_Version.t
+++ /dev/null
@@ -1,99 +0,0 @@
-BEGIN { chdir 't' if -d 't' }
-
-use strict;
-use lib qw[../lib];
-use Test::More 'no_plan';
-
-my $Class = 'Module::Load::Conditional';
-my $Meth = '_parse_version';
-my $Verbose = @ARGV ? 1 : 0;
-
-use_ok( $Class );
-
-### versions that should parse
-{ for my $str ( __PACKAGE__->_succeed ) {
- my $res = $Class->$Meth( $str, $Verbose );
- ok( defined $res, "String '$str' identified as version string" );
-
- ### XXX version.pm 0.69 pure perl fails tests under 5.6.2.
- ### XXX version.pm <= 0.69 do not have a complete overload
- ### implementation, which causes the following error:
- ### $ perl -Mversion -le'qv(1)+0'
- ### Operation "+": no method found,
- ### left argument in overloaded package version,
- ### right argument has no overloaded magic at -e line 1
- ### so we do the comparison ourselves, and then feed it to
- ### the Test::More::ok().
- ###
- ### Mailed jpeacock and p5p about both issues on 25-1-2007:
- ### http://xrl.us/uem7
- ### (http://www.xray.mpe.mpg.de/mailing-lists/
- ### perl5-porters/2007-01/msg00805.html)
-
- ### Quell "Argument isn't numeric in gt" warnings...
- my $bool = do { local $^W; $res > 0 };
-
- ok( $bool, " Version is '$res'" );
- isnt( $res, '0.0', " Not the default value" );
- }
-}
-
-### version that should fail
-{ for my $str ( __PACKAGE__->_fail ) {
- my $res = $Class->$Meth( $str, $Verbose );
- ok( ! defined $res, "String '$str' is not a version string" );
- }
-}
-
-
-################################
-###
-### VERSION declarations to test
-###
-################################
-
-sub _succeed {
- return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[
- $VERSION = 1;
- *VERSION = \'1.01';
- use version; $VERSION = qv('0.0.2');
- use version; $VERSION = qv('3.0.14');
- ($VERSION) = '$Revision: 2.03 $' =~ /\s(\d+\.\d+)\s/;
- ( $VERSION ) = sprintf "%d.%02d", q$Revision: 1.23 $ =~ m/ (\d+) \. (\d+) /gx;
- ($GD::Graph::area::VERSION) = '$Revision: 1.16.2.3 $' =~ /\s([\d.]+)/;
- ($GD::Graph::axestype::VERSION) = '$Revision: 1.44.2.14 $' =~ /\s([\d.]+)/;
- ($GD::Graph::colour::VERSION) = '$Revision: 1.10 $' =~ /\s([\d.]+)/;
- ($GD::Graph::pie::VERSION) = '$Revision: 1.20.2.4 $' =~ /\s([\d.]+)/;
- ($GD::Text::Align::VERSION) = '$Revision: 1.18 $' =~ /\s([\d.]+)/;
- $VERSION = qv('0.0.1');
- use version; $VERSION = qv('0.0.3');
- $VERSION = do { my @r = ( ( $v = q<Version value="0.20.1"> ) =~ /\d+/g ); sprintf "%d.%02d", $r[0], int( $r[1] / 10 ) };
- ($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
- ( $VERSION = q($Id: Tidy.pm,v 1.56 2006/07/19 23:13:33 perltidy Exp $) ) =~ s/^.*\s+(\d+)\/(\d+)\/(\d+).*$/$1$2$3/; # all one line for MakeMaker
- ($VERSION) = q $Revision: 2.120 $ =~ /([\d.]+)/;
- ($VERSION) = q$Revision: 1.00 $ =~ /([\d.]+)/;
- $VERSION = "3.0.8";
- $VERSION = '1.0.5';
- ];
-}
-
-sub _fail {
- return grep { /\S/ } map { s/^\s*//; $_ } split "\n", q[
- use vars qw($VERSION $AUTOLOAD %ERROR $ERROR $Warn $Die);
- sub version { $GD::Graph::colour::VERSION }
- my $VERS = qr{ $HWS VERSION $HWS \n }xms;
- diag( "Testing $main_module \$${main_module}::VERSION" );
- our ( $VERSION, $v, $_VERSION );
- my $seen = { q{::} => { 'VERSION' => 1 } }; # avoid multiple scans
- eval "$module->VERSION"
- 'VERSION' => '1.030' # Variable and Value
- 'VERSION' => '2.121_020'
- 'VERSION' => '0.050', # Standard variable $VERSION
- use vars qw( $VERSION $seq @FontDirs );
- $VERSION
- # *VERSION = \'1.01';
- # ( $VERSION ) = '$Revision: 1.56 $ ' =~ /\$Revision:\s+([^\s]+)/;
- #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/);
- #$VERSION = sprintf("%d.%s", map {s/_//g; $_} q$Name: $ =~ /-(\d+)_([\d_]+)/);
- ];
-}
diff --git a/cpan/Module-Load-Conditional/t/test_lib/a/X.pm b/cpan/Module-Load-Conditional/t/test_lib/a/X.pm
new file mode 100644
index 0000000000..df7eacc0e8
--- /dev/null
+++ b/cpan/Module-Load-Conditional/t/test_lib/a/X.pm
@@ -0,0 +1,5 @@
+package X;
+
+our $VERSION = '0.01';
+
+1;
diff --git a/cpan/Module-Load-Conditional/t/test_lib/b/X.pm b/cpan/Module-Load-Conditional/t/test_lib/b/X.pm
new file mode 100644
index 0000000000..9591f98029
--- /dev/null
+++ b/cpan/Module-Load-Conditional/t/test_lib/b/X.pm
@@ -0,0 +1,5 @@
+package X;
+
+our $VERSION = '0.02';
+
+1;
diff --git a/cpan/Module-Load-Conditional/t/to_load/Commented.pm b/cpan/Module-Load-Conditional/t/to_load/Commented.pm
index 2ee302e96c..e3f516e5ec 100644
--- a/cpan/Module-Load-Conditional/t/to_load/Commented.pm
+++ b/cpan/Module-Load-Conditional/t/to_load/Commented.pm
@@ -1,3 +1,5 @@
+package Commented;
+
# $VERSION = 1;
$VERSION = 2;
diff --git a/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm b/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm
index 87025e8a51..64517ecf47 100644
--- a/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm
+++ b/cpan/Module-Load-Conditional/t/to_load/LoadIt.pm
@@ -1,3 +1,5 @@
+package LoadIt;
+
$VERSION = 1;
1;
diff --git a/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm b/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm
index e6423f3263..ee857ddf87 100644
--- a/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm
+++ b/cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm
@@ -1,3 +1,5 @@
+package MustBe::Loaded;
+
$VERSION = 0.01;
1;
diff --git a/cpan/Module-Load-Conditional/t/to_load/NotMain.pm b/cpan/Module-Load-Conditional/t/to_load/NotMain.pm
new file mode 100644
index 0000000000..a88376194a
--- /dev/null
+++ b/cpan/Module-Load-Conditional/t/to_load/NotMain.pm
@@ -0,0 +1,3 @@
+$VERSION = 1.23;
+
+1;
diff --git a/cpan/Module-Load-Conditional/t/to_load/NotX.pm b/cpan/Module-Load-Conditional/t/to_load/NotX.pm
new file mode 100644
index 0000000000..ff54409dac
--- /dev/null
+++ b/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;