File Coverage

blib/lib/Perl/Lint/Policy/InputOutput/ProhibitOneArgSelect.pm
Criterion Covered Total %
statement 42 43 97.6
branch 13 16 81.2
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 63 69 91.3


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::InputOutput::ProhibitOneArgSelect;
2 133     133   90451 use strict;
  133         272  
  133         5215  
3 133     133   717 use warnings;
  133         226  
  133         3343  
4 133     133   1043 use Perl::Lint::Constants::Type;
  133         211  
  133         81856  
5 133     133   827 use parent "Perl::Lint::Policy";
  133         223  
  133         849  
6              
7             use constant {
8 133         46779 DESC => 'One-argument "select" used',
9             EXPL => [224],
10 133     133   9263 };
  133         262  
11              
12             sub evaluate {
13 7     7 0 19 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 7         10 my @violations;
16 7         36 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 17         25 my $token_type = $token->{type};
18 17         27 my $token_data = $token->{data};
19              
20 17 100 66     75 if ($token_type == BUILTIN_FUNC && $token_data eq 'select') {
21 10         20 $token = $tokens->[++$i];
22 10         16 $token_type = $token->{type};
23 10 100       25 if ($token_type == LEFT_PAREN) {
24 3         6 my $args_num = 0;
25 3         5 my $left_paren_num = 1;
26 3         15 for ($i++; my $token = $tokens->[$i]; $i++) {
27 12         16 $token_type = $token->{type};
28 12 50       29 if ($token_type == LEFT_PAREN) {
    100          
29 0         0 $left_paren_num++;
30             }
31             elsif ($token_type == RIGHT_PAREN) {
32 3 50       15 last if --$left_paren_num <= 0;
33             }
34             else {
35 9         20 $args_num++;
36             }
37             }
38 3 100       13 if ($args_num == 1) {
39 2         19 push @violations, {
40             filename => $file,
41             line => $token->{line},
42             description => DESC,
43             explanation => EXPL,
44             policy => __PACKAGE__,
45             };
46             }
47             }
48             else {
49 7         8 my $args_num = 0;
50 7         29 for (; my $token = $tokens->[$i]; $i++) {
51 14         17 $token_type = $token->{type};
52 14 100       25 if ($token_type == SEMI_COLON) {
53 7         14 last;
54             }
55             else {
56 7         19 $args_num++;
57             }
58             }
59 7 50       15 if ($args_num == 1) {
60 7         54 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 7         35 return \@violations;
73             }
74              
75             1;
76