line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::ProhibitMatchVars; |
2
|
133
|
|
|
133
|
|
67565
|
use strict; |
|
133
|
|
|
|
|
181
|
|
|
133
|
|
|
|
|
3119
|
|
3
|
133
|
|
|
133
|
|
408
|
use warnings; |
|
133
|
|
|
|
|
140
|
|
|
133
|
|
|
|
|
2413
|
|
4
|
133
|
|
|
133
|
|
817
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
146
|
|
|
133
|
|
|
|
|
58687
|
|
5
|
133
|
|
|
133
|
|
541
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
156
|
|
|
133
|
|
|
|
|
538
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
39982
|
DESC => 'Match variable used', |
9
|
|
|
|
|
|
|
EXPL => [82], |
10
|
133
|
|
|
133
|
|
6661
|
}; |
|
133
|
|
|
|
|
166
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
5
|
|
|
5
|
0
|
15
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
4
|
my @violations; |
16
|
5
|
|
|
|
|
18
|
for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { |
17
|
45
|
|
|
|
|
31
|
$token_type = $token->{type}; |
18
|
45
|
|
|
|
|
34
|
$token_data = $token->{data}; |
19
|
|
|
|
|
|
|
|
20
|
45
|
100
|
66
|
|
|
137
|
if ($token_type == SPECIFIC_VALUE) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
21
|
5
|
50
|
100
|
|
|
22
|
if ($token_data eq q{$`} || $token_data eq q{$&} || $token_data eq q{$'}) { |
|
|
|
66
|
|
|
|
|
22
|
|
|
|
|
|
|
push @violations, { |
23
|
|
|
|
|
|
|
filename => $file, |
24
|
|
|
|
|
|
|
line => $token->{line}, |
25
|
5
|
|
|
|
|
17
|
description => DESC, |
26
|
|
|
|
|
|
|
explanation => EXPL, |
27
|
|
|
|
|
|
|
policy => __PACKAGE__, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($token_type == GLOBAL_VAR) { |
32
|
3
|
50
|
100
|
|
|
11
|
if ( |
|
|
|
66
|
|
|
|
|
33
|
|
|
|
|
|
|
$token_data eq '$PREMATCH' || |
34
|
|
|
|
|
|
|
$token_data eq '$MATCH' || |
35
|
|
|
|
|
|
|
$token_data eq '$POSTMATCH' |
36
|
|
|
|
|
|
|
) { |
37
|
|
|
|
|
|
|
push @violations, { |
38
|
|
|
|
|
|
|
filename => $file, |
39
|
|
|
|
|
|
|
line => $token->{line}, |
40
|
3
|
|
|
|
|
11
|
description => DESC, |
41
|
|
|
|
|
|
|
explanation => EXPL, |
42
|
|
|
|
|
|
|
policy => __PACKAGE__, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == USED_NAME && $token_data eq 'English') { |
47
|
10
|
|
|
|
|
10
|
$token = $tokens->[++$i]; |
48
|
|
|
|
|
|
|
|
49
|
10
|
100
|
|
|
|
17
|
if ($token->{type} == REG_LIST) { |
50
|
9
|
|
|
|
|
10
|
$i++; # Skip the first REG_DELIM |
51
|
9
|
|
|
|
|
12
|
for ($i++; $token = $tokens->[$i]; $i++) { |
52
|
18
|
|
|
|
|
12
|
$token_type = $token->{type}; |
53
|
18
|
100
|
|
|
|
31
|
if ($token_type == REG_DELIM) { |
|
|
50
|
|
|
|
|
|
54
|
9
|
|
|
|
|
18
|
last; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($token_type == REG_EXP) { |
57
|
9
|
|
|
|
|
17
|
my @regexps = split / /, $token->{data}; |
58
|
9
|
|
|
|
|
11
|
for my $regexp (@regexps) { |
59
|
11
|
100
|
100
|
|
|
44
|
if ( |
|
|
|
100
|
|
|
|
|
60
|
|
|
|
|
|
|
$regexp eq '$PREMATCH' || |
61
|
|
|
|
|
|
|
$regexp eq '$MATCH' || |
62
|
|
|
|
|
|
|
$regexp eq '$POSTMATCH' |
63
|
|
|
|
|
|
|
) { |
64
|
|
|
|
|
|
|
push @violations, { |
65
|
|
|
|
|
|
|
filename => $file, |
66
|
|
|
|
|
|
|
line => $token->{line}, |
67
|
9
|
|
|
|
|
35
|
description => DESC, |
68
|
|
|
|
|
|
|
explanation => EXPL, |
69
|
|
|
|
|
|
|
policy => __PACKAGE__, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
15
|
return \@violations; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|