Perl/Lint/Policy/NamingConventions/Capitalization.pm

filter: Statementstmt 31.5% 82 / 260 Branchbran 18.0% 31 / 172 Conditioncond 11.6% 7 / 60 MC/DCmcdc 0.0% 0 / 36 Subroutinesub 66.6% 10 / 15 Podpod 0.0% 0 / 1 totaltotal 23.9% 130 / 544 CC 116 SCAR 85.8
CC
116
Cov
24%
evaluate
6411.9
_choose_condition_dispenser
20.7
_is_singlecase
2.3
CRAP 5328.2
« Perl/Lint/Policy/Variables/ProhibitPackageVars.pm ↑ Summary Perl/Lint/Policy/ErrorHandling/RequireCheckingReturnValueOfEval.pm »
1 package Perl::Lint::Policy::NamingConventions::Capitalization;
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 B::Keywords;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use String::CamelCase qw/wordsplit/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # TODO integrate error messages
10  
11 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 EXPL => [45, 46],
13 3 };
14  
15 3 my %local_var_declare_token_types = (
16 &VAR_DECL => 1,
17 &STATE_DECL => 1,
18 );
19  
20 3 my %global_var_declare_token_types = (
21 &OUR_DECL => 1,
22 &LOCAL_DECL => 1,
23 );
24  
25 3 my %var_declare_token_types = (
26 %local_var_declare_token_types,
27 %global_var_declare_token_types,
28 );
29  
30 3 my %var_token_types = (
31 &VAR => 1,
32 &CODE_VAR => 1,
33 &ARRAY_VAR => 1,
34 &HASH_VAR => 1,
35 &GLOBAL_VAR => 1,
36 &GLOBAL_ARRAY_VAR => 1,
37 &GLOBAL_HASH_VAR => 1,
38 &LOCAL_VAR => 1,
39 &LOCAL_ARRAY_VAR => 1,
40 &LOCAL_HASH_VAR => 1,
41 );
42  
43 3 my %globals = map {$_ => 1} ( # TODO integrate?
44 @B::Keywords::Arrays,
45 @B::Keywords::Hashes,
46 @B::Keywords::Scalars,
47 );
48  
49 2 ▶sub evaluate {
Subroutine evaluate: called CC=108 SCAR=87.7
Pod undocumented
50 2 my ($class, $file, $tokens, $src, $args) = @_;
51  
52 2 my $packages_rule = '';
53 2 my $package_exemptions = '';
54  
55 2 my $subroutines_rule = '';
56 2 my $subroutine_exemptions = '';
57  
58 2 my $local_lexical_variables_rule = '';
59 2 my $local_lexical_variable_exemptions = '';
60  
61 2 my $global_variables_rule = '';
62 2 my $global_variable_exemptions = '';
63  
64 2 my $labels_rule = '';
65 2 my $label_exemptions = '';
66  
67 2 ▶ if (my $this_policies_rule = $args->{capitalization}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_rule = $args->{"capitalization"}) 0 2 2
68 0 ▶ $packages_rule = $this_policies_rule->{packages} || '';
Condition0%0/2
$this_policies_rule->{'packages'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'packages'} || ''
$this_policies_rule->{'packages'}
Truth table0%0/2
A
A= $this_policies_rule->{'packages'}
Aresult
11
00
69 0 ▶ $package_exemptions = $this_policies_rule->{package_exemptions} || '';
Condition0%0/2
$this_policies_rule->{'package_exemptions'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'package_exemptions'} || ''
$this_policies_rule->{'package_exemptions'}
Truth table0%0/2
A
A= $this_policies_rule->{'package_exemptions'}
Aresult
11
00
70  
71 0 ▶ $subroutines_rule = $this_policies_rule->{subroutines} || '';
Condition0%0/2
$this_policies_rule->{'subroutines'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'subroutines'} || ''
$this_policies_rule->{'subroutines'}
Truth table0%0/2
A
A= $this_policies_rule->{'subroutines'}
Aresult
11
00
72 0 ▶ $subroutine_exemptions = $this_policies_rule->{subroutine_exemptions} || '';
Condition0%0/2
$this_policies_rule->{'subroutine_exemptions'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'subroutine_exemptions'} || ''
$this_policies_rule->{'subroutine_exemptions'}
Truth table0%0/2
A
A= $this_policies_rule->{'subroutine_exemptions'}
Aresult
11
00
73  
74 0 ▶ $local_lexical_variables_rule = $this_policies_rule->{local_lexical_variables} || '';
Condition0%0/2
$this_policies_rule->{'local_lexical_variables'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'local_lexical_variables'} || ''
$this_policies_rule->{'local_lexical_variables'}
Truth table0%0/2
A
A= $this_policies_rule->{'local_lexical_variables'}
Aresult
11
00
75 0 ▶ $local_lexical_variable_exemptions = $this_policies_rule->{local_lexical_variable_exemptions} || '';
Condition0%0/2
$this_policies_rule->{'local_lexical_variable_exemptions'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'local_lexical_variable_exemptions'} || ''
$this_policies_rule->{'local_lexical_variable_exemptions'}
Truth table0%0/2
A
A= $this_policies_rule->{'local_lexical_variable_exemptions'}
Aresult
11
00
76  
77 0 ▶ $global_variables_rule = $this_policies_rule->{global_variables} || '';
Condition0%0/2
$this_policies_rule->{'global_variables'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'global_variables'} || ''
$this_policies_rule->{'global_variables'}
Truth table0%0/2
A
A= $this_policies_rule->{'global_variables'}
Aresult
11
00
78 0 ▶ $global_variable_exemptions = $this_policies_rule->{global_variable_exemptions} || '';
Condition0%0/2
$this_policies_rule->{'global_variable_exemptions'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'global_variable_exemptions'} || ''
$this_policies_rule->{'global_variable_exemptions'}
Truth table0%0/2
A
A= $this_policies_rule->{'global_variable_exemptions'}
Aresult
11
00
79  
80 0 ▶ $labels_rule = $this_policies_rule->{labels} || '';
Condition0%0/2
$this_policies_rule->{'labels'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'labels'} || ''
$this_policies_rule->{'labels'}
Truth table0%0/2
A
A= $this_policies_rule->{'labels'}
Aresult
11
00
81 0 ▶ $label_exemptions = $this_policies_rule->{label_exemptions} || '';
Condition0%0/2
$this_policies_rule->{'label_exemptions'} || ''
l!l
00
MC/DC0%0/1
$this_policies_rule->{'label_exemptions'} || ''
$this_policies_rule->{'label_exemptions'}
Truth table0%0/2
A
A= $this_policies_rule->{'label_exemptions'}
Aresult
11
00
82 }
83  
84 2 my @violations;
85  
86 2 ▶ TOP: for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 42 2 44
87 42 $token_type = $token->{type};
88 42 $token_data = $token->{data};
89  
90 # for variables name
91 42 ▶ if ($var_declare_token_types{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_declare_token_types{$token_type}) 1 41 42
92 1 my $exemptions;
93 1 my $is_global_var = 0;
94  
95 1 my $checker = \&_is_singlecase;
96 1 my $error_message = '"%s" is not all lower case or all upper case';
97  
98 1 ▶ if ($local_var_declare_token_types{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_var_declare_token_types{$token_type}) { } 1 0 1
99 1 ▶ if (my $condition = $class->_choose_condition_dispenser($local_lexical_variables_rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $condition = $class->_choose_condition_dispenser($local_lexical_variables_rule)) 0 1 1
100 0 $checker = $condition->{checker};
101 0 $error_message = $condition->{error_message};
102 }
103 1 $exemptions = $local_lexical_variable_exemptions;
104 }
105 else {
106 0 ▶ if (my $condition = $class->_choose_condition_dispenser($global_variables_rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $condition = $class->_choose_condition_dispenser($global_variables_rule)) 0 0 0
107 0 $checker = $condition->{checker};
108 0 $error_message = $condition->{error_message};
109 }
110 0 $exemptions = $global_variable_exemptions;
111 0 $is_global_var = 1;
112 }
113  
114 1 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 1 0 1
115 1 $token_type = $token->{type};
116  
117 # when multiple variables declared
118 1 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 1 1
119 0 my $lpnum = 1;
120 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
121 0 $token_type = $token->{type};
122 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 ($var_token_types{$token_type}) { } 0 0 0
123 0 $lpnum++;
124 }
125 elsif ($token_type == RIGHT_PAREN) {
126 0 ▶ last if --$lpnum <= 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
127 }
128 elsif ($var_token_types{$token_type}) {
129 # To ignore variables from other packages
130 # TODO
131 0 ▶ my $next_token = $tokens->[$i+1] || {};
Condition0%0/2
$$tokens[$i + 1] || {}
l!l
00
MC/DC0%0/1
$$tokens[$i + 1] || {}
$$tokens[$i + 1]
Truth table0%0/2
A
A= $$tokens[$i + 1]
Aresult
11
00
132 0 ▶ if ($next_token->{type} && $next_token->{type} == NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} and $next_token->{"type"} == 126) 0 0 0
Condition0%0/3
$next_token->{"type"} and $next_token->{"type"} == 126
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token->{"type"} and $next_token->{"type"} == 126
$next_token->{"type"} $next_token->{"type"} == 126
Truth table0%0/3
A and B
A= $next_token->{"type"}B= $next_token->{"type"} == 126
ABresult
0X0
100
111
133 0 next;
134 }
135  
136 0 $token_data = $token->{data};
137  
138 0 ▶ if ($is_global_var && $globals{$token_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global_var and $globals{$token_data}) 0 0 0
Condition0%0/3
$is_global_var and $globals{$token_data}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_global_var and $globals{$token_data}
$is_global_var $globals{$token_data}
Truth table0%0/3
A and B
A= $is_global_varB= $globals{$token_data}
ABresult
0X0
100
111
139 0 next;
140 }
141  
142 0 $token_data = substr($token_data, 1); # to exclude sigils
143  
144 0 ▶ if ($token_data =~ /\A$exemptions\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$exemptions\Z/) 0 0 0
145 0 next;
146 }
147  
148 0 ▶ if (ref $checker ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $checker ne "CODE") 0 0 0
149 0 ▶ if ($token_data =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$checker\Z/) 0 0 0
150 0 next;
151 }
152  
153 push @violations, {
154 filename => $file,
155 line => $token->{line},
156 0 description => sprintf($error_message, $token_data),
157 explanation => EXPL,
158 policy => __PACKAGE__,
159 };
160 0 next;
161 }
162  
163 0 for my $part (wordsplit($token_data)) {
164 0 ▶ if (!$checker->($part)) { # include Upper Case
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($part)) 0 0 0
165 push @violations, {
166 filename => $file,
167 line => $token->{line},
168 0 description => sprintf($error_message, $token_data),
169 explanation => EXPL,
170 policy => __PACKAGE__,
171 };
172 0 last;
173 }
174 }
175 }
176 }
177  
178 0 next;
179 }
180  
181 # To ignore variables from other packages
182 # TODO
183 1 ▶ my $next_token = $tokens->[$i+1] || {};
Condition50%1/2
$$tokens[$i + 1] || {}
l!l
10
MC/DC0%0/1
$$tokens[$i + 1] || {}
$$tokens[$i + 1]
Truth table50%1/2
A
A= $$tokens[$i + 1]
Aresult
11
00
184 1 ▶ if ($next_token->{type} && $next_token->{type} == NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} and $next_token->{"type"} == 126) 0 1 1
Condition33%1/3
$next_token->{"type"} and $next_token->{"type"} == 126
!ll&&!rl&&r
010
MC/DC0%0/2
$next_token->{"type"} and $next_token->{"type"} == 126
$next_token->{"type"} $next_token->{"type"} == 126
Truth table33%1/3
A and B
A= $next_token->{"type"}B= $next_token->{"type"} == 126
ABresult
0X0
100
111
185 0 next;
186 }
187  
188 1 $token_data = $token->{data};
189  
190 1 ▶ if ($is_global_var && $globals{$token_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_global_var and $globals{$token_data}) 0 1 1
Condition33%1/3
$is_global_var and $globals{$token_data}
!ll&&!rl&&r
100
MC/DC0%0/2
$is_global_var and $globals{$token_data}
$is_global_var $globals{$token_data}
Truth table33%1/3
A and B
A= $is_global_varB= $globals{$token_data}
ABresult
0X0
100
111
191 0 next;
192 }
193  
194 1 $token_data = substr($token_data, 1); # to exclude sigils
195  
196 1 ▶ if ($token_data =~ /\A$exemptions\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$exemptions\Z/) 0 1 1
197 0 next;
198 }
199  
200 1 ▶ if (ref $checker ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $checker ne "CODE") 0 1 1
201 0 ▶ if ($token_data =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$checker\Z/) 0 0 0
202 0 next;
203 }
204  
205 push @violations, {
206 filename => $file,
207 line => $token->{line},
208 0 description => sprintf($error_message, $token_data),
209 explanation => EXPL,
210 policy => __PACKAGE__,
211 };
212 0 next;
213 }
214  
215 1 for my $part (wordsplit($token_data)) {
216 1 ▶ if (!$checker->($part)) { # include Upper Case
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($part)) 0 1 1
217 push @violations, {
218 filename => $file,
219 line => $token->{line},
220 0 description => sprintf($error_message, $token_data),
221 explanation => EXPL,
222 policy => __PACKAGE__,
223 };
224 0 last;
225 }
226 }
227 1 next;
228 }
229  
230 # for subroutines name
231 41 ▶ if ($token_type == FUNCTION_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 63) 0 41 41
232 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
233 0 $token_type = $token->{type};
234  
235 0 ▶ if ($token_type == NAMESPACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 127) { } 0 0 0
elsif ($token_type != 203) { } 0 0 0
236 0 my $last_namespace_token;
237  
238 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
239 0 $token_type = $token->{type};
240  
241 0 ▶ if ($token_type == NAMESPACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 127) { } 0 0 0
elsif ($token_type != 126) { } 0 0 0
242 0 $last_namespace_token = $token;
243 }
244 elsif ($token_type != NAMESPACE_RESOLVER) {
245 0 last;
246 }
247 }
248  
249 0 $token = $last_namespace_token;
250 }
251 elsif ($token_type != FUNCTION) {
252 0 next;
253 }
254  
255 0 my $checker = \&_is_started_with_lower;
256 0 my $error_message = '"%s" does not start with a lower case letter';
257 0 ▶ if (my $condition = $class->_choose_condition_dispenser($subroutines_rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $condition = $class->_choose_condition_dispenser($subroutines_rule)) 0 0 0
258 0 $checker = $condition->{checker};
259 0 $error_message = $condition->{error_message};
260 }
261  
262 0 $token_data = $token->{data};
263  
264 0 ▶ if ($token_data =~ /\A$subroutine_exemptions\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$subroutine_exemptions\Z/) 0 0 0
265 0 next;
266 }
267  
268 0 ▶ if (ref $checker ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $checker ne "CODE") 0 0 0
269 0 ▶ if ($token_data =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$checker\Z/) 0 0 0
270 0 next;
271 }
272  
273 push @violations, {
274 filename => $file,
275 line => $token->{line},
276 0 description => sprintf($error_message, $token_data),
277 explanation => EXPL,
278 policy => __PACKAGE__,
279 };
280 0 next;
281 }
282  
283 0 for my $part (wordsplit($token_data)) { # to exclude sigils
284 0 ▶ if (!$checker->($part)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($part)) 0 0 0
285 push @violations, {
286 filename => $file,
287 line => $token->{line},
288 0 description => sprintf($error_message, $token_data),
289 explanation => EXPL,
290 policy => __PACKAGE__,
291 };
292 0 last;
293 }
294 }
295  
296 0 next;
297 }
298  
299 # for package's name
300 41 ▶ if ($token_type == PACKAGE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 128) 0 41 41
301 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
302 0 $token_type = $token->{type};
303 0 $token_data = $token->{data};
304  
305 # special case: main
306 0 ▶ if ($token_type == CLASS && $token_data eq 'main') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 129 and $token_data eq "main") 0 0 0
Condition0%0/3
$token_type == 129 and $token_data eq "main"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 129 and $token_data eq "main"
$token_type == 129 $token_data eq "main"
Truth table0%0/3
A and B
A= $token_type == 129B= $token_data eq "main"
ABresult
0X0
100
111
307 0 next;
308 }
309  
310 0 ▶ if ($package_exemptions && $token_data =~ /\A$package_exemptions\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_exemptions and $token_data =~ /\A$package_exemptions\Z/) 0 0 0
Condition0%0/3
$package_exemptions and $token_data =~ /\A$package_exemptions\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
$package_exemptions and $token_data =~ /\A$package_exemptions\Z/
$package_exemptions $token_data =~ /\A$package_exemptions\Z/
Truth table0%0/3
A and B
A= $package_exemptionsB= $token_data =~ /\A$package_exemptions\Z/
ABresult
0X0
100
111
311 0 next;
312 }
313  
314 0 my $checker = \&_is_started_with_upper;
315 0 my $error_message = '"%s" does not start with a upper case letter';
316 0 ▶ if (my $condition = $class->_choose_condition_dispenser($packages_rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $condition = $class->_choose_condition_dispenser($packages_rule)) 0 0 0
317 0 $checker = $condition->{checker};
318 0 $error_message = $condition->{error_message};
319 }
320  
321 0 my $package_full_name = $token_data;
322 0 ▶ if (ref $checker eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $checker eq 'CODE') { } 0 0 0
elsif ($token_type == 129) { } 0 0 0
323 0 for my $part (wordsplit($token_data)) {
324 0 ▶ if (!$checker->($part)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($part)) 0 0 0
325 push @violations, {
326 filename => $file,
327 line => $token->{line},
328 0 description => sprintf($error_message, $token_data),
329 explanation => EXPL,
330 policy => __PACKAGE__,
331 };
332  
333 0 next TOP;
334 }
335 }
336 }
337 elsif ($token_type == CLASS) {
338 0 ▶ if ($package_full_name =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_full_name =~ /\A$checker\Z/) 0 0 0
339 0 next;
340 }
341  
342 push @violations, {
343 filename => $file,
344 line => $token->{line},
345 0 description => sprintf($error_message, $token_data),
346 explanation => EXPL,
347 policy => __PACKAGE__,
348 };
349 0 next;
350 }
351  
352 0 ▶ if ($token_type == NAMESPACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127) 0 0 0
353 0 ▶ if (ref $checker ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $checker ne "CODE") 0 0 0
354 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) { # TODO
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
355 0 $token_type = $token->{type};
356 0 $token_data = $token->{data};
357 0 ▶ if ($token_type == NAMESPACE || $token_type == NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127 or $token_type == 126) { } 0 0 0
Condition0%0/3
$token_type == 127 or $token_type == 126
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 127 or $token_type == 126
$token_type == 127 $token_type == 126
Truth table0%0/3
A or B
A= $token_type == 127B= $token_type == 126
ABresult
1X1
011
000
358 0 $package_full_name .= $token_data;
359 }
360 else {
361 0 last;
362 }
363 }
364 0 ▶ if ($package_full_name =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_full_name =~ /\A$checker\Z/) 0 0 0
365 0 next;
366 }
367  
368 push @violations, {
369 filename => $file,
370 line => $token->{line},
371 0 description => sprintf($error_message, $token_data),
372 explanation => EXPL,
373 policy => __PACKAGE__,
374 };
375 0 next;
376 }
377  
378 0 ▶ SCAN_NAMESPACE: for ($i++; $token = $tokens->[$i]; $i++) { # TODO
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
379 0 $token_type = $token->{type};
380 0 $token_data = $token->{data};
381 0 ▶ if ($token_type == NAMESPACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 127) { } 0 0 0
elsif ($token_type != 126) { } 0 0 0
382 0 for my $part (wordsplit($token_data)) {
383 0 ▶ if (!$checker->($part)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($part)) 0 0 0
384 push @violations, {
385 filename => $file,
386 line => $token->{line},
387 0 description => sprintf($error_message, $token_data),
388 explanation => EXPL,
389 policy => __PACKAGE__,
390 };
391 0 last SCAN_NAMESPACE;
392 }
393 }
394 }
395 elsif ($token_type != NAMESPACE_RESOLVER) {
396 0 last;
397 }
398 }
399 }
400  
401 0 next;
402 }
403  
404 # for constant variables
405 # * Readonly::Scalar
406 # * const (From Const::Fast)
407 {
408 41 my $is_const_decl = 0;
409 41 ▶ if ($token_type == NAMESPACE && $token_data eq 'Readonly') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 127 and $token_data eq 'Readonly') { } 0 41 41
elsif ($token_type == 122 and $token_data eq 'const') { } 0 82 82
Condition33%1/3
$token_type == 127 and $token_data eq "Readonly"
!ll&&!rl&&r
4100
MC/DC0%0/2
$token_type == 127 and $token_data eq "Readonly"
$token_type == 127 $token_data eq "Readonly"
Truth table33%1/3
A and B
A= $token_type == 127B= $token_data eq "Readonly"
ABresult
0X0
100
111
410 0 $i += 2;
411 0 ▶ $token = $tokens->[$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $tokens->[$i] or last 0 0 0
412 0 ▶ if ($token->{type} == NAMESPACE && $token->{data} eq 'Scalar') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 127 and $token->{"data"} eq "Scalar") 0 0 0
Condition0%0/3
$token->{"type"} == 127 and $token->{"data"} eq "Scalar"
!ll&&!rl&&r
000
MC/DC0%0/2
$token->{"type"} == 127 and $token->{"data"} eq "Scalar"
$token->{"type"} == 127 $token->{"data"} eq "Scalar"
Truth table0%0/3
A and B
A= $token->{"type"} == 127B= $token->{"data"} eq "Scalar"
ABresult
0X0
100
111
413 0 $is_const_decl = 1;
414 }
415 }
416 ▶ elsif ($token_type == KEY && $token_data eq 'const') {
Condition33%1/3
$token_type == 122 and $token_data eq "const"
!ll&&!rl&&r
4100
MC/DC0%0/2
$token_type == 122 and $token_data eq "const"
$token_type == 122 $token_data eq "const"
Truth table33%1/3
A and B
A= $token_type == 122B= $token_data eq "const"
ABresult
0X0
100
111
417 0 $is_const_decl = 1;
418 }
419  
420 41 ▶ if ($is_const_decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_const_decl) 0 41 41
421 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
422 0 ▶ if (!$var_token_types{$token->{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($var_token_types{$token->{"type"}}) 0 0 0
423 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
424 }
425  
426 0 ▶ if ($var_token_types{$token->{type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_token_types{$token->{"type"}}) 0 0 0
427 0 $token_data = $token->{data};
428 0 ▶ if (uc $token_data ne $token_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $token_data ne $token_data) 0 0 0
429 push @violations, {
430 filename => $file,
431 line => $token->{line},
432 0 description => sprintf('"%s" is not all upper case', $token_data),
433 explanation => EXPL,
434 policy => __PACKAGE__,
435 };
436 }
437 }
438  
439 0 next;
440 }
441 }
442  
443 # for constants
444 # * use constant
445 41 ▶ if ($token_type == USE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 93) 8 33 41
446 8 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 8 0 8
447 8 ▶ if ($token->{type} != USED_NAME || $token->{data} ne 'constant') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} != 94 or $token->{"data"} ne "constant") 8 0 8
Condition33%1/3
$token->{"type"} != 94 or $token->{"data"} ne "constant"
l!l&&r!l&&!r
080
MC/DC0%0/2
$token->{"type"} != 94 or $token->{"data"} ne "constant"
$token->{"type"} != 94 $token->{"data"} ne "constant"
Truth table33%1/3
A or B
A= $token->{"type"} != 94B= $token->{"data"} ne "constant"
ABresult
1X1
011
000
448 8 next;
449 }
450  
451 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
452 0 ▶ if ($token->{type} != ARROW) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} != 124) 0 0 0
453 0 next;
454 }
455  
456 0 my $key = $tokens->[$i-1]->{data};
457 0 ▶ if (uc $key ne $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $key ne $key) 0 0 0
458 push @violations, {
459 filename => $file,
460 line => $token->{line},
461 0 description => sprintf('"%s" is not all upper case', $key),
462 explanation => EXPL,
463 policy => __PACKAGE__,
464 };
465 }
466 }
467  
468 0 next;
469 }
470  
471 # for LABELs
472 33 ▶ if ($token_type == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 122) 0 33 33
473 0 ▶ my $next_token = $tokens->[$i+1] or last;
Branch: 1 branch
BranchTrueFalseTotal
my $next_token = $$tokens[$i + 1] or last 0 0 0
474 0 ▶ if ($next_token->{type} != COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} != 105) 0 0 0
475 0 next;
476 }
477  
478 0 ▶ if ($token_data =~ /\A$label_exemptions\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$label_exemptions\Z/) 0 0 0
479 0 next;
480 }
481  
482 0 my $checker = \&_is_all_upper;
483 0 my $error_message = '"%s" is not all upper case';
484 0 ▶ if (my $condition = $class->_choose_condition_dispenser($labels_rule) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $condition = $class->_choose_condition_dispenser($labels_rule)) 0 0 0
485 0 $checker = $condition->{checker};
486 0 $error_message = $condition->{error_message};
487 }
488  
489 0 ▶ if (ref $checker ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $checker ne "CODE") 0 0 0
490 0 ▶ if ($token_data =~ /\A$checker\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A$checker\Z/) 0 0 0
491 0 next;
492 }
493  
494 push @violations, {
495 filename => $file,
496 line => $token->{line},
497 0 description => sprintf($error_message, $token_data),
498 explanation => EXPL,
499 policy => __PACKAGE__,
500 };
501 0 next;
502 }
503  
504 0 ▶ if (!$checker->($token_data)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$checker($token_data)) 0 0 0
505 push @violations, {
506 filename => $file,
507 line => $token->{line},
508 0 description => sprintf($error_message, $token_data),
509 explanation => EXPL,
510 policy => __PACKAGE__,
511 };
512 }
513  
514 0 next;
515 }
516  
517 }
518  
519 2 return \@violations;
520 }
521  
522 1 ▶sub _choose_condition_dispenser {
Subroutine _choose_condition_dispenser: called CC=8 SCAR=30.3
523 1 my ($self, $rule) = @_;
524  
525 1 ▶ if ($rule eq ':single_case') {
Branch: 7 branches
BranchTrueFalseTotal
if ($rule eq ':single_case') { } 0 1 1
elsif ($rule eq ':all_lower') { } 0 1 1
elsif ($rule eq ':all_upper') { } 0 1 1
elsif ($rule eq ':starts_with_lower') { } 0 1 1
elsif ($rule eq ':starts_with_upper') { } 0 1 1
elsif ($rule eq ':no_restriction') { } 0 1 1
elsif ($rule) { } 0 1 1
526 return {
527 0 error_message => '"%s" is not all lower case or all upper case',
528 checker => \&_is_singlecase,
529 };
530 }
531 elsif ($rule eq ':all_lower') {
532 return {
533 0 error_message => '"%s" is not all lower case',
534 checker => \&_is_all_lower,
535 };
536 }
537 elsif ($rule eq ':all_upper') {
538 return {
539 0 error_message => '"%s" is not all upper case',
540 checker => \&_is_all_upper,
541 };
542 }
543 elsif ($rule eq ':starts_with_lower') {
544 return {
545 0 error_message => '"%s" does not start with a lower case letter',
546 checker => \&_is_started_with_lower,
547 };
548 }
549 elsif ($rule eq ':starts_with_upper') {
550 return {
551 0 error_message => '"%s" does not start with a upper case letter',
552 checker => \&_is_started_with_upper,
553 };
554 }
555 elsif ($rule eq ':no_restriction') {
556 return {
557 0 error_message => 'There is a bug in Perl::Critic if you are reading this',
558 checker => \&_everything_will_be_alright,
559 }
560 }
561 elsif ($rule) {
562 return {
563 0 error_message => qq{"%s" is not matched with $rule},
564 checker => $rule, # XXX
565 };
566 }
567  
568 1 return;
569 }
570  
571 0 ▶sub _is_all_lower {
Subroutine _is_all_lower: not called CC=1 SCAR=6.9
572 0 my ($part) = @_;
573 0 return lc($part) eq $part;
574 }
575  
576 0 ▶sub _is_all_upper {
Subroutine _is_all_upper: not called CC=1 SCAR=6.9
577 0 my ($part) = @_;
578 0 return uc($part) eq $part;
579 }
580  
581 1 ▶sub _is_singlecase {
Subroutine _is_singlecase: called CC=2 SCAR=8.1
582 1 my ($part) = @_;
583 1 ▶ return uc($part) eq $part || lc($part) eq $part;
Condition33%1/3
uc $part eq $part || lc $part eq $part
l!l&&r!l&&!r
010
MC/DC0%0/2
uc $part eq $part || lc $part eq $part
uc $part eq $part lc $part eq $part
Truth table33%1/3
A || B
A= uc $part eq $partB= lc $part eq $part
ABresult
1X1
011
000
584 }
585  
586 0 ▶sub _is_started_with_lower {
Subroutine _is_started_with_lower: not called CC=1 SCAR=6.9
587 0 my ($part) = @_;
588 0 return lcfirst($part) eq $part;
589 }
590  
591 0 ▶sub _is_started_with_upper {
Subroutine _is_started_with_upper: not called CC=1 SCAR=6.9
592 0 my ($part) = @_;
593 0 return ucfirst($part) eq $part;
594 }
595  
596 0 ▶sub _everything_will_be_alright {
Subroutine _everything_will_be_alright: not called CC=1 SCAR=6.9
597 0 return 1;
598 }
599  
600 3 1;
601  
« Perl/Lint/Policy/Variables/ProhibitPackageVars.pm ↑ Summary Perl/Lint/Policy/ErrorHandling/RequireCheckingReturnValueOfEval.pm »