blib/lib/Perl/Lint/Policy/Variables/ProhibitLocalVars.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 SCAR 0.1
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/ProhibitMatchVars.pm »
1 package Perl::Lint::Policy::Variables::ProhibitLocalVars;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use parent "Perl::Lint::Policy";
6  
7 use constant {
8 DESC => 'The names of or patterns for variables to forbid',
9 EXPL => 'Find an alternative variable',
10 };
11  
12 sub evaluate {
13 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 my @violations;
16 for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
17 $token_type = $token->{type};
18  
19 if ($token_type == LOCAL_DECL) {
20 $token = $tokens->[++$i];
21 $token_type = $token->{type};
22  
23 if ($token_type == LEFT_PAREN) {
24 my $violation;
25 my $left_paren_num = 1;
26 for ($i++; my $token = $tokens->[$i]; $i++) {
27 $token_type = $token->{type};
28 if ($token_type == LEFT_PAREN) {
29 $left_paren_num++;
30 }
31 elsif ($token_type == RIGHT_PAREN) {
32 if (--$left_paren_num <= 0) {
33 if ($violation) {
34 push @violations, $violation;
35 undef $violation;
36 }
37 last;
38 }
39 }
40 elsif ($token_type == GLOBAL_VAR || $token_type == VAR) {
41 if ($token->{data} !~ /\A\$[A-Z_]+\Z/) {
42 my $next_token = $tokens->[$i+1];
43 if ($next_token->{type} != NAMESPACE_RESOLVER) {
44 $violation ||= +{
45 filename => $file,
46 line => $token->{line},
47 description => DESC,
48 explanation => EXPL,
49 policy => __PACKAGE__,
50 };
51 }
52 }
53 }
54 }
55 }
56 elsif ($token_type == GLOBAL_VAR || $token_type == VAR) {
57 if ($token->{data} !~ /\A\$[A-Z_]+\Z/) {
58 my $next_token = $tokens->[$i+1];
59 if ($next_token->{type} != NAMESPACE_RESOLVER) {
60 push @violations, {
61 filename => $file,
62 line => $token->{line},
63 description => DESC,
64 explanation => EXPL,
65 policy => __PACKAGE__,
66 };
67 }
68 }
69 }
70 }
71 }
72  
73 return \@violations;
74 }
75  
76 1;
77  
« blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/ProhibitMatchVars.pm »