line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitStringyEval; |
2
|
133
|
|
|
133
|
|
69482
|
use strict; |
|
133
|
|
|
|
|
193
|
|
|
133
|
|
|
|
|
3156
|
|
3
|
133
|
|
|
133
|
|
428
|
use warnings; |
|
133
|
|
|
|
|
195
|
|
|
133
|
|
|
|
|
2441
|
|
4
|
133
|
|
|
133
|
|
802
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
163
|
|
|
133
|
|
|
|
|
58487
|
|
5
|
133
|
|
|
133
|
|
579
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
181
|
|
|
133
|
|
|
|
|
594
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
58030
|
DESC => 'Expression form of "eval"', |
9
|
|
|
|
|
|
|
EXPL => [161], |
10
|
133
|
|
|
133
|
|
6502
|
}; |
|
133
|
|
|
|
|
182
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
11
|
|
|
11
|
0
|
25
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
11
|
|
100
|
|
|
49
|
my $allow_includes = $args->{prohibit_stringy_eval}->{allow_includes} || 0; |
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
|
|
17
|
my @violations; |
18
|
11
|
|
|
|
|
40
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
19
|
347
|
|
|
|
|
237
|
my $token_type = $token->{type}; |
20
|
347
|
|
|
|
|
237
|
my $token_data = $token->{data}; |
21
|
|
|
|
|
|
|
|
22
|
347
|
100
|
100
|
|
|
796
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'eval') { |
23
|
101
|
|
|
|
|
70
|
$token = $tokens->[++$i]; |
24
|
101
|
100
|
|
|
|
134
|
if ($token->{type} == LEFT_PAREN) { |
25
|
7
|
|
|
|
|
9
|
$token = $tokens->[++$i]; |
26
|
7
|
100
|
|
|
|
17
|
if ($token->{type} == RIGHT_PAREN) { |
27
|
1
|
|
|
|
|
3
|
next; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
100
|
|
|
|
|
76
|
$token_type = $token->{type}; |
31
|
|
|
|
|
|
|
|
32
|
100
|
100
|
|
|
|
128
|
if ($token_type != LEFT_BRACE) { |
33
|
98
|
100
|
|
|
|
116
|
if ($allow_includes) { |
34
|
48
|
100
|
|
|
|
96
|
if ($token_type == STRING) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
35
|
5
|
100
|
|
|
|
14
|
if ($token->{data} =~ /\A(?:use|require)[^;]*(?:;|;\s*1;)?\Z/) { |
36
|
4
|
|
|
|
|
8
|
next; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($token_type == RAW_STRING) { |
40
|
20
|
100
|
|
|
|
70
|
if ($token->{data} =~ /\A(?:use|require)\s+([^;\s]+)[^;]*(?:;|;\s*1;)?\Z/) { |
41
|
17
|
100
|
|
|
|
29
|
if ($1 !~ /\A\$/) { |
42
|
16
|
|
|
|
|
25
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == REG_DOUBLE_QUOTE) { |
47
|
4
|
|
|
|
|
2
|
$i += 2; # skip reg delimiter |
48
|
4
|
|
|
|
|
4
|
$token = $tokens->[$i]; |
49
|
4
|
50
|
|
|
|
11
|
if ($token->{data} =~ /\A(?:use|require)[^;]*(?:;|;\s*1;)?\Z/) { |
50
|
4
|
|
|
|
|
8
|
next; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($token_type == REG_QUOTE) { |
54
|
19
|
|
|
|
|
12
|
$i += 2; # skip reg delimiter |
55
|
19
|
|
|
|
|
12
|
$token = $tokens->[$i]; |
56
|
19
|
100
|
|
|
|
58
|
if ($token->{data} =~ /\A(?:use|require)\s+([^;\s]+)[^;]*(?:;|;\s*1;)?\Z/) { |
57
|
17
|
100
|
|
|
|
29
|
if ($1 !~ /\A\$/) { |
58
|
16
|
|
|
|
|
28
|
next; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
push @violations, { |
65
|
|
|
|
|
|
|
filename => $file, |
66
|
|
|
|
|
|
|
line => $token->{line}, |
67
|
58
|
|
|
|
|
206
|
description => DESC, |
68
|
|
|
|
|
|
|
explanation => EXPL, |
69
|
|
|
|
|
|
|
policy => __PACKAGE__, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
11
|
|
|
|
|
46
|
return \@violations; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|