Perl/Lint/Policy/Subroutines/ProhibitUnusedPrivateSubroutines.pm

filter: Statementstmt 21.5% 19 / 88 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 10.7% 25 / 233 CC 51 SCAR 77.7
CC
51
Cov
10%
evaluate
2652.0
BEGIN
1.0
BEGIN
1.0
CRAP 2372.9
« Perl/Lint/Policy/Subroutines/RequireFinalReturn.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm »
1 package Perl::Lint::Policy::Subroutines::ProhibitUnusedPrivateSubroutines;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Compiler::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Private subroutine/method "%s" declared but not used',
10 EXPL => 'Eliminate dead code',
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=51 SCAR=78.8
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my %allow;
17 0 ▶ if (my $allow = $args->{prohibit_unused_private_subroutines}->{allow}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $allow = $args->{"prohibit_unused_private_subroutines"}{"allow"}) 0 0 0
18 0 $allow{$_} = 1 for split / /, $allow;
19 }
20 0 my $allow_regex = $args->{prohibit_unused_private_subroutines}->{private_name_regex};
21  
22 0 my $lexer;
23 my @violations;
24 0 my @private_functions;
25 0 my %ignores;
26 0 my %called;
27 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
28 0 my $token_type = $token->{type};
29 0 my $token_data = $token->{data};
30  
31 0 ▶ if ($token_type == FUNCTION_DECL) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 63) { } 0 0 0
elsif ($token_type == 204 or $token_type == 122 or $token_type == 64) { } 0 0 0
elsif ($token_type == 94 and $token_data eq 'overload') { } 0 0 0
elsif ($token_type == 155 or $token_type == 150) { } 0 0 0
32 0 $token = $tokens->[++$i];
33 0 $token_data = $token->{data};
34 0 my $function_token = $token;
35 0 ▶ if (substr($token_data, 0, 1) eq '_' && !$allow{$token_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($token_data, 0, 1) eq "_" and not $allow{$token_data}) 0 0 0
Condition0%0/3
substr($token_data, 0, 1) eq "_" and not $allow{$token_data}
!ll&&!rl&&r
000
MC/DC0%0/2
substr($token_data, 0, 1) eq "_" and not $allow{$token_data}
substr($token_data, 0, 1) eq "_" not $allow{$token_data}
Truth table0%0/3
A and not(B)
A= substr($token_data, 0, 1) eq "_"B= not $allow{$token_data}
ABresult
0X0
100
111
36 0 ▶ if (!$allow_regex || $token_data !~ /$allow_regex/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allow_regex and $token_data =~ /$allow_regex/) 0 0 0
Condition0%0/3
$allow_regex and $token_data =~ /$allow_regex/
!ll&&!rl&&r
000
MC/DC0%0/2
$allow_regex and $token_data =~ /$allow_regex/
$allow_regex $token_data =~ /$allow_regex/
Truth table0%0/3
A and B
A= $allow_regexB= $token_data =~ /$allow_regex/
ABresult
0X0
100
111
37 0 my $declared_private_function = '';
38 0 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
39 0 $token_type = $token->{type};
40 0 ▶ if ($token_type == NAMESPACE || $token_type == FUNCTION) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 127 or $token_type == 203) { } 0 0 0
elsif ($token_type == 126) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
Condition0%0/3
$token_type == 127 or $token_type == 203
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 127 or $token_type == 203
$token_type == 127 $token_type == 203
Truth table0%0/3
A or B
A= $token_type == 127B= $token_type == 203
ABresult
1X1
011
000
41 0 $declared_private_function = $token->{data};
42 }
43 elsif ($token_type == NAMESPACE_RESOLVER) {
44 0 last;
45 }
46 elsif ($token_type == LEFT_BRACE) {
47 0 push @private_functions, $function_token;
48  
49 0 my $left_brace_num = 1;
50 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
51 0 $token_type = $token->{type};
52 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 204 or $token_type == 122 or $token_type == 64) { } 0 0 0
53 0 $left_brace_num++;
54 }
55 elsif ($token_type == RIGHT_BRACE) {
56 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
57 }
58 ▶ elsif ($token_type == CALL || $token_type == KEY || $token_type == METHOD) {
Condition0%0/6
$token_type == 204 or $token_type == 122 or $token_type == 64
l!l&&r!l&&!r
000
$token_type == 204 or $token_type == 122
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 204 or $token_type == 122 or $token_type == 64
$token_type == 204 $token_type == 122 $token_type == 64
Truth table0%0/4
A or B or C
A= $token_type == 204B= $token_type == 122C= $token_type == 64
ABCresult
1XX1
01X1
0011
0000
59 0 $token_data = $token->{data};
60 0 ▶ if ($token_data eq $declared_private_function) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq $declared_private_function) 0 0 0
61 0 next;
62 }
63 0 $called{$token_data} = 1;
64 }
65 }
66 0 last;
67 }
68 elsif ($token_type == SEMI_COLON) {
69 0 last;
70 }
71 }
72 }
73 }
74 }
75 ▶ elsif ($token_type == CALL || $token_type == KEY || $token_type == METHOD) {
Condition0%0/6
$token_type == 204 or $token_type == 122 or $token_type == 64
l!l&&r!l&&!r
000
$token_type == 204 or $token_type == 122
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 204 or $token_type == 122 or $token_type == 64
$token_type == 204 $token_type == 122 $token_type == 64
Truth table0%0/4
A or B or C
A= $token_type == 204B= $token_type == 122C= $token_type == 64
ABCresult
1XX1
01X1
0011
0000
76 0 $called{$token_data} = 1;
77 }
78 ▶ elsif ($token_type == USED_NAME && $token_data eq 'overload') {
Condition0%0/3
$token_type == 94 and $token_data eq "overload"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 94 and $token_data eq "overload"
$token_type == 94 $token_data eq "overload"
Truth table0%0/3
A and B
A= $token_type == 94B= $token_data eq "overload"
ABresult
0X0
100
111
79 0 my $is_value = 1;
80 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
81 0 $token_type = $token->{type};
82 0 my $next_token = $tokens->[$i+1];
83 0 my $next_token_type = $next_token->{type};
84 0 ▶ if ($token_type == ARROW) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 124) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
85 0 ▶ if ($is_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_value) 0 0 0
86 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
87 0 $token_type = $token->{type};
88 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 122 or $token_type == 172 or $token_type == 173) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
Condition0%0/6
$token_type == 122 or $token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
$token_type == 122 or $token_type == 172
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 122 or $token_type == 172 or $token_type == 173
$token_type == 122 $token_type == 172 $token_type == 173
Truth table0%0/4
A or B or C
A= $token_type == 122B= $token_type == 172C= $token_type == 173
ABCresult
1XX1
01X1
0011
0000
89 $token_type == KEY ||
90 $token_type == STRING ||
91 $token_type == RAW_STRING
92 ) {
93 0 $ignores{$token->{data}} = 1;
94 }
95 elsif ($token_type == SEMI_COLON) {
96 0 last; # fail safe
97 }
98 }
99 }
100 0 $is_value = !$is_value;
101 }
102 elsif ($token_type == SEMI_COLON) {
103 0 last;
104 }
105 }
106 }
107 ▶ elsif ($token_type == REG_REPLACE || $token_type == REG_MATCH) {
Condition0%0/3
$token_type == 155 or $token_type == 150
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 155 or $token_type == 150
$token_type == 155 $token_type == 150
Truth table0%0/3
A or B
A= $token_type == 155B= $token_type == 150
ABresult
1X1
011
000
108 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
109 0 $token_type = $token->{type};
110 0 ▶ if ($token_type == REG_REPLACE_TO || $token_type == REG_EXP) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 157 or $token_type == 187) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
Condition0%0/3
$token_type == 157 or $token_type == 187
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 157 or $token_type == 187
$token_type == 157 $token_type == 187
Truth table0%0/3
A or B
A= $token_type == 157B= $token_type == 187
ABresult
1X1
011
000
111 0 ▶ $lexer ||= Compiler::Lexer->new($file);
Condition0%0/3
$lexer ||= "Compiler::Lexer"->new($file)
l!l&&r!l&&!r
000
MC/DC0%0/2
$lexer ||= "Compiler::Lexer"->new($file)
$lexer "Compiler::Lexer"->new($file)
Truth table0%0/3
A ||= B
A= $lexerB= "Compiler::Lexer"->new($file)
ABresult
1X1
011
000
112 0 my $replace_to_tokens = $lexer->tokenize($token->{data});
113  
114 0 ▶ for (my $i = 0; $token = $replace_to_tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $replace_to_tokens->[$i]) 0 0 0
115 0 my $token_type = $token->{type};
116 0 ▶ if ($token_type == CALL || $token_type == KEY || $token_type == METHOD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 204 or $token_type == 122 or $token_type == 64) 0 0 0
Condition0%0/6
$token_type == 204 or $token_type == 122 or $token_type == 64
l!l&&r!l&&!r
000
$token_type == 204 or $token_type == 122
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 204 or $token_type == 122 or $token_type == 64
$token_type == 204 $token_type == 122 $token_type == 64
Truth table0%0/4
A or B or C
A= $token_type == 204B= $token_type == 122C= $token_type == 64
ABCresult
1XX1
01X1
0011
0000
117 0 $called{$token->{data}} = 1;
118 }
119 }
120 }
121 elsif ($token_type == SEMI_COLON) {
122 0 last; # fail safe
123 }
124 }
125 }
126 }
127  
128 0 for my $private_function (@private_functions) {
129 0 my $private_function_name = $private_function->{data};
130 0 ▶ if ($ignores{$private_function_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignores{$private_function_name}) 0 0 0
131 0 next;
132 }
133  
134 0 ▶ unless ($called{$private_function_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($called{$private_function_name}) 0 0 0
135 push @violations, {
136 filename => $file,
137 line => $private_function->{line},
138 0 description => sprintf(DESC, $private_function_name),
139 explanation => EXPL,
140 policy => __PACKAGE__,
141 };
142 }
143 }
144  
145 0 return \@violations;
146 }
147  
148 2 1;
149  
« Perl/Lint/Policy/Subroutines/RequireFinalReturn.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm »