Subject: | PPI::Token::Symbol::symbol does not properly handle variables with adjacent braces |
The symbol method in PPI::Token::Symbol incorrectly returns "$" for
arrays and hashes with adjacent braces.
For example, symbol called on $foo{bar} returns "$" not the intended "%foo".
The four-argument substr commands within symbol are returning the
original leading character of each variable name.
I have confirmed this behavior on Perl versions 5.6.0 and 5.6.1 (Solaris
8), and ActivePerl 5.6.1 and 5.8.8 (Windows XP).
Please see the attached patch file for a fix.
Subject: | symbol_patch.txt |
--- Symbol.pm Sat Sep 2 00:03:24 2006
+++ Symbol.pm Tue Sep 19 17:08:29 2006
@@ -98,12 +98,19 @@
my $braces = $after->braces;
return $symbol unless defined $braces;
if ( $type eq '$' ) {
- return substr( $symbol, 0, 1, '@' ) if $braces eq '[]';
- return substr( $symbol, 0, 1, '%' ) if $braces eq '{}';
-
+ if ( $braces eq '[]' ) {
+ substr( $symbol, 0, 1, '@' );
+ return $symbol;
+ }
+ if ( $braces eq '{}' ) {
+ substr( $symbol, 0, 1, '%' );
+ return $symbol;
+ }
} elsif ( $type eq '@' ) {
- return substr( $symbol, 0, 1, '%' ) if $braces eq '{}';
-
+ if ( $braces eq '{}' ) {
+ substr( $symbol, 0, 1, '%' );
+ return $symbol;
+ }
}
$symbol;