Skip to content

Commit 26b9aa4

Browse files
properly localize $VERSION when evaluating the version line (RT#101095)
It utterly fails when there is a $VERSION already declared in this namespace. So instead, we create an evaluator sub in the fresh namespace, even before applying strict and warnings.
1 parent 3184f68 commit 26b9aa4

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Revision history for {{$dist->name}}
22

33
{{$NEXT}}
4+
- evaluate version assignment in a clean environment, to fix assignment in a
5+
block (RT#101095)
46

57
1.000024 2014-06-03 01:52:46Z
68
- fix inaccurate prerequisite declaration on Test::More (in 1.000023)

lib/Module/Metadata.pm

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package Module::Metadata;
99
# perl modules (assuming this may be expanded in the distant
1010
# parrot future to look at other types of modules).
1111

12+
sub __clean_eval { eval $_[0] }
1213
use strict;
1314
use warnings;
1415

@@ -637,41 +638,36 @@ sub _evaluate_version_line {
637638
my $self = shift;
638639
my( $sigil, $variable_name, $line ) = @_;
639640

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
643642
# compiletime/runtime issues with local()
644-
my $vsub;
645643
$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};
648646
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+
};
659653

660654
$eval = $1 if $eval =~ m{^(.+)}s;
661655

662656
local $^W;
663657
# Try to get the $VERSION
664-
eval $eval;
658+
my $vsub = __clean_eval($eval);
665659
# some modules say $VERSION <equal sign> $Foo::Bar::VERSION, but Foo::Bar isn't
666660
# installed, so we need to hunt in ./lib for it
667661
if ( $@ =~ /Can't locate/ && -d 'lib' ) {
668662
local @INC = ('lib',@INC);
669-
eval $eval;
663+
$vsub = __clean_eval($eval);
670664
}
671665
warn "Error evaling version line '$eval' in $self->{filename}: $@\n"
672666
if $@;
667+
673668
(ref($vsub) eq 'CODE') or
674669
croak "failed to build version sub for $self->{filename}";
670+
675671
my $result = eval { $vsub->() };
676672
# FIXME: $eval is not the right thing to print here
677673
croak "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error was: $@\n"

0 commit comments

Comments
 (0)