« Perl/Lint/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm
↑ Summary
Perl/Lint/Policy/Subroutines/ProhibitBuiltinHomonyms.pm »
| 1 | package Perl::Lint::Policy::ControlStructures::ProhibitPostfixControls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 List::Util qw/any/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Perl::Lint::Constants::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | DESC => 'Postfix control "%s" used', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | EXPL => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | &IF_STATEMENT => [93, 94], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | &UNLESS_STATEMENT => [96, 97], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | &UNTIL_STATEMENT => [96, 97], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | &FOR_STATEMENT => [96], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | &FOREACH_STATEMENT => [96], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | &WHILE_STATEMENT => [96], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | &WHEN_STATEMENT => q<Similar to "if", postfix "when" should only be used with flow-control>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | my %control_statement_tokens = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | &IF_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | &UNLESS_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | &UNTIL_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | &FOR_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | &FOREACH_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | &WHILE_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | &WHEN_STATEMENT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my %like_flow_control_function_tokens = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | &GOTO => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | &RETURN => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | &NEXT => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | &LAST => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | &REDO => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my %flow_control_statements = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | exit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | die => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | warn => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | carp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | croak => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | cluck => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | confess => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | exit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=23 SCAR=42.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my @allow = split /\s+/, ($args->{prohibit_postfix_controls}->{allow} || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'prohibit_postfix_controls'}{'allow'} || ''
MC/DC0%0/1
$args->{'prohibit_postfix_controls'}{'allow'} || ''
$args->{'prohibit_postfix_controls'}{'allow'}
Truth table50%1/2
A
A= $args->{'prohibit_postfix_controls'}{'allow'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | my @flowcontrol = split /\s+/, ($args->{prohibit_postfix_controls}->{flowcontrol} || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'prohibit_postfix_controls'}{'flowcontrol'} || ''
MC/DC0%0/1
$args->{'prohibit_postfix_controls'}{'flowcontrol'} || ''
$args->{'prohibit_postfix_controls'}{'flowcontrol'}
Truth table50%1/2
A
A= $args->{'prohibit_postfix_controls'}{'flowcontrol'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | if (@flowcontrol) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | undef %flow_control_statements; # override | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | for my $flowcontrol (@flowcontrol) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $flow_control_statements{$flowcontrol} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | my $is_postfix = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 51 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 51 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 51 | ▶ | if ($token_type == SEMI_COLON || $token_type == LEFT_BRACE || $token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$token_type == 106 or $token_type == 109 or $token_type == 110
$token_type == 106 or $token_type == 109
MC/DC100%3/3
$token_type == 106 or $token_type == 109 or $token_type == 110
$token_type == 106
$token_type == 109
$token_type == 110
Truth table100%4/4
A or B or C
A= $token_type == 106B= $token_type == 109C= $token_type == 110
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | $is_postfix = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 38 | ▶ | if ($is_postfix && $control_statement_tokens{$token_type}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_postfix and $control_statement_tokens{$token_type}
MC/DC0%0/2
$is_postfix and $control_statement_tokens{$token_type}
$is_postfix
$control_statement_tokens{$token_type}
Truth table66%2/3
A and B
A= $is_postfixB= $control_statement_tokens{$token_type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (any {$_ eq $token_data} @allow) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | description => sprintf(DESC, $token_data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | explanation => EXPL->{$token_type}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 38 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$token_type == 70 or $token_type == 122 or $token_type == 125 or $like_flow_control_function_tokens{$token_type}
$token_type == 70 or $token_type == 122 or $token_type == 125
$token_type == 70 or $token_type == 122
MC/DC25%1/4
$token_type == 70 or $token_type == 122 or $token_type == 125 or $like_flow_control_function_tokens{$token_type}
$token_type == 70
$token_type == 122
$token_type == 125
$like_flow_control_function_tokens{$token_type}
Truth table40%2/5
A or B or C or D
A= $token_type == 70B= $token_type == 122C= $token_type == 125D= $like_flow_control_function_tokens{$token_type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $token_type == BUILTIN_FUNC || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | $token_type == KEY || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | $token_type == POINTER || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $like_flow_control_function_tokens{$token_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$token_type == 125 or $like_flow_control_function_tokens{$token_type} or $flow_control_statements{$token_data}
$token_type == 125 or $like_flow_control_function_tokens{$token_type}
MC/DC0%0/3
$token_type == 125 or $like_flow_control_function_tokens{$token_type} or $flow_control_statements{$token_data}
$token_type == 125
$like_flow_control_function_tokens{$token_type}
$flow_control_statements{$token_data}
Truth table25%1/4
A or B or C
A= $token_type == 125B= $like_flow_control_function_tokens{$token_type}C= $flow_control_statements{$token_data}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | $token_type == POINTER || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | $like_flow_control_function_tokens{$token_type} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | $flow_control_statements{$token_data} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$token_type == 106 or $token_type == 109 or $control_statement_tokens{$token_type}
$token_type == 106 or $token_type == 109
MC/DC0%0/3
$token_type == 106 or $token_type == 109 or $control_statement_tokens{$token_type}
$token_type == 106
$token_type == 109
$control_statement_tokens{$token_type}
Truth table0%0/4
A or B or C
A= $token_type == 106B= $token_type == 109C= $control_statement_tokens{$token_type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $token_type == SEMI_COLON || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $token_type == LEFT_BRACE || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | $control_statement_tokens{$token_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 37 | $is_postfix = 1; # other tokens has came | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||