Skip to content

Commit fbd275f

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 28b5e78 commit fbd275f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Revision history for Module-Metadata
22

33
{{$NEXT}}
44
- use utf8 in tests when testing non-ascii packages.
5+
- Comply with strictures when trying to detect $VERSION
56

67
1.000037 2019-09-07 18:32:44Z
78
- add decode_pod option for automatic =encoding handling

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)