line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::ProhibitMatchVars; |
2
|
133
|
|
|
133
|
|
68236
|
use strict; |
|
133
|
|
|
|
|
178
|
|
|
133
|
|
|
|
|
3080
|
|
3
|
133
|
|
|
133
|
|
428
|
use warnings; |
|
133
|
|
|
|
|
147
|
|
|
133
|
|
|
|
|
2449
|
|
4
|
133
|
|
|
133
|
|
791
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
151
|
|
|
133
|
|
|
|
|
58862
|
|
5
|
133
|
|
|
133
|
|
551
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
174
|
|
|
133
|
|
|
|
|
632
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
39564
|
DESC => 'Match variable used', |
9
|
|
|
|
|
|
|
EXPL => [82], |
10
|
133
|
|
|
133
|
|
6942
|
}; |
|
133
|
|
|
|
|
173
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
5
|
|
|
5
|
0
|
9
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
5
|
my @violations; |
16
|
5
|
|
|
|
|
16
|
for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { |
17
|
45
|
|
|
|
|
38
|
$token_type = $token->{type}; |
18
|
45
|
|
|
|
|
35
|
$token_data = $token->{data}; |
19
|
|
|
|
|
|
|
|
20
|
45
|
100
|
66
|
|
|
141
|
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
|
|
|
|
|
16
|
description => DESC, |
26
|
|
|
|
|
|
|
explanation => EXPL, |
27
|
|
|
|
|
|
|
policy => __PACKAGE__, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($token_type == GLOBAL_VAR) { |
32
|
3
|
50
|
100
|
|
|
13
|
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
|
|
|
|
|
12
|
description => DESC, |
41
|
|
|
|
|
|
|
explanation => EXPL, |
42
|
|
|
|
|
|
|
policy => __PACKAGE__, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == USED_NAME && $token_data eq 'English') { |
47
|
10
|
|
|
|
|
12
|
$token = $tokens->[++$i]; |
48
|
|
|
|
|
|
|
|
49
|
10
|
100
|
|
|
|
16
|
if ($token->{type} == REG_LIST) { |
50
|
9
|
|
|
|
|
6
|
$i++; # Skip the first REG_DELIM |
51
|
9
|
|
|
|
|
15
|
for ($i++; $token = $tokens->[$i]; $i++) { |
52
|
18
|
|
|
|
|
15
|
$token_type = $token->{type}; |
53
|
18
|
100
|
|
|
|
28
|
if ($token_type == REG_DELIM) { |
|
|
50
|
|
|
|
|
|
54
|
9
|
|
|
|
|
17
|
last; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($token_type == REG_EXP) { |
57
|
9
|
|
|
|
|
21
|
my @regexps = split / /, $token->{data}; |
58
|
9
|
|
|
|
|
13
|
for my $regexp (@regexps) { |
59
|
11
|
100
|
100
|
|
|
47
|
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
|
|
|
|
|
42
|
description => DESC, |
68
|
|
|
|
|
|
|
explanation => EXPL, |
69
|
|
|
|
|
|
|
policy => __PACKAGE__, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
13
|
return \@violations; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|