Perl/Lint/Policy/Variables/ProhibitLocalVars.pm

filter: Statementstmt 50.0% 22 / 44 Branchbran 10.7% 3 / 28 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 33.7% 31 / 92 CC 18 SCAR 51.7
CC
18
Cov
31%
evaluate
223.6
BEGIN
1.0
BEGIN
1.0
CRAP 175.2
« Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm »
1 package Perl::Lint::Policy::Variables::ProhibitLocalVars;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 DESC => 'The names of or patterns for variables to forbid',
9 EXPL => 'Find an alternative variable',
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=18 SCAR=54.1
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my @violations;
16 2 ▶ for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
17 51 $token_type = $token->{type};
18  
19 51 ▶ if ($token_type == LOCAL_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 90) 0 51 51
20 0 $token = $tokens->[++$i];
21 0 $token_type = $token->{type};
22  
23 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 194 or $token_type == 166) { } 0 0 0
24 0 my $violation;
25 0 my $left_paren_num = 1;
26 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
27 0 $token_type = $token->{type};
28 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 194 or $token_type == 166) { } 0 0 0
29 0 $left_paren_num++;
30 }
31 elsif ($token_type == RIGHT_PAREN) {
32 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
33 0 ▶ if ($violation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($violation) 0 0 0
34 0 push @violations, $violation;
35 0 undef $violation;
36 }
37 0 last;
38 }
39 }
40 ▶ elsif ($token_type == GLOBAL_VAR || $token_type == VAR) {
Condition0%0/3
$token_type == 194 or $token_type == 166
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 194 or $token_type == 166
$token_type == 194 $token_type == 166
Truth table0%0/3
A or B
A= $token_type == 194B= $token_type == 166
ABresult
1X1
011
000
41 0 ▶ if ($token->{data} !~ /\A\$[A-Z_]+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->{"data"} =~ /\A\$[A-Z_]+\Z/) 0 0 0
42 0 my $next_token = $tokens->[$i+1];
43 0 ▶ if ($next_token->{type} != NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} != 126) 0 0 0
44 $violation ||= +{
45 filename => $file,
46 line => $token->{line},
47 0 ▶ description => DESC,
Condition0%0/2
$violation ||= {"filename", $file, "line", $token->{"line"}, "description", "The names of or patterns for variables to forbid", "explanation", "Find an alternative variable", "policy", __PACKAGE__}
l!l
00
MC/DC0%0/1
$violation ||= {"filename", $file, "line", $token->{"line"}, "description", "The names of or patterns for variables to forbid", "explanation", "Find an alternative variable", "policy", __PACKAGE__}
$violation
Truth table0%0/2
A
A= $violation
Aresult
11
00
48 explanation => EXPL,
49 policy => __PACKAGE__,
50 };
51 }
52 }
53 }
54 }
55 }
56 ▶ elsif ($token_type == GLOBAL_VAR || $token_type == VAR) {
Condition0%0/3
$token_type == 194 or $token_type == 166
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 194 or $token_type == 166
$token_type == 194 $token_type == 166
Truth table0%0/3
A or B
A= $token_type == 194B= $token_type == 166
ABresult
1X1
011
000
57 0 ▶ if ($token->{data} !~ /\A\$[A-Z_]+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->{"data"} =~ /\A\$[A-Z_]+\Z/) 0 0 0
58 0 my $next_token = $tokens->[$i+1];
59 0 ▶ if ($next_token->{type} != NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} != 126) 0 0 0
60 push @violations, {
61 filename => $file,
62 line => $token->{line},
63 0 description => DESC,
64 explanation => EXPL,
65 policy => __PACKAGE__,
66 };
67 }
68 }
69 }
70 }
71 }
72  
73 2 return \@violations;
74 }
75  
76 3 1;
77  
« Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm »