line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::BuiltinFunctions::ProhibitStringyEval; |
2
|
133
|
|
|
133
|
|
68634
|
use strict; |
|
133
|
|
|
|
|
191
|
|
|
133
|
|
|
|
|
3203
|
|
3
|
133
|
|
|
133
|
|
421
|
use warnings; |
|
133
|
|
|
|
|
164
|
|
|
133
|
|
|
|
|
2474
|
|
4
|
133
|
|
|
133
|
|
804
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
165
|
|
|
133
|
|
|
|
|
58554
|
|
5
|
133
|
|
|
133
|
|
584
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
177
|
|
|
133
|
|
|
|
|
591
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
57461
|
DESC => 'Expression form of "eval"', |
9
|
|
|
|
|
|
|
EXPL => [161], |
10
|
133
|
|
|
133
|
|
7097
|
}; |
|
133
|
|
|
|
|
181
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
11
|
|
|
11
|
0
|
40
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
11
|
|
100
|
|
|
57
|
my $allow_includes = $args->{prohibit_stringy_eval}->{allow_includes} || 0; |
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
|
|
17
|
my @violations; |
18
|
11
|
|
|
|
|
46
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
19
|
347
|
|
|
|
|
236
|
my $token_type = $token->{type}; |
20
|
347
|
|
|
|
|
262
|
my $token_data = $token->{data}; |
21
|
|
|
|
|
|
|
|
22
|
347
|
100
|
100
|
|
|
760
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'eval') { |
23
|
101
|
|
|
|
|
92
|
$token = $tokens->[++$i]; |
24
|
101
|
100
|
|
|
|
132
|
if ($token->{type} == LEFT_PAREN) { |
25
|
7
|
|
|
|
|
9
|
$token = $tokens->[++$i]; |
26
|
7
|
100
|
|
|
|
16
|
if ($token->{type} == RIGHT_PAREN) { |
27
|
1
|
|
|
|
|
3
|
next; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
100
|
|
|
|
|
86
|
$token_type = $token->{type}; |
31
|
|
|
|
|
|
|
|
32
|
100
|
100
|
|
|
|
125
|
if ($token_type != LEFT_BRACE) { |
33
|
98
|
100
|
|
|
|
128
|
if ($allow_includes) { |
34
|
48
|
100
|
|
|
|
100
|
if ($token_type == STRING) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
35
|
5
|
100
|
|
|
|
18
|
if ($token->{data} =~ /\A(?:use|require)[^;]*(?:;|;\s*1;)?\Z/) { |
36
|
4
|
|
|
|
|
6
|
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
|
|
|
|
|
27
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($token_type == REG_DOUBLE_QUOTE) { |
47
|
4
|
|
|
|
|
5
|
$i += 2; # skip reg delimiter |
48
|
4
|
|
|
|
|
3
|
$token = $tokens->[$i]; |
49
|
4
|
50
|
|
|
|
31
|
if ($token->{data} =~ /\A(?:use|require)[^;]*(?:;|;\s*1;)?\Z/) { |
50
|
4
|
|
|
|
|
9
|
next; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($token_type == REG_QUOTE) { |
54
|
19
|
|
|
|
|
17
|
$i += 2; # skip reg delimiter |
55
|
19
|
|
|
|
|
13
|
$token = $tokens->[$i]; |
56
|
19
|
100
|
|
|
|
64
|
if ($token->{data} =~ /\A(?:use|require)\s+([^;\s]+)[^;]*(?:;|;\s*1;)?\Z/) { |
57
|
17
|
100
|
|
|
|
28
|
if ($1 !~ /\A\$/) { |
58
|
16
|
|
|
|
|
27
|
next; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
push @violations, { |
65
|
|
|
|
|
|
|
filename => $file, |
66
|
|
|
|
|
|
|
line => $token->{line}, |
67
|
58
|
|
|
|
|
198
|
description => DESC, |
68
|
|
|
|
|
|
|
explanation => EXPL, |
69
|
|
|
|
|
|
|
policy => __PACKAGE__, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
11
|
|
|
|
|
42
|
return \@violations; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|