blib/lib/Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.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/InputOutput/ProhibitOneArgSelect.pm ↑ Summary blib/lib/Perl/Lint/Policy/InputOutput/ProhibitTwoArgOpen.pm »
1 package Perl::Lint::Policy::InputOutput::ProhibitReadlineInForLoop;
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 => 'Readline inside "for" loop',
9 EXPL => [211],
10 };
11  
12 sub evaluate {
13 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 my @violations;
16 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 my $token_type = $token->{type};
18  
19 if ($token_type == FOR_STATEMENT || $token_type == FOREACH_STATEMENT) {
20 $i++;
21 $token = $tokens->[$i];
22 $token_type = $token->{type};
23 if ($token_type == DIAMOND || $token_type == LESS) {
24 # ~~~~ XXX should be HandleDecl in fact
25 push @violations, {
26 filename => $file,
27 line => $token->{line},
28 description => DESC,
29 explanation => EXPL,
30 policy => __PACKAGE__,
31 };
32 next;
33 }
34  
35 for (; my $token = $tokens->[$i]; $i++) {
36 $token_type = $token->{type};
37 my $left_paren_num = 0;
38 if ($token_type == LEFT_PAREN) {
39 $left_paren_num++;
40 for ($i++; my $token = $tokens->[$i]; $i++) {
41 $token_type = $token->{type};
42 if ($token_type == LEFT_PAREN) {
43 $left_paren_num++;
44 }
45 elsif ($token_type == RIGHT_PAREN) {
46 last if --$left_paren_num <= 0;
47 }
48 elsif ($token_type == DIAMOND) {
49 push @violations, {
50 filename => $file,
51 line => $token->{line},
52 description => DESC,
53 explanation => EXPL,
54 policy => __PACKAGE__,
55 };
56 }
57 elsif ($token_type == HANDLE_DELIM) {
58 for ($i++; my $token = $tokens->[$i]; $i++) {
59 $token_type = $token->{type};
60 if ($token_type == HANDLE_DELIM) {
61 push @violations, {
62 filename => $file,
63 line => $token->{line},
64 description => DESC,
65 explanation => EXPL,
66 policy => __PACKAGE__,
67 };
68 last;
69 }
70 }
71 }
72 }
73 last;
74 }
75 }
76 }
77 }
78  
79 return \@violations;
80 }
81  
82 1;
83  
« blib/lib/Perl/Lint/Policy/InputOutput/ProhibitOneArgSelect.pm ↑ Summary blib/lib/Perl/Lint/Policy/InputOutput/ProhibitTwoArgOpen.pm »