This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Module-Load-Conditional to 0.52
authorSteve Hay <steve.m.hay@googlemail.com>
Thu, 9 Aug 2012 07:18:27 +0000 (08:18 +0100)
committerSteve Hay <steve.m.hay@googlemail.com>
Thu, 9 Aug 2012 07:18:27 +0000 (08:18 +0100)
12 files changed:
MANIFEST
Porting/Maintainers.pl
cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm
cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t
cpan/Module-Load-Conditional/t/02_Parse_Version.t [deleted file]
cpan/Module-Load-Conditional/t/test_lib/a/X.pm [new file with mode: 0644]
cpan/Module-Load-Conditional/t/test_lib/b/X.pm [new file with mode: 0644]
cpan/Module-Load-Conditional/t/to_load/Commented.pm
cpan/Module-Load-Conditional/t/to_load/LoadIt.pm
cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm
cpan/Module-Load-Conditional/t/to_load/NotMain.pm [new file with mode: 0644]
cpan/Module-Load-Conditional/t/to_load/NotX.pm [new file with mode: 0644]

index 054acc9..e08315f 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -1749,12 +1749,15 @@ cpan/Module-Build/t/write_default_maniskip.t
 cpan/Module-Build/t/xs.t
 cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm    Module::Conditional
 cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t    Module::Conditional tests
-cpan/Module-Load-Conditional/t/02_Parse_Version.t              Module::Load::Conditional tests
+cpan/Module-Load-Conditional/t/test_lib/a/X.pm                 Module::Conditional tests
+cpan/Module-Load-Conditional/t/test_lib/b/X.pm                 Module::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/Commented.pm            Module::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/InPod.pm                        Module::Load::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/LoadIt.pm               Module::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/LoadMe.pl               Module::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm                Module::Load::Conditional tests
+cpan/Module-Load-Conditional/t/to_load/NotMain.pm              Module::Conditional tests
+cpan/Module-Load-Conditional/t/to_load/NotX.pm                 Module::Conditional tests
 cpan/Module-Load-Conditional/t/to_load/ToBeLoaded              Module::Conditional tests
 cpan/Module-Loaded/lib/Module/Loaded.pm        Module::Loaded
 cpan/Module-Loaded/t/01_Module-Loaded.t        Module::Loaded tests
index 841e5bd..cdd86bd 100755 (executable)
@@ -1274,7 +1274,7 @@ use File::Glob qw(:case);
 
     'Module::Load::Conditional' => {
         'MAINTAINER'   => 'kane',
-        'DISTRIBUTION' => 'BINGOS/Module-Load-Conditional-0.50.tar.gz',
+        'DISTRIBUTION' => 'BINGOS/Module-Load-Conditional-0.52.tar.gz',
         'FILES'        => q[cpan/Module-Load-Conditional],
         'UPSTREAM'     => 'cpan',
     },
index 09ddeae..0470f47 100644 (file)
@@ -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
index c846e0d..ee5d59e 100644 (file)
@@ -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 (file)
index fb95df7..0000000
+++ /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 (file)
index 0000000..df7eacc
--- /dev/null
@@ -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 (file)
index 0000000..9591f98
--- /dev/null
@@ -0,0 +1,5 @@
+package X;
+
+our $VERSION = '0.02';
+
+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 (file)
index 0000000..a883761
--- /dev/null
@@ -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 (file)
index 0000000..ff54409
--- /dev/null
@@ -0,0 +1,15 @@
+$VERSION = 1;
+
+package Y;
+
+$VERSION = 2;
+
+package NotX;
+
+$VERSION = 3;
+
+package X;
+
+$VERSION = 4;
+
+1;