line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::TestingAndDebugging::RequireUseWarnings; |
2
|
133
|
|
|
133
|
|
67249
|
use strict; |
|
133
|
|
|
|
|
165
|
|
|
133
|
|
|
|
|
3112
|
|
3
|
133
|
|
|
133
|
|
398
|
use warnings; |
|
133
|
|
|
|
|
155
|
|
|
133
|
|
|
|
|
2725
|
|
4
|
133
|
|
|
133
|
|
375
|
use List::Util qw/any/; |
|
133
|
|
|
|
|
130
|
|
|
133
|
|
|
|
|
5914
|
|
5
|
133
|
|
|
133
|
|
993
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
139
|
|
|
133
|
|
|
|
|
59179
|
|
6
|
133
|
|
|
133
|
|
525
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
155
|
|
|
133
|
|
|
|
|
530
|
|
7
|
|
|
|
|
|
|
|
8
|
133
|
|
|
133
|
|
5983
|
use constant EQUIVALENT_PERL_VERSION => 5.005; |
|
133
|
|
|
|
|
157
|
|
|
133
|
|
|
|
|
6834
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant { |
11
|
133
|
|
|
|
|
44999
|
DESC => 'Code before warnings are enabled', |
12
|
|
|
|
|
|
|
EXPL => [431], |
13
|
133
|
|
|
133
|
|
451
|
}; |
|
133
|
|
|
|
|
145
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub evaluate { |
16
|
20
|
|
|
20
|
0
|
33
|
my ($class, $file, $tokens, $src, $args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
43
|
my @marshals = ('warnings', 'Moose', 'Moose::Role', 'Moose::Util::TypeConstraints'); |
19
|
20
|
100
|
|
|
|
42
|
if (my $this_policies_arg = $args->{require_use_warnings}) { |
20
|
1
|
|
50
|
|
|
9
|
push @marshals, split / /, ($this_policies_arg->{equivalent_modules} || ''); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
20
|
|
|
|
|
19
|
my @violations; |
24
|
20
|
|
|
|
|
20
|
my $token_num = scalar @$tokens; |
25
|
20
|
|
|
|
|
18
|
my $is_used_strict = 0; |
26
|
20
|
|
|
|
|
42
|
TOP: for (my $i = 0; $i < $token_num; $i++) { |
27
|
23
|
|
|
|
|
23
|
my $token = $tokens->[$i]; |
28
|
23
|
|
|
|
|
26
|
my $token_type = $token->{type}; |
29
|
|
|
|
|
|
|
|
30
|
23
|
100
|
|
|
|
42
|
if ($token_type == USE_DECL) { |
31
|
11
|
|
|
|
|
15
|
my $next_token = $tokens->[$i+1]; |
32
|
11
|
100
|
|
|
|
26
|
if ($next_token->{type} == DOUBLE) { |
33
|
2
|
|
|
|
|
5
|
(my $next_token_data = $next_token->{data}) =~ s/_//g; |
34
|
2
|
100
|
|
|
|
10
|
if ($next_token_data == EQUIVALENT_PERL_VERSION) { |
35
|
1
|
|
|
|
|
4
|
last; |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
|
|
4
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
11
|
my $used_module = ''; |
41
|
9
|
|
|
|
|
24
|
for ($i++; $i < $token_num; $i++) { |
42
|
24
|
|
|
|
|
26
|
$token = $tokens->[$i]; |
43
|
24
|
|
|
|
|
16
|
my $token_type = $token->{type}; |
44
|
24
|
|
|
|
|
36
|
my $token_data = $token->{data}; |
45
|
24
|
100
|
100
|
|
|
96
|
if ( |
|
|
|
100
|
|
|
|
|
46
|
|
|
|
|
|
|
$token_type == USED_NAME || |
47
|
|
|
|
|
|
|
$token_type == NAMESPACE || |
48
|
|
|
|
|
|
|
$token_type == NAMESPACE_RESOLVER |
49
|
|
|
|
|
|
|
) { |
50
|
15
|
|
|
|
|
31
|
$used_module .= $token_data; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
9
|
100
|
|
22
|
|
71
|
if (any {$_ eq $used_module} @marshals) { |
|
22
|
|
|
|
|
32
|
|
54
|
8
|
|
|
|
|
18
|
last TOP; |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
6
|
next TOP; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
12
|
100
|
|
|
|
18
|
if ($token_type == PACKAGE) { |
62
|
1
|
|
|
|
|
6
|
for ($i++; $i < $token_num; $i++) { |
63
|
2
|
|
|
|
|
2
|
$token = $tokens->[$i]; |
64
|
2
|
100
|
|
|
|
6
|
if ($token->{type} == SEMI_COLON) { |
65
|
1
|
|
|
|
|
3
|
next TOP; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
push @violations, { |
71
|
|
|
|
|
|
|
filename => $file, |
72
|
|
|
|
|
|
|
line => $token->{line}, |
73
|
11
|
|
|
|
|
46
|
description => DESC, |
74
|
|
|
|
|
|
|
explanation => EXPL, |
75
|
|
|
|
|
|
|
policy => __PACKAGE__, |
76
|
|
|
|
|
|
|
}; |
77
|
11
|
|
|
|
|
19
|
last; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
20
|
|
|
|
|
85
|
return \@violations; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|