From: Vincent Pit Date: Thu, 9 Jul 2009 08:04:05 +0000 (+0200) Subject: Make sure the errors are sorted before mapping them to PPI elements X-Git-Tag: v0.03~2 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git;a=commitdiff_plain;h=ba8eb2c0e9b3b9a75dc7fd128e722b1a0eef8b75 Make sure the errors are sorted before mapping them to PPI elements --- diff --git a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm index 20b9e27..aa4a03a 100644 --- a/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm +++ b/lib/Perl/Critic/Policy/Dynamic/NoIndirect.pm @@ -71,6 +71,8 @@ sub violates_dynamic { } } + @errs = sort { $a->[3] <=> $b->[3] } @errs; + my @violations; if (@errs) { diff --git a/t/10-basic.t b/t/10-basic.t index a1b1885..29c2f10 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -5,11 +5,11 @@ use warnings; my ($tests, $subtests); BEGIN { - $tests = 8; + $tests = 13; $subtests = 3; } -use Test::More tests => $tests + $subtests * 14; +use Test::More tests => $tests + $subtests * 21; use Perl::Critic::TestUtils qw/pcritique_with_violations/; @@ -77,6 +77,21 @@ my $y = new X; ---- [ 'new', 'X', 1, 9 ], [ 'new', 'X', 2, 9 ] #### +my $x = new + X; +---- +[ 'new', 'X', 1, 9 ] +#### +my $x = new + X new + X; +---- +[ 'new', 'X', 1, 9 ], [ 'new', 'X', 2, 4 ] +#### +my $x = new new; +---- +[ 'new', 'new', 1, 9 ] +#### our $obj; my $x = new $obj; ---- @@ -97,4 +112,16 @@ my $x = new $obj; my $y = new $obj; ---- [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 9 ] - +#### +our $obj; +my $x = new + $obj; +---- +[ 'new', '$obj', 2, 9 ] +#### +our $obj; +my $x = new + $obj new + $obj; +---- +[ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 7 ]