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