Perl/Lint/Policy/Subroutines/RequireArgUnpacking.pm

filter: Statementstmt 21.8% 19 / 87 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 1 totaltotal 12.0% 25 / 207 CC 41 SCAR 72.2
CC
41
Cov
11%
evaluate
1640.0
__ANON__
6.0
BEGIN
1.0
CRAP 1367.0
« Perl/Lint/Policy/InputOutput/RequireCheckedClose.pm ↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitUnreachableCode.pm »
1 package Perl::Lint::Policy::Subroutines::RequireArgUnpacking;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Always unpack @_ first',
10 EXPL => [178],
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=40 SCAR=74.0
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my $require_arg_unpacking_arg = $args->{require_arg_unpacking};
17 0 ▶ my $short_subroutine_statements = $require_arg_unpacking_arg->{short_subroutine_statements} || undef;
Condition0%0/2
$require_arg_unpacking_arg->{'short_subroutine_statements'} || undef
l!l
00
MC/DC0%0/1
$require_arg_unpacking_arg->{'short_subroutine_statements'} || undef
$require_arg_unpacking_arg->{'short_subroutine_statements'}
Truth table0%0/2
A
A= $require_arg_unpacking_arg->{'short_subroutine_statements'}
Aresult
11
00
18 0 ▶ my $allow_subscripts = $require_arg_unpacking_arg->{allow_subscripts} || 0;
Condition0%0/2
$require_arg_unpacking_arg->{'allow_subscripts'} || 0
l!l
00
MC/DC0%0/1
$require_arg_unpacking_arg->{'allow_subscripts'} || 0
$require_arg_unpacking_arg->{'allow_subscripts'}
Truth table0%0/2
A
A= $require_arg_unpacking_arg->{'allow_subscripts'}
Aresult
11
00
19 0 ▶ my @allow_delegation_to = split(/ /, $require_arg_unpacking_arg->{allow_delegation_to} || '');
Condition0%0/2
$require_arg_unpacking_arg->{'allow_delegation_to'} || ''
l!l
00
MC/DC0%0/1
$require_arg_unpacking_arg->{'allow_delegation_to'} || ''
$require_arg_unpacking_arg->{'allow_delegation_to'}
Truth table0%0/2
A
A= $require_arg_unpacking_arg->{'allow_delegation_to'}
Aresult
11
00
20  
21 0 my @violations;
22 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
23 0 my $token_type = $token->{type};
24 0 my $next_token = $tokens->[$i+1];
25  
26 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 63 or $token_type == 122 and $next_token->{"type"} == 109) 0 0 0
Condition0%0/6
$token_type == 63 or $token_type == 122 and $next_token->{"type"} == 109
l!l&&r!l&&!r
000
$token_type == 122 and $next_token->{"type"} == 109
!ll&&!rl&&r
000
MC/DC0%0/3
$token_type == 63 or $token_type == 122 and $next_token->{"type"} == 109
$token_type == 63 $token_type == 122 $next_token->{"type"} == 109
Truth table0%0/4
A or B and C
A= $token_type == 63B= $token_type == 122C= $next_token->{"type"} == 109
ABCresult
1XX1
0111
00X0
0100
27 $token_type == FUNCTION_DECL ||
28 ($token_type == KEY && $next_token->{type} == LEFT_BRACE)
29 ) {
30 0 my $function_token = $token;
31 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
32 0 $token_type = $token->{type};
33  
34 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
35 0 my $begin_line = $token->{line};
36  
37 # variable for each line
38 0 my $is_inherited = 0;
39 0 my $package_name = '';
40  
41 0 my $is_violated = 0;
42 0 my $left_brace_num = 1;
43 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
44 0 $token_type = $token->{type};
45 0 my $token_data = $token->{data};
46  
47 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 70 and $token_data eq 'shift') { } 0 0 0
elsif ($token_type == 137 and $token_data eq '$_') { } 0 0 0
elsif ($token_type == 136 and not $allow_subscripts) { } 0 0 0
elsif ($token_type == 127 or $token_type == 64) { } 0 0 0
elsif ($token_type == 126) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
48 0 $left_brace_num++;
49 }
50 elsif ($token_type == RIGHT_BRACE) {
51 0 ▶ if (--$left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_brace_num <= 0) 0 0 0
52 0 my $end_line = $token->{line};
53 0 ▶ if ($is_violated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_violated) 0 0 0
54 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $short_subroutine_statements or $end_line - $begin_line - 1 > $short_subroutine_statements) 0 0 0
Condition0%0/3
not defined $short_subroutine_statements or $end_line - $begin_line - 1 > $short_subroutine_statements
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $short_subroutine_statements or $end_line - $begin_line - 1 > $short_subroutine_statements
not defined $short_subroutine_statements $end_line - $begin_line - 1 > $short_subroutine_statements
Truth table0%0/3
not(A) or B
A= not defined $short_subroutine_statementsB= $end_line - $begin_line - 1 > $short_subroutine_statements
ABresult
1X1
011
000
55 not(defined $short_subroutine_statements) ||
56 (($end_line - $begin_line - 1) > $short_subroutine_statements)
57 ) {
58 push @violations, {
59 filename => $file,
60 line => $function_token->{line},
61 0 description => DESC,
62 explanation => EXPL,
63 policy => __PACKAGE__,
64 };
65 }
66 }
67 0 last;
68 }
69 }
70 ▶ elsif ($token_type == BUILTIN_FUNC && $token_data eq 'shift') {
Condition0%0/3
$token_type == 70 and $token_data eq "shift"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token_data eq "shift"
$token_type == 70 $token_data eq "shift"
Truth table0%0/3
A and B
A= $token_type == 70B= $token_data eq "shift"
ABresult
0X0
100
111
71 0 $token = $tokens->[++$i];
72 0 $token_type = $token->{type};
73 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 0 0
74 0 $token = $tokens->[++$i];
75 0 $token_type = $token->{type};
76 }
77 0 ▶ if ($token_type == ARGUMENT_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 136) 0 0 0
78 0 $is_violated = 1;
79 }
80 }
81 ▶ elsif ($token_type == SPECIFIC_VALUE && $token_data eq '$_') {
Condition0%0/3
$token_type == 137 and $token_data eq "\$_"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 137 and $token_data eq "\$_"
$token_type == 137 $token_data eq "\$_"
Truth table0%0/3
A and B
A= $token_type == 137B= $token_data eq "\$_"
ABresult
0X0
100
111
82 0 $token = $tokens->[++$i];
83 0 $token_type = $token->{type};
84 0 ▶ if ($token_type == LEFT_BRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 111) 0 0 0
85 0 $token = $tokens->[++$i];
86 0 $token_type = $token->{type};
87 0 ▶ if ($token_type == INT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 170) 0 0 0
88 0 $is_violated = 1;
89 }
90 }
91 }
92 ▶ elsif ($token_type == ARGUMENT_ARRAY && !$allow_subscripts) {
Condition0%0/3
$token_type == 136 and not $allow_subscripts
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 136 and not $allow_subscripts
$token_type == 136 not $allow_subscripts
Truth table0%0/3
A and not(B)
A= $token_type == 136B= not $allow_subscripts
ABresult
0X0
100
111
93 0 $token = $tokens->[++$i];
94 0 $token_type = $token->{type};
95 0 ▶ if ($token_type == LEFT_BRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 111) 0 0 0
96 0 $is_violated = 1;
97 }
98 }
99 ▶ elsif ($token_type == NAMESPACE || $token_type == METHOD) {
Condition0%0/3
$token_type == 127 or $token_type == 64
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 127 or $token_type == 64
$token_type == 127 $token_type == 64
Truth table0%0/3
A or B
A= $token_type == 127B= $token_type == 64
ABresult
1X1
011
000
100 0 ▶ if ($is_inherited || $token_data eq 'NEXT' || $token_data eq 'SUPER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_inherited or $token_data eq "NEXT" or $token_data eq "SUPER") 0 0 0
Condition0%0/6
$is_inherited or $token_data eq "NEXT" or $token_data eq "SUPER"
l!l&&r!l&&!r
000
$is_inherited or $token_data eq "NEXT"
l!l&&r!l&&!r
000
MC/DC0%0/3
$is_inherited or $token_data eq "NEXT" or $token_data eq "SUPER"
$is_inherited $token_data eq "NEXT" $token_data eq "SUPER"
Truth table0%0/4
A or B or C
A= $is_inheritedB= $token_data eq "NEXT"C= $token_data eq "SUPER"
ABCresult
1XX1
01X1
0011
0000
101 0 $is_inherited = 1;
102 0 $package_name .= $token_data;
103 0 next;
104 }
105  
106 0 my $next_token = $tokens->[$i+1];
107 0 my $next_token_type = $next_token->{type};
108 0 ▶ if ($next_token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type == 107) 0 0 0
109 0 $next_token = $tokens->[$i+2];
110 0 $next_token_type = $next_token->{type};
111 }
112 0 ▶ if ($next_token_type == ARGUMENT_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type == 136) 0 0 0
113 0 ▶ if (@allow_delegation_to && any {$_ eq $package_name || $_ eq $token_data} @allow_delegation_to) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if (@allow_delegation_to and &any(sub { $_ eq $package_name or $_ eq $token_data; } , @allow_delegation_to)) 0 0 0
$_ eq $package_name or $_ eq $token_data 0 0 0
Condition0%0/3
@allow_delegation_to and &any(sub { $_ eq $package_name or $_ eq $token_data; } , @allow_delegation_to)
!ll&&!rl&&r
000
MC/DC0%0/2
@allow_delegation_to and &any(sub { $_ eq $package_name or $_ eq $token_data; } , @allow_delegation_to)
@allow_delegation_to &any(sub { $_ eq $package_name or $_ eq $token_data; } , @allow_delegation_to)
Truth table0%0/3
A and B
A= @allow_delegation_toB= &any(sub { $_ eq $package_name or $_ eq $token_data; } , @allow_delegation_to)
ABresult
0X0
100
111
114 0 next;
115 }
116 0 $is_violated = 1;
117 }
118 0 $package_name .= $token_data;
119 }
120 elsif ($token_type == NAMESPACE_RESOLVER) {
121 0 $package_name .= $token_data;
122 }
123 elsif ($token_type == SEMI_COLON) {
124 0 $is_inherited = 0;
125 0 $package_name = '';
126 }
127 }
128 }
129 elsif ($token_type == SEMI_COLON) {
130 0 last;
131 }
132 }
133 }
134 }
135  
136 0 return \@violations;
137 }
138  
139 2 1;
140  
« Perl/Lint/Policy/InputOutput/RequireCheckedClose.pm ↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitUnreachableCode.pm »