line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::TooMuchCode; |
2
|
5
|
|
|
5
|
|
536
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
2617
|
|
3
|
|
|
|
|
|
|
our $VERSION='0.19'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
## Look for the signature of misparsed ternary operator. |
6
|
|
|
|
|
|
|
## https://github.com/adamkennedy/PPI/issues/62 |
7
|
|
|
|
|
|
|
## Once PPI is fixed, this workaround can be eliminated. |
8
|
|
|
|
|
|
|
sub __get_terop_usage { |
9
|
30
|
|
|
30
|
|
55
|
my ($used, $doc) = @_; |
10
|
30
|
100
|
|
864
|
|
139
|
for my $question_mark (@{ $doc->find( sub { $_[1]->isa('PPI::Token::Operator') && $_[1]->content eq '?' }) ||[]}) { |
|
30
|
100
|
|
|
|
141
|
|
|
864
|
|
|
|
|
11140
|
|
11
|
4
|
|
|
|
|
37
|
my $el = $question_mark->snext_sibling; |
12
|
4
|
100
|
|
|
|
158
|
next unless $el->isa('PPI::Token::Label'); |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
10
|
my $tok = $el->content; |
15
|
3
|
|
|
|
|
25
|
$tok =~ s/\s*:\z//; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
10
|
$used->{$tok}++; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub __get_symbol_usage { |
22
|
30
|
|
|
30
|
|
69
|
my ($usage, $doc) = @_; |
23
|
|
|
|
|
|
|
|
24
|
30
|
|
|
|
|
95
|
__get_terop_usage($usage, $doc); |
25
|
|
|
|
|
|
|
|
26
|
30
|
|
|
|
|
544
|
Perl::Critic::Policy::Variables::ProhibitUnusedVariables::_get_regexp_symbol_usage($usage, $doc); |
27
|
|
|
|
|
|
|
|
28
|
30
|
100
|
|
|
|
1380
|
for my $e (@{ $doc->find('PPI::Token::Symbol') || [] }) { |
|
30
|
|
|
|
|
76
|
|
29
|
21
|
|
|
|
|
476
|
$usage->{ $e->symbol() }++; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
30
|
|
|
|
|
888
|
for my $class (qw{ |
33
|
|
|
|
|
|
|
PPI::Token::Quote::Double |
34
|
|
|
|
|
|
|
PPI::Token::Quote::Interpolate |
35
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Backtick |
36
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Command |
37
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Readline |
38
|
|
|
|
|
|
|
PPI::Token::HereDoc |
39
|
|
|
|
|
|
|
}) { |
40
|
180
|
100
|
|
|
|
1852
|
for my $e (@{ $doc->find( $class ) || [] }) { |
|
180
|
|
|
|
|
370
|
|
41
|
5
|
50
|
|
|
|
86
|
my $str = PPIx::QuoteLike->new( $e ) or next; |
42
|
5
|
|
|
|
|
7343
|
for my $var ( $str->variables() ) { |
43
|
2
|
|
|
|
|
7968
|
$usage->{ $var }++; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Gather usages in the exact form of: |
49
|
|
|
|
|
|
|
# our @EXPORT = qw( ... ); |
50
|
|
|
|
|
|
|
# our @EXPORT_OK = qw( ... ); |
51
|
30
|
100
|
|
|
|
354
|
for my $st (@{ $doc->find('PPI::Statement::Variable') || [] }) { |
|
30
|
|
|
|
|
76
|
|
52
|
14
|
100
|
|
|
|
167
|
next unless $st->schildren == 5; |
53
|
|
|
|
|
|
|
|
54
|
7
|
|
|
|
|
208
|
my @children = $st->schildren; |
55
|
7
|
50
|
66
|
|
|
128
|
next unless $children[0]->content() eq 'our' |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
56
|
|
|
|
|
|
|
&& ($children[1]->content() eq '@EXPORT' |
57
|
|
|
|
|
|
|
|| $children[1]->content() eq '@EXPORT_OK') |
58
|
|
|
|
|
|
|
&& $children[2]->content() eq '=' |
59
|
|
|
|
|
|
|
&& $children[3]->isa('PPI::Token::QuoteLike::Words') |
60
|
|
|
|
|
|
|
&& $children[4]->content() eq ';'; |
61
|
|
|
|
|
|
|
|
62
|
5
|
|
|
|
|
154
|
for my $w ($children[3]->literal) { |
63
|
10
|
|
|
|
|
319
|
$usage->{ $w }++; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
30
|
|
|
|
|
439
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Perl::Critic::TooMuchCode - perlcritic add-ons that generally check for dead code. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This add-on for L<Perl::Critic> is aiming for identifying trivial dead |
81
|
|
|
|
|
|
|
code. Either the ones that has no use, or the one that produce no |
82
|
|
|
|
|
|
|
effect. Having dead code floating around causes maintenance burden. Some |
83
|
|
|
|
|
|
|
might prefer not to generate them in the first place. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Kang-min Liu <gugod@gugod.org> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
MIT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |