@@ -9,6 +9,7 @@ package Module::Metadata;
9
9
# perl modules (assuming this may be expanded in the distant
10
10
# parrot future to look at other types of modules).
11
11
12
+ sub __clean_eval { eval $_ [0] }
12
13
use strict;
13
14
use warnings;
14
15
@@ -637,41 +638,36 @@ sub _evaluate_version_line {
637
638
my $self = shift ;
638
639
my ( $sigil , $variable_name , $line ) = @_ ;
639
640
640
- # Some of this code came from the ExtUtils:: hierarchy.
641
-
642
- # We compile into $vsub because 'use version' would cause
641
+ # We compile into a local sub because 'use version' would cause
643
642
# compiletime/runtime issues with local()
644
- my $vsub ;
645
643
$pn ++; # everybody gets their own package
646
- my $eval = qq{ BEGIN { my \$ dummy = q# Hide from _packages_inside()
647
- #; package Module::Metadata::_version::p$pn ;
644
+ my $eval = qq{ my \$ dummy = q# Hide from _packages_inside()
645
+ #; package Module::Metadata::_version::p${pn} ;
648
646
use version;
649
- no strict;
650
- no warnings;
651
-
652
- \$ vsub = sub {
653
- local $sigil$variable_name ;
654
- \$ $variable_name =undef;
655
- $line ;
656
- \$ $variable_name
657
- };
658
- }} ;
647
+ sub {
648
+ local $sigil$variable_name ;
649
+ $line ;
650
+ \$ $variable_name
651
+ };
652
+ } ;
659
653
660
654
$eval = $1 if $eval =~ m { ^(.+)} s ;
661
655
662
656
local $^W;
663
657
# Try to get the $VERSION
664
- eval $ eval ;
658
+ my $vsub = __clean_eval( $ eval) ;
665
659
# some modules say $VERSION <equal sign> $Foo::Bar::VERSION, but Foo::Bar isn't
666
660
# installed, so we need to hunt in ./lib for it
667
661
if ( $@ =~ / Can't locate/ && -d ' lib' ) {
668
662
local @INC = (' lib' ,@INC );
669
- eval $eval ;
663
+ $vsub = __clean_eval( $eval ) ;
670
664
}
671
665
warn " Error evaling version line '$eval ' in $self ->{filename}: $@ \n "
672
666
if $@ ;
667
+
673
668
(ref ($vsub ) eq ' CODE' ) or
674
669
croak " failed to build version sub for $self ->{filename}" ;
670
+
675
671
my $result = eval { $vsub -> () };
676
672
# FIXME: $eval is not the right thing to print here
677
673
croak " Could not get version from $self ->{filename} by executing:\n $eval \n\n The fatal error was: $@ \n "
0 commit comments