line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::RequireLexicalLoopIterators; |
2
|
133
|
|
|
133
|
|
700986
|
use strict; |
|
133
|
|
|
|
|
196
|
|
|
133
|
|
|
|
|
3578
|
|
3
|
133
|
|
|
133
|
|
485
|
use warnings; |
|
133
|
|
|
|
|
166
|
|
|
133
|
|
|
|
|
3421
|
|
4
|
133
|
|
|
133
|
|
1537
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
155
|
|
|
133
|
|
|
|
|
69654
|
|
5
|
133
|
|
|
133
|
|
594
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
182
|
|
|
133
|
|
|
|
|
794
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
31597
|
DESC => 'Loop iterator is not lexical', |
9
|
|
|
|
|
|
|
EXPL => [108], |
10
|
133
|
|
|
133
|
|
8197
|
}; |
|
133
|
|
|
|
|
164
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
8
|
|
|
8
|
0
|
11
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
8
|
|
|
|
|
8
|
my $perl_version_threshold = 5.003; |
16
|
8
|
|
|
|
|
7
|
my $perl_version = 6; # to hit always on default. Yes, this is Perl6 :) |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
8
|
my @violations; |
19
|
8
|
|
|
|
|
21
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
20
|
154
|
|
|
|
|
109
|
$token_type = $token->{type}; |
21
|
|
|
|
|
|
|
|
22
|
154
|
100
|
100
|
|
|
640
|
if ( |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
23
|
|
|
|
|
|
|
$token_type == FOR_STATEMENT || |
24
|
|
|
|
|
|
|
($token_type == FOREACH_STATEMENT && $perl_version > $perl_version_threshold) |
25
|
|
|
|
|
|
|
) { |
26
|
18
|
|
|
|
|
20
|
$token = $tokens->[++$i]; |
27
|
18
|
|
|
|
|
16
|
$token_type = $token->{type}; |
28
|
|
|
|
|
|
|
|
29
|
18
|
100
|
100
|
|
|
57
|
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
|
|
|
|
|
2
|
$token = $tokens->[++$i]; |
41
|
1
|
50
|
|
|
|
4
|
if ($token->{type} == DOUBLE) { |
42
|
1
|
|
|
|
|
3
|
$perl_version = $token->{data}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
30
|
return \@violations; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|