diff options
author | Steve Hay <steve.m.hay@googlemail.com> | 2012-08-09 08:18:27 +0100 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2012-08-09 08:18:27 +0100 |
commit | 201db1c76dc6bb7834b23f3a56ca9a0499470bf9 (patch) | |
tree | df244ca3ce9f4106ef1db1433088a931498066ad /cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm | |
parent | 7ef3083086f16586f909089ba7d9cc1468ffe2c5 (diff) | |
download | perl-201db1c76dc6bb7834b23f3a56ca9a0499470bf9.tar.gz |
Upgrade Module-Load-Conditional to 0.52
Diffstat (limited to 'cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm')
-rw-r--r-- | cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm | 97 |
1 files changed, 12 insertions, 85 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 |