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   68231 use strict;
  133         193  
  133         3064  
3 133     133   428 use warnings;
  133         156  
  133         2428  
4 133     133   778 use Perl::Lint::Constants::Type;
  133         163  
  133         59575  
5 133     133   601 use parent "Perl::Lint::Policy";
  133         184  
  133         595  
6              
7             use constant {
8 133         35294 DESC => 'One-argument "select" used',
9             EXPL => [224],
10 133     133   6623 };
  133         176  
11              
12             sub evaluate {
13 7     7 0 11 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 7         5 my @violations;
16 7         21 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 17         16 my $token_type = $token->{type};
18 17         14 my $token_data = $token->{data};
19              
20 17 100 66     49 if ($token_type == BUILTIN_FUNC && $token_data eq 'select') {
21 10         11 $token = $tokens->[++$i];
22 10         9 $token_type = $token->{type};
23 10 100       16 if ($token_type == LEFT_PAREN) {
24 3         2 my $args_num = 0;
25 3         4 my $left_paren_num = 1;
26 3         6 for ($i++; my $token = $tokens->[$i]; $i++) {
27 12         9 $token_type = $token->{type};
28 12 50       18 if ($token_type == LEFT_PAREN) {
    100          
29 0         0 $left_paren_num++;
30             }
31             elsif ($token_type == RIGHT_PAREN) {
32 3 50       8 last if --$left_paren_num <= 0;
33             }
34             else {
35 9         13 $args_num++;
36             }
37             }
38 3 100       8 if ($args_num == 1) {
39             push @violations, {
40             filename => $file,
41             line => $token->{line},
42 2         13 description => DESC,
43             explanation => EXPL,
44             policy => __PACKAGE__,
45             };
46             }
47             }
48             else {
49 7         4 my $args_num = 0;
50 7         13 for (; my $token = $tokens->[$i]; $i++) {
51 14         13 $token_type = $token->{type};
52 14 100       15 if ($token_type == SEMI_COLON) {
53 7         6 last;
54             }
55             else {
56 7         10 $args_num++;
57             }
58             }
59 7 50       10 if ($args_num == 1) {
60             push @violations, {
61             filename => $file,
62             line => $token->{line},
63 7         27 description => DESC,
64             explanation => EXPL,
65             policy => __PACKAGE__,
66             };
67             }
68             }
69             }
70             }
71              
72 7         20 return \@violations;
73             }
74              
75             1;
76