Perl/Lint/Policy/Variables/RequireLocalizedPunctuationVars.pm

filter: Statementstmt 26.6% 29 / 109 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 16.2% 36 / 222 CC 46 SCAR 75.4
CC
46
Cov
14%
evaluate
2162.0
BEGIN
1.0
BEGIN
1.0
CRAP 1876.6
« Perl/Lint/Policy/RegularExpressions/RequireExtendedFormatting.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitComplexVersion.pm »
1 package Perl::Lint::Policy::Variables::RequireLocalizedPunctuationVars;
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 B::Keywords;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use List::MoreUtils qw/apply uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 DESC => 'Magic variable "%s" should be assigned as "local"',
11 EXPL => [81, 82],
12 2 };
13  
14 2 my %var_token_types = (
15 &VAR => 1,
16 &ARRAY_VAR => 1,
17 &HASH_VAR => 1,
18 &GLOBAL_VAR => 1,
19 &GLOBAL_ARRAY_VAR => 1,
20 &GLOBAL_HASH_VAR => 1,
21  
22 &PROGRAM_ARGUMENT => 1,
23 &LIBRARY_DIRECTORIES => 1,
24 &INCLUDE => 1,
25 &ENVIRONMENT => 1,
26 &SIGNAL => 1,
27 &SPECIFIC_VALUE => 1,
28 &ARRAY_SIZE => 1,
29 );
30  
31 2 my @globals = (
32 @B::Keywords::Arrays,
33 @B::Keywords::Hashes,
34 @B::Keywords::Scalars,
35 );
36 2 push @globals, map { "*$_" } grep { substr($_, 0, 1) ne '*' } @B::Keywords::Filehandles;
37 2 my %globals = map { $_ => 1 } @globals;
38  
39 0 ▶sub evaluate {
Subroutine evaluate: not called CC=46 SCAR=76.8
Pod undocumented
40 0 my ($class, $file, $tokens, $src, $args) = @_;
41  
42 0 my @exemptions = qw/$_ $ARG @_/;
43 0 ▶ if (my $this_policies_arg = $args->{require_localized_punctuation_vars}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"require_localized_punctuation_vars"}) 0 0 0
44 0 ▶ push @exemptions, split(/\s+/, $this_policies_arg->{allow} || '');
Condition0%0/2
$this_policies_arg->{'allow'} || ''
l!l
00
MC/DC0%0/1
$this_policies_arg->{'allow'} || ''
$this_policies_arg->{'allow'}
Truth table0%0/2
A
A= $this_policies_arg->{'allow'}
Aresult
11
00
45 }
46 0 my %exemptions = map { $_ => 1 } @exemptions;
47  
48 0 my @violations;
49 0 ▶ for (my $i = 0, my $token_type, my $variable; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
50 0 $token_type = $token->{type};
51  
52 0 ▶ if ($token_type == LOCAL_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 90) 0 0 0
53 0 $token = $tokens->[++$i];
54  
55 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
56 0 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 0 0 0
57 0 my $lpnum = 1;
58 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
59 0 $token_type = $token->{type};
60  
61 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
62 0 $lpnum++;
63 }
64 elsif ($token_type == RIGHT_PAREN) {
65 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
66 }
67 }
68 }
69  
70 0 next;
71 }
72  
73 0 $variable = $token->{data};
74 0 ▶ if ($token_type == MOD) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 5) { } 0 0 0
elsif ($token_type == 137) { } 0 0 0
elsif ($token_type == 11) { } 0 0 0
75 0 $token = $tokens->[++$i];
76 0 $token_type = $token->{type};
77  
78 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
79 0 ▶ if ($token_type == NOT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 68) { } 0 0 0
elsif ($token_type == 17) { } 0 0 0
80 0 $variable .= $token->{data};
81 0 $token_type = VAR; # XXX
82 }
83 elsif ($token_type == BIT_XOR) {
84 0 $variable .= $token->{data};
85  
86 0 $token = $tokens->[++$i];
87 0 $token_type = $token->{type};
88  
89 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
90  
91 0 ▶ if ($token_type == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 122) 0 0 0
92 0 $variable .= $token->{data};
93 0 $token_type = VAR; # XXX
94 }
95 }
96 }
97 elsif ($token_type == SPECIFIC_VALUE) {
98 0 $token = $tokens->[$i+1];
99 0 ▶ next if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
100  
101 0 ▶ if ($token->{type} == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 122) 0 0 0
102 0 $i++;
103 0 $variable .= $token->{data};
104 0 $token_type = SPECIFIC_VALUE;
105 }
106 }
107 elsif ($token_type == GLOB) {
108 0 $token = $tokens->[++$i];
109  
110 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
111 0 $token_type = $token->{type};
112 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 122 or $token_type == 79 or $token_type == 80 or $token_type == 81) 0 0 0
Condition0%0/9
$token_type == 122 or $token_type == 79 or $token_type == 80 or $token_type == 81
l!l&&r!l&&!r
000
$token_type == 122 or $token_type == 79 or $token_type == 80
l!l&&r!l&&!r
000
$token_type == 122 or $token_type == 79
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 122 or $token_type == 79 or $token_type == 80 or $token_type == 81
$token_type == 122 $token_type == 79 $token_type == 80 $token_type == 81
Truth table0%0/5
A or B or C or D
A= $token_type == 122B= $token_type == 79C= $token_type == 80D= $token_type == 81
ABCDresult
1XXX1
01XX1
001X1
00011
00000
113 $token_type == KEY ||
114 $token_type == TYPE_STDIN ||
115 $token_type == TYPE_STDOUT ||
116 $token_type == TYPE_STDERR
117 ) {
118 0 $variable .= $token->{data};
119 0 $token_type = VAR; # XXX
120 }
121 } ## fall through
122  
123 0 ▶ if ($var_token_types{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_token_types{$token_type}) 0 0 0
124 0 my $line = $token->{line};
125  
126 0 my $before_token = $tokens->[$i-1];
127 0 ▶ if ($before_token && $before_token->{type} == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before_token and $before_token->{"type"} == 65) 0 0 0
Condition0%0/3
$before_token and $before_token->{"type"} == 65
!ll&&!rl&&r
000
MC/DC0%0/2
$before_token and $before_token->{"type"} == 65
$before_token $before_token->{"type"} == 65
Truth table0%0/3
A and B
A= $before_tokenB= $before_token->{"type"} == 65
ABresult
0X0
100
111
128 0 next;
129 }
130  
131 0 $token = $tokens->[++$i];
132 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
133 0 $token_type = $token->{type};
134  
135 0 ▶ if ($token_type == LEFT_BRACKET) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 111) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
136 0 my $lbnum = 1;
137 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
138 0 $token_type = $token->{type};
139 0 ▶ if ($token_type == LEFT_BRACKET) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 111) { } 0 0 0
elsif ($token_type == 112) { } 0 0 0
140 0 $lbnum++;
141 }
142 elsif ($token_type == RIGHT_BRACKET) {
143 0 ▶ last if --$lbnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lbnum <= 0 0 0 0
144 }
145 }
146 0 $token = $tokens->[++$i];
147  
148 0 substr($variable, 0, 1) = '@';
149 }
150 elsif ($token_type == LEFT_BRACE) {
151 0 my $lbnum = 1;
152 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
153 0 $token_type = $token->{type};
154 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
155 0 $lbnum++;
156 }
157 elsif ($token_type == RIGHT_BRACE) {
158 0 ▶ last if --$lbnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lbnum <= 0 0 0 0
159 }
160 }
161 0 $token = $tokens->[++$i];
162  
163 0 substr($variable, 0, 1) = '%';
164 }
165  
166 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
167  
168 0 ▶ if ($token->{type} == RIGHT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 108) 0 0 0
169 0 $token = $tokens->[++$i];
170 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
171 }
172  
173 0 ▶ next if $token->{type} != ASSIGN;
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"type"} != 65 0 0 0
174  
175 0 ▶ if ($globals{$variable} && !$exemptions{$variable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($globals{$variable} and not $exemptions{$variable}) 0 0 0
Condition0%0/3
$globals{$variable} and not $exemptions{$variable}
!ll&&!rl&&r
000
MC/DC0%0/2
$globals{$variable} and not $exemptions{$variable}
$globals{$variable} not $exemptions{$variable}
Truth table0%0/3
A and not(B)
A= $globals{$variable}B= not $exemptions{$variable}
ABresult
0X0
100
111
176 0 push @violations, {
177 filename => $file,
178 line => $line,
179 description => DESC,
180 explanation => EXPL,
181 policy => __PACKAGE__,
182 };
183 }
184 }
185 }
186  
187 0 return \@violations;
188 }
189  
190 2 1;
191  
« Perl/Lint/Policy/RegularExpressions/RequireExtendedFormatting.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitComplexVersion.pm »