CC: | Heiko <heiko [...] hexco.de> |
Subject: | RequireLocalizedPunctuationVars doesn't handle lexicalized $a and $b. |
Date: | Sun, 09 Mar 2008 16:58:52 -0500 |
To: | bug-Perl-Critic [...] rt.cpan.org |
From: | Elliot Shank <perl [...] galumph.com> |
Variables::RequireLocalizedPunctuationVars.pm gives
Magic variables should be assigned as "local" at line 11, column 15. See pages 81,82 of PBP. (Severity: 4)
Magic variables should be assigned as "local" at line 12, column 15. See pages 81,82 of PBP. (Severity: 4)
on this code:
for my $entry (
sort {
my @a = split m{,}xms, $a;
my @b = split m{,}xms, $b;
$a[0] cmp $b[0] || $a[1] <=> $b[1]
} qw( b,6 c,3 )
)
{
print;
}
While '$a' is a punctuation variable, 'my @a' is none (and 'my $a' would also be none).
The patch makes sure to return without a violation in the presence of 'my' or 'local'.
If there were a list of punctuation variables to consult including sigils, this false alarm would vanish also.
--- RequireLocalizedPunctuationVars.pm.org 2008-02-25 23:28:36.890625000 +0100
+++ RequireLocalizedPunctuationVars.pm.new 2008-02-23 23:55:53.046875000 +0100
@@ -58,7 +58,7 @@
# Quick exit if in good form
my $modifier = $elem->sprevious_sibling;
return if $modifier && $modifier->isa('PPI::Token::Word')
- && $modifier eq 'local';
+ && ($modifier eq 'local' || $modifier eq 'my');
# Implementation note: Can't rely on PPI::Token::Magic,
# unfortunately, because we need English too