Subject: | constant hash subscript is sometimes parsed as variable declaration |
my, local, and our are not parsed correctly by PPI when used as hash keys.
The attached test demonstrates the problem.
--
rjbs
Subject: | local-hash.t |
use strict;
use warnings;
use Test::More tests => 7;
use PPI 1.118;
sub subscript_ok {
my ($string) = @_;
my $doc = PPI::Document->new(\"my \$y = \$x->{$string};");
my ($assignment) = $doc->schildren;
my @sa_schildren = $assignment->schildren;
my ($x, $arrow, $braces, $semi) = @sa_schildren[ -4 .. -1 ];
my ($subscript) = $braces->schildren;
if (eval { $subscript->isa('PPI::Statement::Variable') } ) {
my $type = eval { $subscript->type } || '(undef)';
fail "\$x->{$string} shows subscript is a variable of type $type";
} else {
pass "\$x->{$string} shows subscript is a non-variable expression";
}
}
subscript_ok('foo');
subscript_ok('bar');
subscript_ok('baz');
subscript_ok('local');
subscript_ok('my');
subscript_ok('our');
subscript_ok('state');