lib/Perl/Critic/Utils.pm

filter: Statementstmt 92.6% 363 / 392 Branchbran 66.0% 148 / 224 Conditioncond 60.5% 72 / 119 MC/DCmcdc 31.4% 22 / 70 Subroutinesub 91.1% 62 / 68 Podpod 100% 39 / 39 totaltotal 77.4% 706 / 912 CC 160 SCAR 28.1
CC
160
Cov
79%
is_in_void_context
182.0
is_hash_key
13.5
is_function_call
13.1
CRAP 16.6
« lib/Perl/Critic/Policy/Subroutines/ProtectPrivateSubs.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitLvalueSubstr.pm »
1 # NOTE: This module is way too large. Please think about adding new
2 # functionality into a P::C::Utils::* module instead.
3  
4 package Perl::Critic::Utils;
5  
6 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 ▶use File::Find qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 40 ▶use File::Spec qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 40 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 40 ▶use B::Keywords qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 40 ▶use PPI::Token::Quote::Single;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 40 ▶use List::SomeUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 40 ▶use Perl::Critic::Exception::Fatal::Generic qw{ throw_generic };
Subroutine BEGIN: called CC=1 SCAR=0.0
21 40 ▶use Perl::Critic::Utils::PPI qw< is_ppi_expression_or_generic_statement >;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 40 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 40 our $VERSION = '1.156';
26  
27 #-----------------------------------------------------------------------------
28 # Exportable symbols here.
29  
30 40 Readonly::Array our @EXPORT_OK => qw(
31 $TRUE
32 $FALSE
33  
34 $POLICY_NAMESPACE
35  
36 $SEVERITY_HIGHEST
37 $SEVERITY_HIGH
38 $SEVERITY_MEDIUM
39 $SEVERITY_LOW
40 $SEVERITY_LOWEST
41 @SEVERITY_NAMES
42  
43 $DEFAULT_VERBOSITY
44 $DEFAULT_VERBOSITY_WITH_FILE_NAME
45  
46 $COLON
47 $COMMA
48 $DQUOTE
49 $EMPTY
50 $EQUAL
51 $FATCOMMA
52 $PERIOD
53 $PIPE
54 $QUOTE
55 $BACKTICK
56 $SCOLON
57 $SPACE
58 $SLASH
59 $BSLASH
60 $LEFT_PAREN
61 $RIGHT_PAREN
62  
63 all_perl_files
64 find_keywords
65 first_arg
66 hashify
67 interpolate
68 is_assignment_operator
69 is_class_name
70 is_function_call
71 is_hash_key
72 is_in_void_context
73 is_included_module_name
74 is_integer
75 is_label_pointer
76 is_method_call
77 is_package_declaration
78 is_perl_bareword
79 is_perl_builtin
80 is_perl_builtin_with_list_context
81 is_perl_builtin_with_multiple_arguments
82 is_perl_builtin_with_no_arguments
83 is_perl_builtin_with_one_argument
84 is_perl_builtin_with_optional_argument
85 is_perl_builtin_with_zero_and_or_one_arguments
86 is_perl_filehandle
87 is_perl_global
88 is_qualified_name
89 is_script
90 is_subroutine_name
91 is_unchecked_call
92 is_valid_numeric_verbosity
93 parse_arg_list
94 policy_long_name
95 policy_short_name
96 precedence_of
97 severity_to_number
98 shebang_line
99 split_nodes_on_comma
100 verbosity_to_format
101 words_from_string
102 );
103  
104  
105 # Note: this is deprecated. This should also violate ProhibitAutomaticExportation,
106 # but at the moment, we aren't smart enough to deal with Readonly variables.
107 40 Readonly::Array our @EXPORT => @EXPORT_OK;
108  
109  
110 40 Readonly::Hash our %EXPORT_TAGS => (
111 all => [ @EXPORT_OK ],
112 booleans => [ qw{ $TRUE $FALSE } ],
113 severities => [
114 qw{
115 $SEVERITY_HIGHEST
116 $SEVERITY_HIGH
117 $SEVERITY_MEDIUM
118 $SEVERITY_LOW
119 $SEVERITY_LOWEST
120 @SEVERITY_NAMES
121 }
122 ],
123 characters => [
124 qw{
125 $COLON
126 $COMMA
127 $DQUOTE
128 $EMPTY
129 $EQUAL
130 $FATCOMMA
131 $PERIOD
132 $PIPE
133 $QUOTE
134 $BACKTICK
135 $SCOLON
136 $SPACE
137 $SLASH
138 $BSLASH
139 $LEFT_PAREN
140 $RIGHT_PAREN
141 }
142 ],
143 classification => [
144 qw{
145 is_assignment_operator
146 is_class_name
147 is_function_call
148 is_hash_key
149 is_included_module_name
150 is_integer
151 is_label_pointer
152 is_method_call
153 is_package_declaration
154 is_perl_bareword
155 is_perl_builtin
156 is_perl_filehandle
157 is_perl_global
158 is_perl_builtin_with_list_context
159 is_perl_builtin_with_multiple_arguments
160 is_perl_builtin_with_no_arguments
161 is_perl_builtin_with_one_argument
162 is_perl_builtin_with_optional_argument
163 is_perl_builtin_with_zero_and_or_one_arguments
164 is_qualified_name
165 is_script
166 is_subroutine_name
167 is_unchecked_call
168 is_valid_numeric_verbosity
169 }
170 ],
171 data_conversion => [ qw{ hashify words_from_string interpolate } ],
172 ppi => [ qw{ first_arg parse_arg_list } ],
173 internal_lookup => [ qw{ severity_to_number verbosity_to_format } ],
174 language => [ qw{ precedence_of } ],
175 deprecated => [ qw{ find_keywords } ],
176 );
177  
178 #-----------------------------------------------------------------------------
179  
180 40 Readonly::Scalar our $POLICY_NAMESPACE => 'Perl::Critic::Policy';
181  
182 #-----------------------------------------------------------------------------
183  
184 40 Readonly::Scalar our $SEVERITY_HIGHEST => 5;
185 40 Readonly::Scalar our $SEVERITY_HIGH => 4;
186 40 Readonly::Scalar our $SEVERITY_MEDIUM => 3;
187 40 Readonly::Scalar our $SEVERITY_LOW => 2;
188 40 Readonly::Scalar our $SEVERITY_LOWEST => 1;
189  
190 #-----------------------------------------------------------------------------
191  
192 40 Readonly::Scalar our $COMMA => q{,};
193 40 Readonly::Scalar our $EQUAL => q{=};
194 40 Readonly::Scalar our $FATCOMMA => q{=>};
195 40 Readonly::Scalar our $COLON => q{:};
196 40 Readonly::Scalar our $SCOLON => q{;};
197 40 Readonly::Scalar our $QUOTE => q{'};
198 40 Readonly::Scalar our $DQUOTE => q{"};
199 40 Readonly::Scalar our $BACKTICK => q{`};
200 40 Readonly::Scalar our $PERIOD => q{.};
201 40 Readonly::Scalar our $PIPE => q{|};
202 40 Readonly::Scalar our $SPACE => q{ };
203 40 Readonly::Scalar our $SLASH => q{/};
204 40 Readonly::Scalar our $BSLASH => q{\\};
205 40 Readonly::Scalar our $LEFT_PAREN => q{(};
206 40 Readonly::Scalar our $RIGHT_PAREN => q{)};
207 40 Readonly::Scalar our $EMPTY => q{};
208 40 Readonly::Scalar our $TRUE => 1;
209 40 Readonly::Scalar our $FALSE => 0;
210  
211  
212 #-----------------------------------------------------------------------------
213 ## no critic (ProhibitNoisyQuotes);
214  
215 40 Readonly::Hash my %PRECEDENCE_OF => (
216 '->' => 1,
217 '++' => 2,
218 '--' => 2,
219 '**' => 3,
220 '!' => 4,
221 '~' => 4,
222 '\\' => 4,
223 '=~' => 5,
224 '!~' => 5,
225 '*' => 6,
226 '/' => 6,
227 '%' => 6,
228 'x' => 6,
229 '+' => 7,
230 '-' => 7,
231 '.' => 7,
232 '<<' => 8,
233 '>>' => 8,
234 '-R' => 9,
235 '-W' => 9,
236 '-X' => 9,
237 '-r' => 9,
238 '-w' => 9,
239 '-x' => 9,
240 '-e' => 9,
241 '-O' => 9,
242 '-o' => 9,
243 '-z' => 9,
244 '-s' => 9,
245 '-M' => 9,
246 '-A' => 9,
247 '-C' => 9,
248 '-S' => 9,
249 '-c' => 9,
250 '-b' => 9,
251 '-f' => 9,
252 '-d' => 9,
253 '-p' => 9,
254 '-l' => 9,
255 '-u' => 9,
256 '-g' => 9,
257 '-k' => 9,
258 '-t' => 9,
259 '-T' => 9,
260 '-B' => 9,
261 '<' => 10,
262 '>' => 10,
263 '<=' => 10,
264 '>=' => 10,
265 'lt' => 10,
266 'gt' => 10,
267 'le' => 10,
268 'ge' => 10,
269 '==' => 11,
270 '!=' => 11,
271 '<=>' => 11,
272 'eq' => 11,
273 'ne' => 11,
274 'cmp' => 11,
275 '~~' => 11,
276 '&' => 12,
277 '|' => 13,
278 '^' => 13,
279 '&&' => 14,
280 '//' => 15,
281 '||' => 15,
282 '..' => 16,
283 '...' => 17,
284 '?' => 18,
285 ':' => 18,
286 '=' => 19,
287 '+=' => 19,
288 '-=' => 19,
289 '*=' => 19,
290 '/=' => 19,
291 '%=' => 19,
292 '||=' => 19,
293 '&&=' => 19,
294 '|=' => 19,
295 '&=' => 19,
296 '**=' => 19,
297 'x=' => 19,
298 '.=' => 19,
299 '^=' => 19,
300 '<<=' => 19,
301 '>>=' => 19,
302 '//=' => 19,
303 ',' => 20,
304 '=>' => 20,
305 'not' => 22,
306 'and' => 23,
307 'or' => 24,
308 'xor' => 24,
309 );
310  
311 ## use critic
312  
313 40 Readonly::Scalar my $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST =>
314 precedence_of( 'not' );
315  
316 #-----------------------------------------------------------------------------
317  
318 21119 ▶sub hashify { ## no critic (ArgUnpacking)
Subroutine hashify: called CC=1 SCAR=0.0
Pod documented
319 21119 return map { $_ => 1 } @_;
320 }
321  
322 #-----------------------------------------------------------------------------
323  
324 539 ▶sub interpolate {
Subroutine interpolate: called CC=2 SCAR=7.2
Pod documented
325 539 my ( $literal ) = @_;
326 539 ▶ return eval "\"$literal\"" || confess $EVAL_ERROR; ## no critic (StringyEval);
Condition50%1/2
eval qq["$literal"] || confess($Perl::Critic::Utils::EVAL_ERROR)
l!l
5390
MC/DC0%0/1
eval qq["$literal"] || confess($Perl::Critic::Utils::EVAL_ERROR)
eval qq["$literal"]
Truth table50%1/2
A
A= eval qq["$literal"]
Aresult
11
00
327 }
328  
329 #-----------------------------------------------------------------------------
330  
331 5 ▶sub find_keywords {
Subroutine find_keywords: called CC=3 SCAR=11.0
Pod documented
332 5 my ( $doc, $keyword ) = @_;
333 5 my $nodes_ref = $doc->find('PPI::Token::Word');
334 5 ▶ return if !$nodes_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $nodes_ref 1 4 5
335 4 my @matches = grep { $_ eq $keyword } @{$nodes_ref};
336 4 ▶ return @matches ? \@matches : undef;
Branch: 1 branch
BranchTrueFalseTotal
@matches ? : 3 1 4
337 }
338  
339 #-----------------------------------------------------------------------------
340  
341 1007 ▶sub _name_for_sub_or_stringified_element {
Subroutine _name_for_sub_or_stringified_element: called CC=3 SCAR=11.0
342 1007 my $elem = shift;
343  
344 1007 ▶ if ( blessed $elem and $elem->isa('PPI::Statement::Sub') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($elem) and $elem->isa("PPI::Statement::Sub")) 17 990 1007
Condition100%3/3
builtin::blessed($elem) and $elem->isa("PPI::Statement::Sub")
!ll&&!rl&&r
598517
MC/DC100%2/2
builtin::blessed($elem) and $elem->isa("PPI::Statement::Sub")
builtin::blessed($elem) $elem->isa("PPI::Statement::Sub")
Truth table100%3/3
A and B
A= builtin::blessed($elem)B= $elem->isa("PPI::Statement::Sub")
ABresult
0X0
100
111
345 17 return $elem->name();
346 }
347  
348 990 return "$elem";
349 }
350  
351 #-----------------------------------------------------------------------------
352 ## no critic (ProhibitPackageVars)
353  
354 40 Readonly::Hash my %BUILTINS => hashify( @B::Keywords::Functions );
355  
356 264 ▶sub is_perl_builtin {
Subroutine is_perl_builtin: called CC=2 SCAR=7.1
Pod documented
357 264 my $elem = shift;
358  
359 264 ▶ return $elem && exists $BUILTINS{ _name_for_sub_or_stringified_element($elem) };
Condition66%2/3
$elem && exists $BUILTINS{_name_for_sub_or_stringified_element($elem)}
!ll&&!rl&&r
017193
MC/DC50%1/2
$elem && exists $BUILTINS{_name_for_sub_or_stringified_element($elem)}
$elem exists $BUILTINS{_name_for_sub_or_stringified_element($elem)}
Truth table66%2/3
A && B
A= $elemB= exists $BUILTINS{_name_for_sub_or_stringified_element($elem)}
ABresult
0X0
100
111
360 }
361  
362 #-----------------------------------------------------------------------------
363  
364 40 Readonly::Hash my %BAREWORDS => hashify(
365 @B::Keywords::Barewords,
366 @B::Keywords::BarewordsExtra,
367 );
368  
369 383 ▶sub is_perl_bareword {
Subroutine is_perl_bareword: called CC=2 SCAR=7.1
Pod documented
370 383 my $elem = shift;
371  
372 383 ▶ return $elem && exists $BAREWORDS{ _name_for_sub_or_stringified_element($elem) };
Condition66%2/3
$elem && exists $BAREWORDS{_name_for_sub_or_stringified_element($elem)}
!ll&&!rl&&r
031370
MC/DC50%1/2
$elem && exists $BAREWORDS{_name_for_sub_or_stringified_element($elem)}
$elem exists $BAREWORDS{_name_for_sub_or_stringified_element($elem)}
Truth table66%2/3
A && B
A= $elemB= exists $BAREWORDS{_name_for_sub_or_stringified_element($elem)}
ABresult
0X0
100
111
373 }
374  
375 #-----------------------------------------------------------------------------
376  
377 40 ▶sub _build_globals_without_sigils {
Subroutine _build_globals_without_sigils: called CC=2 SCAR=6.9
378 # B::Keywords as of 1.08 forgot $\
379 my @globals =
380 40 map { substr $_, 1 }
381 @B::Keywords::Arrays,
382 @B::Keywords::Hashes,
383 @B::Keywords::Scalars,
384 '$\\'; ## no critic (RequireInterpolationOfMetachars)
385  
386 # Not all of these have sigils
387 40 foreach my $filehandle (@B::Keywords::Filehandles) {
388 360 (my $stripped = $filehandle) =~ s< \A [*] ><>xms;
389 360 push @globals, $stripped;
390 }
391  
392 40 return @globals;
393 }
394  
395 40 Readonly::Array my @GLOBALS_WITHOUT_SIGILS => _build_globals_without_sigils();
396  
397 40 Readonly::Hash my %GLOBALS => hashify( @GLOBALS_WITHOUT_SIGILS );
398  
399 64 ▶sub is_perl_global {
Subroutine is_perl_global: called CC=2 SCAR=7.0
Pod documented
400 64 my $elem = shift;
401 64 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 64 64
402 64 my $var_name = "$elem"; #Convert Token::Symbol to string
403 64 $var_name =~ s{\A [\$@%*] }{}xms; #Chop off the sigil
404 64 return exists $GLOBALS{ $var_name };
405 }
406  
407 #-----------------------------------------------------------------------------
408  
409 40 Readonly::Hash my %FILEHANDLES => hashify( @B::Keywords::Filehandles );
410  
411 308 ▶sub is_perl_filehandle {
Subroutine is_perl_filehandle: called CC=2 SCAR=8.1
Pod documented
412 308 my $elem = shift;
413  
414 308 ▶ return $elem && exists $FILEHANDLES{ _name_for_sub_or_stringified_element($elem) };
Condition33%1/3
$elem && exists $FILEHANDLES{_name_for_sub_or_stringified_element($elem)}
!ll&&!rl&&r
03080
MC/DC0%0/2
$elem && exists $FILEHANDLES{_name_for_sub_or_stringified_element($elem)}
$elem exists $FILEHANDLES{_name_for_sub_or_stringified_element($elem)}
Truth table33%1/3
A && B
A= $elemB= exists $FILEHANDLES{_name_for_sub_or_stringified_element($elem)}
ABresult
0X0
100
111
415 }
416  
417 ## use critic
418 #-----------------------------------------------------------------------------
419  
420 # egrep '=item.*LIST' perlfunc.pod
421 40 Readonly::Hash my %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT =>
422 hashify(
423 qw{
424 chmod
425 chown
426 die
427 exec
428 formline
429 grep
430 import
431 join
432 kill
433 map
434 no
435 open
436 pack
437 print
438 printf
439 push
440 reverse
441 say
442 sort
443 splice
444 sprintf
445 syscall
446 system
447 tie
448 unlink
449 unshift
450 use
451 utime
452 warn
453 },
454 );
455  
456 0 ▶sub is_perl_builtin_with_list_context {
Subroutine is_perl_builtin_with_list_context: not called CC=1 SCAR=6.9
Pod documented
457 0 my $elem = shift;
458  
459 return
460 exists
461 $BUILTINS_WHICH_PROVIDE_LIST_CONTEXT{
462 0 _name_for_sub_or_stringified_element($elem)
463 };
464 }
465  
466 #-----------------------------------------------------------------------------
467  
468 # egrep '=item.*[A-Z],' perlfunc.pod
469 40 Readonly::Hash my %BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS =>
470 hashify(
471 qw{
472 accept
473 atan2
474 bind
475 binmode
476 bless
477 connect
478 crypt
479 dbmopen
480 fcntl
481 flock
482 gethostbyaddr
483 getnetbyaddr
484 getpriority
485 getservbyname
486 getservbyport
487 getsockopt
488 index
489 ioctl
490 link
491 listen
492 mkdir
493 msgctl
494 msgget
495 msgrcv
496 msgsnd
497 open
498 opendir
499 pipe
500 read
501 recv
502 rename
503 rindex
504 seek
505 seekdir
506 select
507 semctl
508 semget
509 semop
510 send
511 setpgrp
512 setpriority
513 setsockopt
514 shmctl
515 shmget
516 shmread
517 shmwrite
518 shutdown
519 socket
520 socketpair
521 splice
522 split
523 substr
524 symlink
525 sysopen
526 sysread
527 sysseek
528 syswrite
529 truncate
530 unpack
531 vec
532 waitpid
533 },
534 keys %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT
535 );
536  
537 9 ▶sub is_perl_builtin_with_multiple_arguments {
Subroutine is_perl_builtin_with_multiple_arguments: called CC=1 SCAR=0.0
Pod documented
538 9 my $elem = shift;
539  
540 return
541 exists
542 $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{
543 9 _name_for_sub_or_stringified_element($elem)
544 };
545 }
546  
547 #-----------------------------------------------------------------------------
548  
549 40 Readonly::Hash my %BUILTINS_WHICH_TAKE_NO_ARGUMENTS =>
550 hashify(
551 qw{
552 endgrent
553 endhostent
554 endnetent
555 endprotoent
556 endpwent
557 endservent
558 fork
559 format
560 getgrent
561 gethostent
562 getlogin
563 getnetent
564 getppid
565 getprotoent
566 getpwent
567 getservent
568 setgrent
569 setpwent
570 split
571 time
572 times
573 wait
574 wantarray
575 }
576 );
577  
578 0 ▶sub is_perl_builtin_with_no_arguments {
Subroutine is_perl_builtin_with_no_arguments: not called CC=1 SCAR=6.9
Pod documented
579 0 my $elem = shift;
580  
581 return
582 exists
583 $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{
584 0 _name_for_sub_or_stringified_element($elem)
585 };
586 }
587  
588 #-----------------------------------------------------------------------------
589  
590 40 Readonly::Hash my %BUILTINS_WHICH_TAKE_ONE_ARGUMENT =>
591 hashify(
592 qw{
593 closedir
594 dbmclose
595 delete
596 each
597 exists
598 fileno
599 getgrgid
600 getgrnam
601 gethostbyname
602 getnetbyname
603 getpeername
604 getpgrp
605 getprotobyname
606 getprotobynumber
607 getpwnam
608 getpwuid
609 getsockname
610 goto
611 keys
612 local
613 prototype
614 readdir
615 readline
616 readpipe
617 rewinddir
618 scalar
619 sethostent
620 setnetent
621 setprotoent
622 setservent
623 telldir
624 tied
625 untie
626 values
627 }
628 );
629  
630 0 ▶sub is_perl_builtin_with_one_argument {
Subroutine is_perl_builtin_with_one_argument: not called CC=1 SCAR=6.9
Pod documented
631 0 my $elem = shift;
632  
633 return
634 exists
635 $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{
636 0 _name_for_sub_or_stringified_element($elem)
637 };
638 }
639  
640 #-----------------------------------------------------------------------------
641  
642 ## no critic (ProhibitPackageVars)
643 Readonly::Hash my %BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT =>
644 hashify(
645 5440 grep { not exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $_ } }
646 6320 grep { not exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $_ } }
647 40 grep { not exists $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ $_ } }
648 @B::Keywords::Functions
649 );
650 ## use critic
651  
652 0 ▶sub is_perl_builtin_with_optional_argument {
Subroutine is_perl_builtin_with_optional_argument: not called CC=1 SCAR=6.9
Pod documented
653 0 my $elem = shift;
654  
655 return
656 exists
657 $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{
658 0 _name_for_sub_or_stringified_element($elem)
659 };
660 }
661  
662 #-----------------------------------------------------------------------------
663  
664 43 ▶sub is_perl_builtin_with_zero_and_or_one_arguments {
Subroutine is_perl_builtin_with_zero_and_or_one_arguments: called CC=4 SCAR=14.0
Pod documented
665 43 my $elem = shift;
666  
667 43 ▶ return if not $elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 43 43
668  
669 43 my $name = _name_for_sub_or_stringified_element($elem);
670  
671 return (
672 exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $name }
673 or exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $name }
674 43 ▶ or exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ $name }
Condition83%5/6
exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{$name} || exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{$name} || exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{$name}
l!l&&r!l&&!r
1834
exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{$name} or exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{$name}
l!l&&r!l&&!r
0142
MC/DC66%2/3
exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{$name} || exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{$name} || exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{$name}
exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{$name} exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{$name} exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{$name}
Truth table75%3/4
A or B || C
A= exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{$name}B= exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{$name}C= exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{$name}
ABCresult
1XX1
01X1
0011
0000
675 );
676 }
677  
678 #-----------------------------------------------------------------------------
679  
680 0 ▶sub is_qualified_name {
Subroutine is_qualified_name: not called CC=2 SCAR=17.9
Pod documented
681 0 my $name = shift;
682  
683 0 ▶ return $name && (index($name, q{::}) >= 0);
Condition0%0/3
$name && (index($name, '::') != -1)
!ll&&!rl&&r
000
MC/DC0%0/2
$name && (index($name, '::') != -1)
$name (index($name, '::') != -1)
Truth table0%0/3
A && B
A= $nameB= (index($name, '::') != -1)
ABresult
0X0
100
111
684 }
685  
686 #-----------------------------------------------------------------------------
687  
688 208 ▶sub precedence_of {
Subroutine precedence_of: called CC=3 SCAR=11.7
Pod documented
689 208 my $elem = shift;
690  
691 208 ▶ return $elem && $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem };
Branch: 1 branch
BranchTrueFalseTotal
ref $elem ? : 6 202 208
Condition33%1/3
$elem && $PRECEDENCE_OF{ref $elem ? "$elem" : $elem}
!ll&&!rl&&r
00208
MC/DC0%0/2
$elem && $PRECEDENCE_OF{ref $elem ? "$elem" : $elem}
$elem $PRECEDENCE_OF{ref $elem ? "$elem" : $elem}
Truth table33%1/3
A && B
A= $elemB= $PRECEDENCE_OF{ref $elem ? "$elem" : $elem}
ABresult
0X0
100
111
692 }
693  
694 #-----------------------------------------------------------------------------
695  
696 730 ▶sub is_hash_key {
Subroutine is_hash_key: called CC=13 SCAR=26.0
Pod documented
697 730 my $elem = shift;
698 730 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 730 730
699  
700 #If followed by an argument list, then it's a function call, not a literal.
701 730 my $sib = $elem->snext_sibling();
702 730 ▶ return if $sib && $sib->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $sib and $sib->isa("PPI::Structure::List") 50 680 730
Condition100%3/3
$sib and $sib->isa("PPI::Structure::List")
!ll&&!rl&&r
467650
MC/DC100%2/2
$sib and $sib->isa("PPI::Structure::List")
$sib $sib->isa("PPI::Structure::List")
Truth table100%3/3
A and B
A= $sibB= $sib->isa("PPI::Structure::List")
ABresult
0X0
100
111
703  
704 #Check curly-brace style: $hash{foo} = bar;
705 680 my $parent = $elem->parent();
706 680 ▶ return if !$parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 680 680
707 680 my $grandparent = $parent->parent();
708 680 ▶ return if !$grandparent;
Branch: 1 branch
BranchTrueFalseTotal
unless $grandparent 0 680 680
709 680 ▶ if ( $grandparent->isa('PPI::Structure::Subscript') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grandparent->isa("PPI::Structure::Subscript")) 5 675 680
710 # If followed by a non-(fat)comma, then it's not a hash slice,
711 # so a function call without parentheses.
712 5 ▶ return if $sib && !($sib->isa('PPI::Token::Operator')
Branch: 1 branch
BranchTrueFalseTotal
if $sib and not $sib->isa("PPI::Token::Operator") && ($sib eq $Perl::Critic::Utils::COMMA || $sib eq $Perl::Critic::Utils::FATCOMMA) 1 4 5
Condition66%6/9
$sib and not $sib->isa("PPI::Token::Operator") && ($sib eq $Perl::Critic::Utils::COMMA || $sib eq $Perl::Critic::Utils::FATCOMMA)
!ll&&!rl&&r
311
$sib->isa('PPI::Token::Operator') && ($sib eq $Perl::Critic::Utils::COMMA || $sib eq $Perl::Critic::Utils::FATCOMMA)
!ll&&!rl&&r
101
$sib eq $Perl::Critic::Utils::COMMA or $sib eq $Perl::Critic::Utils::FATCOMMA
l!l&&r!l&&!r
100
MC/DC50%2/4
$sib and not $sib->isa("PPI::Token::Operator") && ($sib eq $Perl::Critic::Utils::COMMA || $sib eq $Perl::Critic::Utils::FATCOMMA)
$sib $sib->isa('PPI::Token::Operator') $sib eq $Perl::Critic::Utils::COMMA $sib eq $Perl::Critic::Utils::FATCOMMA
Truth table60%3/5
A and not(B && C or D)
A= $sibB= $sib->isa('PPI::Token::Operator')C= $sib eq $Perl::Critic::Utils::COMMAD= $sib eq $Perl::Critic::Utils::FATCOMMA
ABCDresult
0XXX0
111X0
11010
10XX1
11001
713 && ($sib eq $COMMA || $sib eq $FATCOMMA));
714 4 return 1;
715 }
716  
717 #Check declarative style: %hash = (foo => bar);
718 return
719 675 ▶ $sib
Condition100%6/6
$sib && $sib->isa('PPI::Token::Operator') && $sib eq $Perl::Critic::Utils::FATCOMMA
!ll&&!rl&&r
67221
$sib and $sib->isa("PPI::Token::Operator")
!ll&&!rl&&r
16713
MC/DC100%3/3
$sib && $sib->isa('PPI::Token::Operator') && $sib eq $Perl::Critic::Utils::FATCOMMA
$sib $sib->isa("PPI::Token::Operator") $sib eq $Perl::Critic::Utils::FATCOMMA
Truth table100%4/4
A and B && C
A= $sibB= $sib->isa("PPI::Token::Operator")C= $sib eq $Perl::Critic::Utils::FATCOMMA
ABCresult
0XX0
10X0
1100
1111
720 && $sib->isa('PPI::Token::Operator')
721 && $sib eq $FATCOMMA
722 ;
723 }
724  
725 #-----------------------------------------------------------------------------
726  
727 371 ▶sub is_included_module_name {
Subroutine is_included_module_name: called CC=4 SCAR=14.0
Pod documented
728 371 my $elem = shift;
729 371 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 371 371
730 371 my $stmnt = $elem->statement();
731 371 ▶ return if !$stmnt;
Branch: 1 branch
BranchTrueFalseTotal
unless $stmnt 0 371 371
732 371 ▶ return if !$stmnt->isa('PPI::Statement::Include');
Branch: 1 branch
BranchTrueFalseTotal
unless $stmnt->isa("PPI::Statement::Include") 257 114 371
733 114 return $stmnt->schild(1) == $elem;
734 }
735  
736 #-----------------------------------------------------------------------------
737  
738 1734 ▶sub is_integer {
Subroutine is_integer: called CC=2 SCAR=7.1
Pod documented
739 1734 my ($value) = @_;
740 1734 ▶ return 0 if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1734 1734
741  
742 1734 return $value =~ m{ \A [+-]? \d+ \z }xms;
743 }
744  
745 #-----------------------------------------------------------------------------
746  
747 287 ▶sub is_label_pointer {
Subroutine is_label_pointer: called CC=5 SCAR=16.4
Pod documented
748 287 my $elem = shift;
749 287 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 287 287
750  
751 287 my $statement = $elem->statement();
752 287 ▶ return if !$statement;
Branch: 1 branch
BranchTrueFalseTotal
unless $statement 0 287 287
753 287 ▶ return if !$statement->isa('PPI::Statement::Break');
Branch: 1 branch
BranchTrueFalseTotal
unless $statement->isa("PPI::Statement::Break") 273 14 287
754  
755 14 my $psib = $elem->sprevious_sibling();
756 14 state $redirectors = { hashify( qw( redo goto next last ) ) };
757 14 ▶ return $psib && exists $redirectors->{$psib};
Condition66%2/3
$psib && exists $redirectors->{$psib}
!ll&&!rl&&r
1040
MC/DC0%0/2
$psib && exists $redirectors->{$psib}
$psib exists $redirectors->{$psib}
Truth table66%2/3
A && B
A= $psibB= exists $redirectors->{$psib}
ABresult
0X0
100
111
758 }
759  
760 #-----------------------------------------------------------------------------
761  
762 604 ▶sub is_method_call {
Subroutine is_method_call: called CC=2 SCAR=8.1
Pod documented
763 604 my $elem = shift;
764  
765 604 ▶ return $elem && _is_dereference_operator( $elem->sprevious_sibling() );
Condition33%1/3
$elem && _is_dereference_operator($elem->sprevious_sibling)
!ll&&!rl&&r
06040
MC/DC0%0/2
$elem && _is_dereference_operator($elem->sprevious_sibling)
$elem _is_dereference_operator($elem->sprevious_sibling)
Truth table33%1/3
A && B
A= $elemB= _is_dereference_operator($elem->sprevious_sibling)
ABresult
0X0
100
111
766 }
767  
768 #-----------------------------------------------------------------------------
769  
770 308 ▶sub is_class_name {
Subroutine is_class_name: called CC=3 SCAR=14.2
Pod documented
771 308 my $elem = shift;
772  
773 return
774 308 ▶ $elem
Condition33%2/6
$elem && _is_dereference_operator($elem->snext_sibling) && !_is_dereference_operator($elem->sprevious_sibling)
!ll&&!rl&&r
30800
$elem and _is_dereference_operator($elem->snext_sibling)
!ll&&!rl&&r
03080
MC/DC0%0/3
$elem && _is_dereference_operator($elem->snext_sibling) && !_is_dereference_operator($elem->sprevious_sibling)
$elem _is_dereference_operator($elem->snext_sibling) !_is_dereference_operator($elem->sprevious_sibling)
Truth table25%1/4
A and B && not(C)
A= $elemB= _is_dereference_operator($elem->snext_sibling)C= !_is_dereference_operator($elem->sprevious_sibling)
ABCresult
0XX0
10X0
1100
1111
775 && _is_dereference_operator( $elem->snext_sibling() )
776 && !_is_dereference_operator( $elem->sprevious_sibling() )
777 ;
778 }
779  
780 #-----------------------------------------------------------------------------
781  
782 912 ▶sub _is_dereference_operator {
Subroutine _is_dereference_operator: called CC=3 SCAR=11.0
783 912 my $elem = shift;
784  
785 return
786 912 ▶ $elem
Condition83%5/6
$elem && $elem->isa('PPI::Token::Operator') && $elem eq '->'
!ll&&!rl&&r
91020
$elem and $elem->isa("PPI::Token::Operator")
!ll&&!rl&&r
5044062
MC/DC0%0/3
$elem && $elem->isa('PPI::Token::Operator') && $elem eq '->'
$elem $elem->isa("PPI::Token::Operator") $elem eq '->'
Truth table75%3/4
A and B && C
A= $elemB= $elem->isa("PPI::Token::Operator")C= $elem eq '->'
ABCresult
0XX0
10X0
1100
1111
787 && $elem->isa('PPI::Token::Operator')
788 && $elem eq q{->}
789 ;
790 }
791  
792 #-----------------------------------------------------------------------------
793  
794 337 ▶sub is_package_declaration {
Subroutine is_package_declaration: called CC=4 SCAR=15.2
Pod documented
795 337 my $elem = shift;
796 337 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 337 337
797 337 my $stmnt = $elem->statement();
798 337 ▶ return if !$stmnt;
Branch: 1 branch
BranchTrueFalseTotal
unless $stmnt 0 337 337
799 337 ▶ return if !$stmnt->isa('PPI::Statement::Package');
Branch: 1 branch
BranchTrueFalseTotal
unless $stmnt->isa("PPI::Statement::Package") 337 0 337
800 0 return $stmnt->schild(1) == $elem;
801 }
802  
803 #-----------------------------------------------------------------------------
804  
805 357 ▶sub is_subroutine_name {
Subroutine is_subroutine_name: called CC=5 SCAR=16.2
Pod documented
806 357 my $elem = shift;
807 357 ▶ return if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 357 357
808  
809 357 my $sib = $elem->sprevious_sibling();
810 357 ▶ return if !$sib;
Branch: 1 branch
BranchTrueFalseTotal
unless $sib 287 70 357
811 70 ▶ return if $sib ne 'sub';
Branch: 1 branch
BranchTrueFalseTotal
if $sib ne "sub" 48 22 70
812  
813 22 my $stmnt = $elem->statement();
814 22 ▶ return if !$stmnt;
Branch: 1 branch
BranchTrueFalseTotal
unless $stmnt 0 22 22
815 22 return $stmnt->isa('PPI::Statement::Sub');
816 }
817  
818 #-----------------------------------------------------------------------------
819  
820 372 ▶sub is_function_call {
Subroutine is_function_call: called CC=11 SCAR=25.7
Pod documented
821 372 ▶ my $elem = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $elem = shift() or return 372 0 372
822  
823 372 ▶ return if is_perl_bareword($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_perl_bareword($elem) 64 308 372
824 308 ▶ return if is_perl_filehandle($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_perl_filehandle($elem) 0 308 308
825 308 ▶ return if is_package_declaration($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_package_declaration($elem) 0 308 308
826 308 ▶ return if is_included_module_name($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_included_module_name($elem) 0 308 308
827 308 ▶ return if is_method_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_method_call($elem) 0 308 308
828 308 ▶ return if is_class_name($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_class_name($elem) 0 308 308
829 308 ▶ return if is_subroutine_name($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_subroutine_name($elem) 21 287 308
830 287 ▶ return if is_label_pointer($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_label_pointer($elem) 0 287 287
831 287 ▶ return if is_hash_key($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_hash_key($elem) 0 287 287
832  
833 287 return 1;
834 }
835  
836 #-----------------------------------------------------------------------------
837  
838 8 ▶sub is_script {
Subroutine is_script: called CC=5 SCAR=16.5
Pod documented
839 8 my $doc = shift;
840  
841 8 warnings::warnif(
842 'deprecated',
843 'Perl::Critic::Utils::is_script($doc) deprecated, use $doc->is_program() instead.', ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
844 );
845  
846 8 ▶ return $doc->is_program()
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($doc) and $doc->isa("Perl::Critic::Document") 0 8 8
Condition33%1/3
builtin::blessed($doc) and $doc->isa("Perl::Critic::Document")
!ll&&!rl&&r
080
MC/DC0%0/2
builtin::blessed($doc) and $doc->isa("Perl::Critic::Document")
builtin::blessed($doc) $doc->isa("Perl::Critic::Document")
Truth table33%1/3
A and B
A= builtin::blessed($doc)B= $doc->isa("Perl::Critic::Document")
ABresult
0X0
100
111
847 if blessed($doc) && $doc->isa('Perl::Critic::Document');
848  
849 8 ▶ return 1 if shebang_line($doc);
Branch: 1 branch
BranchTrueFalseTotal
if shebang_line($doc) 5 3 8
850 3 ▶ return 1 if _is_PL_file($doc);
Branch: 1 branch
BranchTrueFalseTotal
if _is_PL_file($doc) 1 2 3
851 2 return 0;
852 }
853  
854 #-----------------------------------------------------------------------------
855  
856 3 ▶sub _is_PL_file { ## no critic (NamingConventions::Capitalization)
Subroutine _is_PL_file: called CC=4 SCAR=14.6
857 3 my ($doc) = @_;
858 3 ▶ return if not $doc->can('filename');
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->can("filename") 0 3 3
859 3 ▶ my $filename = $doc->filename() || return;
Condition100%2/2
$doc->filename || (return)
l!l
12
MC/DC100%1/1
$doc->filename || (return)
$doc->filename
Truth table100%2/2
A
A= $doc->filename
Aresult
11
00
860 1 ▶ return 1 if $filename =~ m/[.] PL \z/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /[.] PL \z/msx 1 0 1
861 0 return 0;
862 }
863  
864 #-----------------------------------------------------------------------------
865  
866 0 ▶sub is_in_void_context {
Subroutine is_in_void_context: not called CC=13 SCAR=52.0
Pod documented
867 0 my ($token) = @_;
868  
869 # If part of a collective, can't be void.
870 0 ▶ return if $token->sprevious_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $token->sprevious_sibling 0 0 0
871  
872 0 my $parent = $token->statement()->parent();
873 0 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 0 0 0
874 0 ▶ return if $parent->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::List") 0 0 0
875 0 ▶ return if $parent->isa('PPI::Structure::For');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::For") 0 0 0
876 0 ▶ return if $parent->isa('PPI::Structure::Condition');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Condition") 0 0 0
877 0 ▶ return if $parent->isa('PPI::Structure::Constructor');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Constructor") 0 0 0
878 0 ▶ return if $parent->isa('PPI::Structure::Subscript');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Subscript") 0 0 0
879  
880 # If it's in a block and not the last statement then it's in void.
881 0 ▶ return 1 if
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Block") and $token->statement->snext_sibling 0 0 0
Condition0%0/3
$parent->isa("PPI::Structure::Block") and $token->statement->snext_sibling
!ll&&!rl&&r
000
MC/DC0%0/2
$parent->isa("PPI::Structure::Block") and $token->statement->snext_sibling
$parent->isa("PPI::Structure::Block") $token->statement->snext_sibling
Truth table0%0/3
A and B
A= $parent->isa("PPI::Structure::Block")B= $token->statement->snext_sibling
ABresult
0X0
100
111
882 $parent->isa('PPI::Structure::Block')
883 and $token->statement()->snext_sibling();
884  
885 0 my $grandparent = $parent->parent();
886 0 ▶ if ($grandparent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grandparent) 0 0 0
887 return if
888 0 ▶ $parent->isa('PPI::Structure::Block')
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Block") and not $grandparent->isa("PPI::Statement::Compound") 0 0 0
Condition0%0/3
$parent->isa("PPI::Structure::Block") and not $grandparent->isa("PPI::Statement::Compound")
!ll&&!rl&&r
000
MC/DC0%0/2
$parent->isa("PPI::Structure::Block") and not $grandparent->isa("PPI::Statement::Compound")
$parent->isa("PPI::Structure::Block") not $grandparent->isa("PPI::Statement::Compound")
Truth table0%0/3
A and not(B)
A= $parent->isa("PPI::Structure::Block")B= not $grandparent->isa("PPI::Statement::Compound")
ABresult
0X0
100
111
889 and not $grandparent->isa('PPI::Statement::Compound');
890 }
891 }
892  
893 0 return $TRUE;
894 }
895  
896 #-----------------------------------------------------------------------------
897  
898 27153 ▶sub policy_long_name {
Subroutine policy_long_name: called CC=2 SCAR=6.9
Pod documented
899 27153 my ( $policy_name ) = @_;
900 27153 ▶ if ( $policy_name !~ m{ \A $POLICY_NAMESPACE }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($policy_name =~ / \A $Perl::Critic::Utils::POLICY_NAMESPACE /msx) 460 26693 27153
901 460 $policy_name = $POLICY_NAMESPACE . q{::} . $policy_name;
902 }
903 27153 return $policy_name;
904 }
905  
906 #-----------------------------------------------------------------------------
907  
908 121579 ▶sub policy_short_name {
Subroutine policy_short_name: called CC=1 SCAR=0.0
Pod documented
909 121579 my ( $policy_name ) = @_;
910 121579 $policy_name =~ s{\A $POLICY_NAMESPACE ::}{}xms;
911 121579 return $policy_name;
912 }
913  
914 #-----------------------------------------------------------------------------
915  
916 15 ▶sub first_arg {
Subroutine first_arg: called CC=5 SCAR=16.2
Pod documented
917 15 my $elem = shift;
918 15 my $sib = $elem->snext_sibling();
919 15 ▶ return if !$sib;
Branch: 1 branch
BranchTrueFalseTotal
unless $sib 0 15 15
920  
921 15 ▶ if ( $sib->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sib->isa("PPI::Structure::List")) 2 13 15
922  
923 2 my $expr = $sib->schild(0);
924 2 ▶ return if !$expr;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr 1 1 2
925 1 ▶ return $expr->isa('PPI::Statement') ? $expr->schild(0) : $expr;
Branch: 1 branch
BranchTrueFalseTotal
$expr->isa('PPI::Statement') ? : 1 0 1
926 }
927  
928 13 return $sib;
929 }
930  
931 #-----------------------------------------------------------------------------
932  
933 26 ▶sub parse_arg_list {
Subroutine parse_arg_list: called CC=11 SCAR=24.9
Pod documented
934 26 my $elem = shift;
935 26 my $sib = $elem->snext_sibling();
936 26 ▶ return if !$sib;
Branch: 1 branch
BranchTrueFalseTotal
unless $sib 0 26 26
937  
938 26 ▶ if ( $sib->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sib->isa('PPI::Structure::List')) { } 3 23 26
939  
940 #Pull siblings from list
941 3 my @list_contents = $sib->schildren();
942 3 ▶ return if not @list_contents;
Branch: 1 branch
BranchTrueFalseTotal
unless @list_contents 0 3 3
943  
944 3 my @list_expressions;
945 3 foreach my $item (@list_contents) {
946 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (is_ppi_expression_or_generic_statement($item)) { } 3 0 3
947 is_ppi_expression_or_generic_statement($item)
948 ) {
949 3 push
950 @list_expressions,
951 split_nodes_on_comma( $item->schildren() );
952 }
953 else {
954 0 push @list_expressions, $item;
955 }
956 }
957  
958 3 return @list_expressions;
959 }
960 else {
961  
962 # Gather up remaining nodes in the statement.
963 23 my $iter = $elem;
964 23 my @arg_list;
965  
966 23 ▶ while ($iter = $iter->snext_sibling() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iter = $iter->snext_sibling) 58 0 58
967 58 ▶ last if $iter->isa('PPI::Token::Structure') and $iter eq $SCOLON;
Branch: 1 branch
BranchTrueFalseTotal
if $iter->isa("PPI::Token::Structure") and $iter eq $Perl::Critic::Utils::SCOLON 23 35 58
Condition66%2/3
$iter->isa("PPI::Token::Structure") and $iter eq $Perl::Critic::Utils::SCOLON
!ll&&!rl&&r
35023
MC/DC50%1/2
$iter->isa("PPI::Token::Structure") and $iter eq $Perl::Critic::Utils::SCOLON
$iter->isa("PPI::Token::Structure") $iter eq $Perl::Critic::Utils::SCOLON
Truth table66%2/3
A and B
A= $iter->isa("PPI::Token::Structure")B= $iter eq $Perl::Critic::Utils::SCOLON
ABresult
0X0
100
111
968 35 ▶ last if $iter->isa('PPI::Token::Operator')
Branch: 1 branch
BranchTrueFalseTotal
if $iter->isa("PPI::Token::Operator") and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of($iter) 0 35 35
Condition66%2/3
$iter->isa("PPI::Token::Operator") and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of($iter)
!ll&&!rl&&r
3140
MC/DC0%0/2
$iter->isa("PPI::Token::Operator") and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of($iter)
$iter->isa("PPI::Token::Operator") $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of($iter)
Truth table66%2/3
A and B
A= $iter->isa("PPI::Token::Operator")B= $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of($iter)
ABresult
0X0
100
111
969 and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <=
970 precedence_of( $iter );
971 35 push @arg_list, $iter;
972 }
973 23 return split_nodes_on_comma( @arg_list );
974 }
975 }
976  
977 #---------------------------------
978  
979 26 ▶sub split_nodes_on_comma {
Subroutine split_nodes_on_comma: called CC=8 SCAR=20.9
Pod documented
980 26 my @nodes = @_;
981  
982 26 my $i = 0;
983 26 my @node_stacks;
984 26 for my $node (@nodes) {
985 50 my $node_content = $node->content;
986 50 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($node->isa('PPI::Token::Operator') and $node_content eq $Perl::Critic::Utils::COMMA || $node_content eq $Perl::Critic::Utils::FATCOMMA) { } 10 40 50
elsif ($node->isa('PPI::Token::QuoteLike::Words')) { } 7 33 40
Condition66%4/6
$node->isa("PPI::Token::Operator") and $node_content eq $Perl::Critic::Utils::COMMA || $node_content eq $Perl::Critic::Utils::FATCOMMA
!ll&&!rl&&r
40010
$node_content eq $Perl::Critic::Utils::COMMA or $node_content eq $Perl::Critic::Utils::FATCOMMA
l!l&&r!l&&!r
820
MC/DC33%1/3
$node->isa("PPI::Token::Operator") and $node_content eq $Perl::Critic::Utils::COMMA || $node_content eq $Perl::Critic::Utils::FATCOMMA
$node->isa("PPI::Token::Operator") $node_content eq $Perl::Critic::Utils::COMMA $node_content eq $Perl::Critic::Utils::FATCOMMA
Truth table75%3/4
A and B or C
A= $node->isa("PPI::Token::Operator")B= $node_content eq $Perl::Critic::Utils::COMMAC= $node_content eq $Perl::Critic::Utils::FATCOMMA
ABCresult
0XX0
1000
11X1
1011
987 $node->isa('PPI::Token::Operator')
988 and ($node_content eq $COMMA or $node_content eq $FATCOMMA)
989 ) {
990 10 ▶ if (@node_stacks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@node_stacks) 10 0 10
991 10 $i++; #Move forward to next 'node stack'
992 }
993 10 next;
994 } elsif ( $node->isa('PPI::Token::QuoteLike::Words' )) {
995 7 my $section = $node->{sections}->[0];
996 7 my @words = words_from_string(substr $node_content, $section->{position}, $section->{size});
997 7 my $loc = $node->location;
998 7 for my $word (@words) {
999 10 my $token = PPI::Token::Quote::Single->new(q{'} . $word . q{'});
1000 10 $token->{_location} = $loc;
1001 10 push @{ $node_stacks[$i++] }, $token;
1002 }
1003 7 next;
1004 }
1005 33 push @{ $node_stacks[$i] }, $node;
1006 }
1007 26 return @node_stacks;
1008 }
1009  
1010 #-----------------------------------------------------------------------------
1011  
1012 # XXX: You must keep the regular expressions in extras/perlcritic.el in sync
1013 # if you change these.
1014 40 Readonly::Hash my %FORMAT_OF => (
1015 1 => "%f:%l:%c:%m\n",
1016 2 => "%f: (%l:%c) %m\n",
1017 3 => "%m at %f line %l\n",
1018 4 => "%m at line %l, column %c. %e. (Severity: %s)\n",
1019 5 => "%f: %m at line %l, column %c. %e. (Severity: %s)\n",
1020 6 => "%m at line %l, near '%r'. (Severity: %s)\n",
1021 7 => "%f: %m at line %l near '%r'. (Severity: %s)\n",
1022 8 => "[%p] %m at line %l, column %c. (Severity: %s)\n",
1023 9 => "[%p] %m at line %l, near '%r'. (Severity: %s)\n",
1024 10 => "%m at line %l, column %c.\n %p (Severity: %s)\n%d\n",
1025 11 => "%m at line %l, near '%r'.\n %p (Severity: %s)\n%d\n",
1026 );
1027  
1028 40 Readonly::Scalar our $DEFAULT_VERBOSITY => 4;
1029 40 Readonly::Scalar our $DEFAULT_VERBOSITY_WITH_FILE_NAME => 5;
1030 40 Readonly::Scalar my $DEFAULT_FORMAT => $FORMAT_OF{$DEFAULT_VERBOSITY};
1031  
1032 280 ▶sub is_valid_numeric_verbosity {
Subroutine is_valid_numeric_verbosity: called CC=1 SCAR=0.0
Pod documented
1033 280 my ($verbosity) = @_;
1034  
1035 280 return exists $FORMAT_OF{$verbosity};
1036 }
1037  
1038 20 ▶sub verbosity_to_format {
Subroutine verbosity_to_format: called CC=4 SCAR=13.9
Pod documented
1039 20 my ($verbosity) = @_;
1040 20 ▶ return $DEFAULT_FORMAT if not defined $verbosity;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $verbosity 1 19 20
1041 19 ▶ return $FORMAT_OF{abs int $verbosity} || $DEFAULT_FORMAT if is_integer($verbosity);
Branch: 1 branch
BranchTrueFalseTotal
if is_integer($verbosity) 2 17 19
Condition66%2/3
$FORMAT_OF{abs int $verbosity} || $DEFAULT_FORMAT
l!l&&r!l&&!r
110
MC/DC0%0/2
$FORMAT_OF{abs int $verbosity} || $DEFAULT_FORMAT
$FORMAT_OF{abs int $verbosity} $DEFAULT_FORMAT
Truth table66%2/3
A || B
A= $FORMAT_OF{abs int $verbosity}B= $DEFAULT_FORMAT
ABresult
1X1
011
000
1042 17 return interpolate( $verbosity ); #Otherwise, treat as a format spec
1043 }
1044  
1045 #-----------------------------------------------------------------------------
1046  
1047 40 Readonly::Hash my %SEVERITY_NUMBER_OF => (
1048 gentle => 5,
1049 stern => 4,
1050 harsh => 3,
1051 cruel => 2,
1052 brutal => 1,
1053 );
1054  
1055 Readonly::Array our @SEVERITY_NAMES => #This is exported!
1056 sort
1057 40 { $SEVERITY_NUMBER_OF{$a} <=> $SEVERITY_NUMBER_OF{$b} }
1058 keys %SEVERITY_NUMBER_OF;
1059  
1060 871 ▶sub severity_to_number {
Subroutine severity_to_number: called CC=3 SCAR=11.0
Pod documented
1061 871 my ($severity) = @_;
1062 871 ▶ return _normalize_severity( $severity ) if is_integer( $severity );
Branch: 1 branch
BranchTrueFalseTotal
if is_integer($severity) 865 6 871
1063 6 my $severity_number = $SEVERITY_NUMBER_OF{lc $severity};
1064  
1065 6 ▶ if ( not defined $severity_number ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $severity_number) 1 5 6
1066 1 throw_generic qq{Invalid severity: "$severity"};
1067 }
1068  
1069 5 return $severity_number;
1070 }
1071  
1072 865 ▶sub _normalize_severity {
Subroutine _normalize_severity: called CC=4 SCAR=14.9
1073 865 ▶ my $s = shift || return $SEVERITY_HIGHEST;
Condition50%1/2
shift() || (return $Perl::Critic::Utils::SEVERITY_HIGHEST)
l!l
8650
MC/DC0%0/1
shift() || (return $Perl::Critic::Utils::SEVERITY_HIGHEST)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1074 865 ▶ $s = $s > $SEVERITY_HIGHEST ? $SEVERITY_HIGHEST : $s;
Branch: 1 branch
BranchTrueFalseTotal
$s > $Perl::Critic::Utils::SEVERITY_HIGHEST ? : 0 865 865
1075 865 ▶ $s = $s < $SEVERITY_LOWEST ? $SEVERITY_LOWEST : $s;
Branch: 1 branch
BranchTrueFalseTotal
$s < $Perl::Critic::Utils::SEVERITY_LOWEST ? : 0 865 865
1076 865 return $s;
1077 }
1078  
1079 #-----------------------------------------------------------------------------
1080  
1081 40 Readonly::Array my @SKIP_DIR => qw( CVS RCS .svn _darcs {arch} .bzr .cdv .git .hg .pc _build blib );
1082 40 Readonly::Hash my %SKIP_DIR => hashify( @SKIP_DIR );
1083  
1084 1 ▶sub all_perl_files {
Subroutine all_perl_files: called CC=2 SCAR=7.2
Pod documented
1085 1 my @arg = @_;
1086 1 my @code_files;
1087  
1088 # The old code did a breadth-first search (documentation to the
1089 # contrary notwithstanding,) whereas File::Find does depth-first. So
1090 # there appears to be no way to use File::Find without changing the
1091 # order in which the files are returned.
1092 File::Find::find( {
1093 163 ▶ wanted => sub {
Subroutine __ANON__: called CC=6 SCAR=19.3
1094 163 ▶ if ( -d && $SKIP_DIR{$_} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $_ and $SKIP_DIR{$_}) { } 0 163 163
elsif (-f $_ and not _is_backup($_) and _is_perl($_)) { } 145 36 181
Condition66%2/3
-d $_ and $SKIP_DIR{$_}
!ll&&!rl&&r
145180
MC/DC0%0/2
-d $_ and $SKIP_DIR{$_}
-d $_ $SKIP_DIR{$_}
Truth table66%2/3
A and B
A= -d $_B= $SKIP_DIR{$_}
ABresult
0X0
100
111
1095 0 $File::Find::prune = 1;
1096 ▶ } elsif ( -f && ! _is_backup( $_ ) && _is_perl( $_ ) ) {
Condition66%4/6
-f $_ and not _is_backup($_) and _is_perl($_)
!ll&&!rl&&r
180145
-f $_ and not _is_backup($_)
!ll&&!rl&&r
180145
MC/DC33%1/3
-f $_ and not _is_backup($_) and _is_perl($_)
-f $_ not _is_backup($_) _is_perl($_)
Truth table50%2/4
A and not(B) and C
A= -f $_B= not _is_backup($_)C= _is_perl($_)
ABCresult
0XX0
10X0
1100
1111
1097 145 push @code_files, $File::Find::name;
1098 }
1099 163 return;
1100 },
1101 1 untaint => 1,
1102 },
1103 @arg,
1104 );
1105  
1106 # Use File::Spec->abs2rel() to get rid of leading './' or other OS
1107 # equivalent on relative filenames.
1108 # Use map {} to get rid of leading './', or other OS equivalent
1109 1 ▶ return ( map { File::Spec->file_name_is_absolute( $_ ) ?
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($_) ? : 0 145 145
1110 $_ : File::Spec->abs2rel( $_ ) } @code_files );
1111 }
1112  
1113  
1114 #-----------------------------------------------------------------------------
1115 # Decide if it's some sort of backup file
1116  
1117 152 ▶sub _is_backup {
Subroutine _is_backup: called CC=3 SCAR=11.0
1118 152 my ($file) = @_;
1119 152 ▶ return 1 if $file =~ m{ (?: [.] swp | [.] bak | ~ ) \z}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ / (?: [.] swp | [.] bak | ~ ) \z/msx 3 149 152
1120 149 ▶ return 1 if $file =~ m{ \A [#] .+ [#] \z}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ / \A [#] .+ [#] \z/msx 1 148 149
1121 148 return;
1122 }
1123  
1124 #-----------------------------------------------------------------------------
1125 # Returns true if the argument ends with a perl-ish file
1126 # extension, or if it has a shebang-line containing 'perl' This
1127 # subroutine was also poached from Test::Perl::Critic
1128  
1129 165 ▶sub _is_perl {
Subroutine _is_perl: called CC=6 SCAR=18.0
1130 165 my ($file) = @_;
1131  
1132 #Check filename extensions
1133 165 ▶ return 1 if $file =~ m{ [.] (?: PL | p[lm] | psgi | t ) \z}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ / [.] (?: PL | p[lm] | psgi | t ) \z/msx 150 15 165
1134  
1135 #Check for shebang
1136 15 ▶ open my $fh, '<', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return 9 6 15
1137 9 my $first = <$fh>;
1138 9 ▶ close $fh or throw_generic "unable to close $file: $OS_ERROR";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or throw_generic("unable to close ${file}: $Perl::Critic::Utils::OS_ERROR") 9 0 9
1139  
1140 9 ▶ return 1 if defined $first && ( $first =~ m{ \A [#]!.*perl }xms );
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and $first =~ / \A [#]!.*perl /msx 6 3 9
Condition66%2/3
defined $first and $first =~ / \A [#]!.*perl /msx
!ll&&!rl&&r
036
MC/DC50%1/2
defined $first and $first =~ / \A [#]!.*perl /msx
defined $first $first =~ / \A [#]!.*perl /msx
Truth table66%2/3
A and B
A= defined $firstB= $first =~ / \A [#]!.*perl /msx
ABresult
0X0
100
111
1141 3 return;
1142 }
1143  
1144 #-----------------------------------------------------------------------------
1145  
1146 158 ▶sub shebang_line {
Subroutine shebang_line: called CC=7 SCAR=19.8
Pod documented
1147 158 my $doc = shift;
1148 158 my $first_element = $doc->first_element();
1149 158 ▶ return if not $first_element;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_element 0 158 158
1150 158 ▶ return if not $first_element->isa('PPI::Token::Comment');
Branch: 1 branch
BranchTrueFalseTotal
unless $first_element->isa("PPI::Token::Comment") 124 34 158
1151 34 my $location = $first_element->location();
1152 34 ▶ return if !$location;
Branch: 1 branch
BranchTrueFalseTotal
unless $location 0 34 34
1153 # The shebang must be the first two characters in the file, according to
1154 # http://en.wikipedia.org/wiki/Shebang_(Unix)
1155 34 ▶ return if $location->[0] != 1; # line number
Branch: 1 branch
BranchTrueFalseTotal
if $location->[0] != 1 0 34 34
1156 34 ▶ return if $location->[1] != 1; # column number
Branch: 1 branch
BranchTrueFalseTotal
if $location->[1] != 1 0 34 34
1157 34 my $shebang = $first_element->content;
1158 34 ▶ return if $shebang !~ m{ \A [#]! }xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $shebang =~ / \A [#]! /msx 18 16 34
1159 16 return $shebang;
1160 }
1161  
1162 #-----------------------------------------------------------------------------
1163  
1164 6608 ▶sub words_from_string {
Subroutine words_from_string: called CC=1 SCAR=0.0
Pod documented
1165 6608 my $str = shift;
1166  
1167 6608 return split q{ }, $str; # This must be a literal space, not $SPACE
1168 }
1169  
1170 #-----------------------------------------------------------------------------
1171  
1172 40 Readonly::Hash my %ASSIGNMENT_OPERATORS => hashify( qw( = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //= ) );
1173  
1174 56 ▶sub is_assignment_operator {
Subroutine is_assignment_operator: called CC=1 SCAR=0.0
Pod documented
1175 56 my $elem = shift;
1176  
1177 56 return $ASSIGNMENT_OPERATORS{ $elem };
1178 }
1179  
1180 #-----------------------------------------------------------------------------
1181  
1182 17 ▶sub is_unchecked_call {
Subroutine is_unchecked_call: called CC=12 SCAR=25.2
Pod documented
1183 17 my ( $elem, $autodie_modules ) = @_;
1184  
1185 17 ▶ return if not is_function_call( $elem );
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 17 17
1186  
1187 # Check to see if there's an '=' or 'unless' or something before this.
1188 17 ▶ return if $elem->sprevious_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $elem->sprevious_sibling 2 15 17
1189  
1190 15 ▶ if( my $statement = $elem->statement() ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $statement = $elem->statement) 15 0 15
1191  
1192 # "open or die" is OK.
1193 # We can't check snext_sibling for 'or' since the next siblings are an
1194 # unknown number of arguments to the system call. Instead, check all of
1195 # the elements to this statement to see if we find 'or' or '||'.
1196  
1197 15 state $or_or_or = { hashify( qw( or || ) ) };
1198 185 ▶ my $or_operators = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1199 185 my (undef, $elem) = @_; ## no critic(Variables::ProhibitReusedNames)
1200 185 ▶ return $elem->isa('PPI::Token::Operator') && exists $or_or_or->{$elem->content};
Condition100%3/3
$elem->isa('PPI::Token::Operator') && exists $$or_or_or{$elem->content}
!ll&&!rl&&r
160241
MC/DC100%2/2
$elem->isa('PPI::Token::Operator') && exists $$or_or_or{$elem->content}
$elem->isa('PPI::Token::Operator') exists $$or_or_or{$elem->content}
Truth table100%3/3
A && B
A= $elem->isa('PPI::Token::Operator')B= exists $$or_or_or{$elem->content}
ABresult
0X0
100
111
1201 15 };
1202  
1203 15 ▶ return if $statement->find( $or_operators );
Branch: 1 branch
BranchTrueFalseTotal
if $statement->find($or_operators) 1 14 15
1204  
1205 14 ▶ if( my $parent = $elem->statement()->parent() ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $elem->statement->parent) 14 0 14
1206  
1207 # Check if we're in an if( open ) {good} else {bad} condition
1208 14 ▶ return if $parent->isa('PPI::Structure::Condition');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Condition") 0 14 14
1209  
1210 # Return val could be captured in data structure and checked later
1211 14 ▶ return if $parent->isa('PPI::Structure::Constructor');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Structure::Constructor") 0 14 14
1212  
1213 # "die if not ( open() )" - It's in list context.
1214 14 ▶ if ( $parent->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("PPI::Structure::List")) 6 8 14
1215 6 ▶ if( my $uncle = $parent->sprevious_sibling() ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $uncle = $parent->sprevious_sibling) 1 5 6
1216 1 ▶ return if $uncle;
Branch: 1 branch
BranchTrueFalseTotal
if $uncle 1 0 1
1217 }
1218 }
1219 }
1220 }
1221  
1222 13 ▶ return if _is_fatal($elem, $autodie_modules);
Branch: 1 branch
BranchTrueFalseTotal
if _is_fatal($elem, $autodie_modules) 7 6 13
1223  
1224 # Otherwise, return. this system call is unchecked.
1225 6 return 1;
1226 }
1227  
1228 # Based upon autodie 2.10.
1229 Readonly::Hash my %AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP => (
1230 # Map builtins to themselves.
1231 (
1232 40 map { $_ => { hashify( $_ ) } }
1233 qw<
1234 accept bind binmode chdir chmod close closedir connect
1235 dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl
1236 link listen mkdir msgctl msgget msgrcv msgsnd open opendir
1237 pipe read readlink recv rename rmdir seek semctl semget semop
1238 send setsockopt shmctl shmget shmread shutdown socketpair
1239 symlink sysopen sysread sysseek system syswrite truncate umask
1240 unlink
1241 >
1242 ),
1243  
1244 # Generate these using tools/dump-autodie-tag-contents
1245 ':threads' => { hashify( qw< fork > ) },
1246 ':system' => { hashify( qw< exec system > ) },
1247 ':dbm' => { hashify( qw< dbmclose dbmopen > ) },
1248 ':semaphore' => { hashify( qw< semctl semget semop > ) },
1249 ':shm' => { hashify( qw< shmctl shmget shmread > ) },
1250 ':msg' => { hashify( qw< msgctl msgget msgrcv msgsnd > ) },
1251 ':file' => {
1252 hashify(
1253 qw<
1254 binmode chmod close fcntl fileno flock ioctl open sysopen
1255 truncate
1256 >
1257 )
1258 },
1259 ':filesys' => {
1260 hashify(
1261 qw<
1262 chdir closedir link mkdir opendir readlink rename rmdir
1263 symlink umask unlink
1264 >
1265 )
1266 },
1267 ':ipc' => {
1268 hashify(
1269 qw<
1270 msgctl msgget msgrcv msgsnd pipe semctl semget semop shmctl
1271 shmget shmread
1272 >
1273 )
1274 },
1275 ':socket' => {
1276 hashify(
1277 qw<
1278 accept bind connect getsockopt listen recv send setsockopt
1279 shutdown socketpair
1280 >
1281 )
1282 },
1283 ':io' => {
1284 hashify(
1285 qw<
1286 accept bind binmode chdir chmod close closedir connect
1287 dbmclose dbmopen fcntl fileno flock getsockopt ioctl link
1288 listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe
1289 read readlink recv rename rmdir seek semctl semget semop send
1290 setsockopt shmctl shmget shmread shutdown socketpair symlink
1291 sysopen sysread sysseek syswrite truncate umask unlink
1292 >
1293 )
1294 },
1295 ':default' => {
1296 hashify(
1297 qw<
1298 accept bind binmode chdir chmod close closedir connect
1299 dbmclose dbmopen fcntl fileno flock fork getsockopt ioctl link
1300 listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe
1301 read readlink recv rename rmdir seek semctl semget semop send
1302 setsockopt shmctl shmget shmread shutdown socketpair symlink
1303 sysopen sysread sysseek syswrite truncate umask unlink
1304 >
1305 )
1306 },
1307 ':all' => {
1308 hashify(
1309 qw<
1310 accept bind binmode chdir chmod close closedir connect
1311 dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl
1312 link listen mkdir msgctl msgget msgrcv msgsnd open opendir
1313 pipe read readlink recv rename rmdir seek semctl semget semop
1314 send setsockopt shmctl shmget shmread shutdown socketpair
1315 symlink sysopen sysread sysseek system syswrite truncate umask
1316 unlink
1317 >
1318 )
1319 },
1320 );
1321  
1322 13 ▶sub _is_fatal {
Subroutine _is_fatal: called CC=12 SCAR=25.3
1323 13 my ( $elem, $autodie_modules ) = @_;
1324  
1325 13 my $top = $elem->top();
1326 13 ▶ return if not $top->isa('PPI::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless $top->isa("PPI::Document") 0 13 13
1327  
1328 13 my $includes = $top->find('PPI::Statement::Include');
1329 13 ▶ return if not $includes;
Branch: 1 branch
BranchTrueFalseTotal
unless $includes 3 10 13
1330  
1331 10 for my $include (@{$includes}) {
1332 14 ▶ next if 'use' ne $include->type();
Branch: 1 branch
BranchTrueFalseTotal
if "use" ne $include->type 2 12 14
1333  
1334 12 ▶ if ('Fatal' eq $include->module()) {
Branch: 3 branches
BranchTrueFalseTotal
if ('Fatal' eq $include->module) { } 2 10 12
elsif ('Fatal::Exception' eq $include->module) { } 2 8 10
elsif ($include->pragma eq 'autodie' or &any(sub { $_ eq $include->module; } , @{$autodie_modules or [];})) { } 4 4 8
1335 2 my @args = parse_arg_list($include->schild(1));
1336 2 ▶ return $TRUE if any { $_->[0]->isa('PPI::Token::Quote') && $elem eq $_->[0]->string() } @args;
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { $_->[0]->isa("PPI::Token::Quote") and $elem eq $_->[0]->string; } , @args) 2 0 2
$_->[0]->isa("PPI::Token::Quote") and $elem eq $_->[0]->string 2 0 2
1337 }
1338 elsif ('Fatal::Exception' eq $include->module()) {
1339 2 my @args = parse_arg_list($include->schild(1));
1340 2 shift @args; # skip exception class name
1341 2 ▶ return $TRUE if any { $_->[0]->isa('PPI::Token::Quote') && $elem eq $_->[0]->string() } @args;
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
BranchTrueFalseTotal
if &any(sub { $_->[0]->isa("PPI::Token::Quote") and $elem eq $_->[0]->string; } , @args) 2 0 2
$_->[0]->isa("PPI::Token::Quote") and $elem eq $_->[0]->string 2 0 2
1342 }
1343 4 ▶ elsif ($include->pragma eq 'autodie' || any {$_ eq $include->module()} @{$autodie_modules || []}) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Condition60%3/5
$include->pragma eq "autodie" or &any(sub { $_ eq $include->module; } , @{$autodie_modules or [];})
l!l&&r!l&&!r
404
$autodie_modules || []
l!l
40
MC/DC50%1/2
$include->pragma eq "autodie" or &any(sub { $_ eq $include->module; } , @{$autodie_modules or [];})
$include->pragma eq "autodie" &any(sub { $_ eq $include->module; } , @{$autodie_modules or [];})
MC/DC0%0/1
$autodie_modules || []
$autodie_modules
Truth table66%2/3
A or B
A= $include->pragma eq "autodie"B= &any(sub { $_ eq $include->module; } , @{$autodie_modules or [];})
ABresult
1X1
011
000
Truth table50%1/2
A
A= $autodie_modules
Aresult
11
00
1344 4 return _is_covered_by_autodie($elem, $include);
1345 }
1346 }
1347  
1348 2 return;
1349 }
1350  
1351 4 ▶sub _is_covered_by_autodie {
Subroutine _is_covered_by_autodie: called CC=9 SCAR=23.4
1352 4 my ($elem, $include) = @_;
1353  
1354 4 my $autodie = $include->schild(1);
1355 4 my @args = parse_arg_list($autodie);
1356 4 my $first_arg = first_arg($autodie);
1357  
1358 # The first argument to any `use` pragma could be a version number.
1359 # If so, then we just discard it. We only want the arguments after it.
1360 4 ▶ if ($first_arg and $first_arg->isa('PPI::Token::Number')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_arg and $first_arg->isa("PPI::Token::Number")) 0 4 4
Condition33%1/3
$first_arg and $first_arg->isa("PPI::Token::Number")
!ll&&!rl&&r
040
MC/DC0%0/2
$first_arg and $first_arg->isa("PPI::Token::Number")
$first_arg $first_arg->isa("PPI::Token::Number")
Truth table33%1/3
A and B
A= $first_argB= $first_arg->isa("PPI::Token::Number")
ABresult
0X0
100
111
1361 0 shift @args;
1362 }
1363  
1364 4 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 3 1 4
1365 3 my $elem_content = $elem->content();
1366 3 foreach my $arg (@args) {
1367 my $builtins =
1368 $AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{
1369 4 $arg->[0]->string
1370 };
1371  
1372 4 ▶ return $TRUE if $builtins and $builtins->{$elem_content};
Branch: 1 branch
BranchTrueFalseTotal
if $builtins and $builtins->{$elem_content} 2 2 4
Condition66%2/3
$builtins and $builtins->{$elem_content}
!ll&&!rl&&r
022
MC/DC50%1/2
$builtins and $builtins->{$elem_content}
$builtins $builtins->{$elem_content}
Truth table66%2/3
A and B
A= $builtinsB= $builtins->{$elem_content}
ABresult
0X0
100
111
1373 }
1374 }
1375 else {
1376 my $builtins =
1377 1 $AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{':default'};
1378  
1379 1 ▶ return $TRUE if $builtins and $builtins->{$elem->content()};
Branch: 1 branch
BranchTrueFalseTotal
if $builtins and $$builtins{$elem->content} 1 0 1
Condition33%1/3
$builtins and $$builtins{$elem->content}
!ll&&!rl&&r
001
MC/DC0%0/2
$builtins and $$builtins{$elem->content}
$builtins $$builtins{$elem->content}
Truth table33%1/3
A and B
A= $builtinsB= $$builtins{$elem->content}
ABresult
0X0
100
111
1380 }
1381  
1382 1 return;
1383 }
1384  
1385 40 1;
1386  
1387 __END__
« lib/Perl/Critic/Policy/Subroutines/ProtectPrivateSubs.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitLvalueSubstr.pm »