« Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm
↑ Summary
Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm »
| 1 | package Perl::Lint::Policy::Variables::ProhibitLocalVars; | ||||||||||||||||||||
| 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 Perl::Lint::Constants::Type; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use constant { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | DESC => 'The names of or patterns for variables to forbid', | |||||||||||||||||||
| 9 | EXPL => 'Find an alternative variable', | ||||||||||||||||||||
| 10 | 3 | }; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | sub evaluate { | ||||||||||||||||||
|
Subroutine
evaluate: called CC=18 SCAR=54.1
Pod
undocumented
| |||||||||||||||||||||
| 13 | 2 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | my @violations; | |||||||||||||||||||
| 16 | 2 | ▶ | for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 51 | $token_type = $token->{type}; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 51 | ▶ | if ($token_type == LOCAL_DECL) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||
| 21 | 0 | $token_type = $token->{type}; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 24 | 0 | my $violation; | |||||||||||||||||||
| 25 | 0 | my $left_paren_num = 1; | |||||||||||||||||||
| 26 | 0 | ▶ | for ($i++; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 0 | $token_type = $token->{type}; | |||||||||||||||||||
| 28 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 29 | 0 | $left_paren_num++; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | elsif ($token_type == RIGHT_PAREN) { | ||||||||||||||||||||
| 32 | 0 | ▶ | if (--$left_paren_num <= 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | ▶ | if ($violation) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | push @violations, $violation; | |||||||||||||||||||
| 35 | 0 | undef $violation; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | 0 | last; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | ▶ | elsif ($token_type == GLOBAL_VAR || $token_type == VAR) { | |||||||||||||||||||
|
Condition0%0/3
$token_type == 194 or $token_type == 166
MC/DC0%0/2
$token_type == 194 or $token_type == 166
$token_type == 194
$token_type == 166
Truth table0%0/3
A or B
A= $token_type == 194B= $token_type == 166
| |||||||||||||||||||||
| 41 | 0 | ▶ | if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||
| 43 | 0 | ▶ | if ($next_token->{type} != NAMESPACE_RESOLVER) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | $violation ||= +{ | ||||||||||||||||||||
| 45 | filename => $file, | ||||||||||||||||||||
| 46 | line => $token->{line}, | ||||||||||||||||||||
| 47 | 0 | ▶ | description => DESC, | ||||||||||||||||||
|
Condition0%0/2
$violation ||= {"filename", $file, "line", $token->{"line"}, "description", "The names of or patterns for variables to forbid", "explanation", "Find an alternative variable", "policy", __PACKAGE__}
MC/DC0%0/1
$violation ||= {"filename", $file, "line", $token->{"line"}, "description", "The names of or patterns for variables to forbid", "explanation", "Find an alternative variable", "policy", __PACKAGE__}
$violation
Truth table0%0/2
A
A= $violation
| |||||||||||||||||||||
| 48 | explanation => EXPL, | ||||||||||||||||||||
| 49 | policy => __PACKAGE__, | ||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | ▶ | elsif ($token_type == GLOBAL_VAR || $token_type == VAR) { | |||||||||||||||||||
|
Condition0%0/3
$token_type == 194 or $token_type == 166
MC/DC0%0/2
$token_type == 194 or $token_type == 166
$token_type == 194
$token_type == 166
Truth table0%0/3
A or B
A= $token_type == 194B= $token_type == 166
| |||||||||||||||||||||
| 57 | 0 | ▶ | if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||
| 59 | 0 | ▶ | if ($next_token->{type} != NAMESPACE_RESOLVER) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | push @violations, { | ||||||||||||||||||||
| 61 | filename => $file, | ||||||||||||||||||||
| 62 | line => $token->{line}, | ||||||||||||||||||||
| 63 | 0 | description => DESC, | |||||||||||||||||||
| 64 | explanation => EXPL, | ||||||||||||||||||||
| 65 | policy => __PACKAGE__, | ||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 2 | return \@violations; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 3 | 1; | |||||||||||||||||||
| 77 | |||||||||||||||||||||