Skip to content

Commit 77e5af9

Browse files
committed
Do not do local on a variable when it has not yet been declared.
MM's code to determine version does a local on $VERSION without having first declared it. Instead it should do 'my' on it unless the variable is defined at a distance. my $VERSION = ... # or local $Foo::Bar::VERSION = ... Doing this causes this code to pass strict where it did not previously do so.
1 parent e8b6e16 commit 77e5af9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

corpus/BOMTest/UTF8.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package Heart;
1+
use utf8;
2+
3+
package Heart;
24

35
our $VERSION = 1;
46

lib/Module/Metadata.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,19 @@ sub _evaluate_version_line {
685685
my $self = shift;
686686
my( $sigil, $variable_name, $line ) = @_;
687687

688+
# It is not legal to do local on a variable in the local name space before it is declared.
689+
my $local = ($variable_name =~ m/::/) ? 'local' : 'our';
690+
688691
# We compile into a local sub because 'use version' would cause
689692
# compiletime/runtime issues with local()
690693
$pn++; # everybody gets their own package
691694
my $eval = qq{ my \$dummy = q# Hide from _packages_inside()
692695
#; package Module::Metadata::_version::p${pn};
693696
use version;
697+
no strict 'vars';
698+
694699
sub {
695-
local $sigil$variable_name;
700+
$local $sigil$variable_name;
696701
$line;
697702
return \$$variable_name if defined \$$variable_name;
698703
return \$Module::Metadata::_version::p${pn}::$variable_name;

0 commit comments

Comments
 (0)