« 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
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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $allow_subscripts = $require_arg_unpacking_arg->{allow_subscripts} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$require_arg_unpacking_arg->{'allow_subscripts'} || 0
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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my @allow_delegation_to = split(/ /, $require_arg_unpacking_arg->{allow_delegation_to} || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$require_arg_unpacking_arg->{'allow_delegation_to'} || ''
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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$token_type == 63 or $token_type == 122 and $next_token->{"type"} == 109
$token_type == 122 and $next_token->{"type"} == 109
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $left_brace_num++; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (--$left_brace_num <= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $end_line = $token->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($is_violated) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $short_subroutine_statements or $end_line - $begin_line - 1 > $short_subroutine_statements
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($token_type == ARGUMENT_ARRAY) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 "\$_"
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 "\$_"
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($token_type == LEFT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($token_type == INT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($token_type == LEFT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($is_inherited || $token_data eq 'NEXT' || $token_data eq 'SUPER') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$is_inherited or $token_data eq "NEXT" or $token_data eq "SUPER"
$is_inherited or $token_data eq "NEXT"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@allow_delegation_to and &any(sub {
$_ eq $package_name or $_ eq $token_data;
}
, @allow_delegation_to)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||