line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::RequireLexicalLoopIterators; |
2
|
133
|
|
|
133
|
|
690155
|
use strict; |
|
133
|
|
|
|
|
202
|
|
|
133
|
|
|
|
|
3824
|
|
3
|
133
|
|
|
133
|
|
494
|
use warnings; |
|
133
|
|
|
|
|
154
|
|
|
133
|
|
|
|
|
3729
|
|
4
|
133
|
|
|
133
|
|
1560
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
157
|
|
|
133
|
|
|
|
|
69796
|
|
5
|
133
|
|
|
133
|
|
616
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
175
|
|
|
133
|
|
|
|
|
829
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
33065
|
DESC => 'Loop iterator is not lexical', |
9
|
|
|
|
|
|
|
EXPL => [108], |
10
|
133
|
|
|
133
|
|
8583
|
}; |
|
133
|
|
|
|
|
175
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
8
|
|
|
8
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
8
|
|
|
|
|
7
|
my $perl_version_threshold = 5.003; |
16
|
8
|
|
|
|
|
4
|
my $perl_version = 6; # to hit always on default. Yes, this is Perl6 :) |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
8
|
my @violations; |
19
|
8
|
|
|
|
|
22
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
20
|
154
|
|
|
|
|
100
|
$token_type = $token->{type}; |
21
|
|
|
|
|
|
|
|
22
|
154
|
100
|
100
|
|
|
645
|
if ( |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
23
|
|
|
|
|
|
|
$token_type == FOR_STATEMENT || |
24
|
|
|
|
|
|
|
($token_type == FOREACH_STATEMENT && $perl_version > $perl_version_threshold) |
25
|
|
|
|
|
|
|
) { |
26
|
18
|
|
|
|
|
15
|
$token = $tokens->[++$i]; |
27
|
18
|
|
|
|
|
13
|
$token_type = $token->{type}; |
28
|
|
|
|
|
|
|
|
29
|
18
|
100
|
100
|
|
|
55
|
if ($token_type != VAR_DECL && $token_type != LEFT_PAREN) { |
30
|
|
|
|
|
|
|
push @violations, { |
31
|
|
|
|
|
|
|
filename => $file, |
32
|
|
|
|
|
|
|
line => $token->{line}, |
33
|
9
|
|
|
|
|
35
|
description => DESC, |
34
|
|
|
|
|
|
|
explanation => EXPL, |
35
|
|
|
|
|
|
|
policy => __PACKAGE__, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($token_type == USE_DECL || $token_type == REQUIRE_DECL) { |
40
|
1
|
|
|
|
|
3
|
$token = $tokens->[++$i]; |
41
|
1
|
50
|
|
|
|
3
|
if ($token->{type} == DOUBLE) { |
42
|
1
|
|
|
|
|
4
|
$perl_version = $token->{data}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
27
|
return \@violations; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|