blib/lib/Perl/Lint/Policy/Variables/RequireInitializationForLocalVars.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/Variables/ProtectPrivateVars.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/RequireLexicalLoopIterators.pm »
1 package Perl::Lint::Policy::Variables::RequireInitializationForLocalVars;
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 => '"local" variable not initialized',
9 EXPL => [78],
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 $left_paren_num = 1;
25 for ($i++; $token = $tokens->[$i]; $i++) {
26 $token_type = $token->{type};
27  
28 if ($token_type == LEFT_PAREN) {
29 $left_paren_num++;
30 }
31 elsif ($token_type == RIGHT_PAREN) {
32 last if --$left_paren_num <= 0;
33 }
34 }
35 }
36  
37 $token = $tokens->[++$i];
38 $token_type = $token->{type};
39  
40 if ($token_type != ASSIGN) {
41 push @violations, {
42 filename => $file,
43 line => $token->{line},
44 description => DESC,
45 explanation => EXPL,
46 policy => __PACKAGE__,
47 };
48 }
49 }
50 }
51  
52 return \@violations;
53 }
54  
55 1;
56  
« blib/lib/Perl/Lint/Policy/Variables/ProtectPrivateVars.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/RequireLexicalLoopIterators.pm »