blib/lib/Perl/Lint/Policy/InputOutput/ProhibitOneArgSelect.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/ProhibitJoinedReadline.pm ↑ Summary blib/lib/Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm »
1 package Perl::Lint::Policy::InputOutput::ProhibitOneArgSelect;
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 => 'One-argument "select" used',
9 EXPL => [224],
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 my $token_data = $token->{data};
19  
20 if ($token_type == BUILTIN_FUNC && $token_data eq 'select') {
21 $token = $tokens->[++$i];
22 $token_type = $token->{type};
23 if ($token_type == LEFT_PAREN) {
24 my $args_num = 0;
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 last if --$left_paren_num <= 0;
33 }
34 else {
35 $args_num++;
36 }
37 }
38 if ($args_num == 1) {
39 push @violations, {
40 filename => $file,
41 line => $token->{line},
42 description => DESC,
43 explanation => EXPL,
44 policy => __PACKAGE__,
45 };
46 }
47 }
48 else {
49 my $args_num = 0;
50 for (; my $token = $tokens->[$i]; $i++) {
51 $token_type = $token->{type};
52 if ($token_type == SEMI_COLON) {
53 last;
54 }
55 else {
56 $args_num++;
57 }
58 }
59 if ($args_num == 1) {
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 return \@violations;
73 }
74  
75 1;
76  
« blib/lib/Perl/Lint/Policy/InputOutput/ProhibitJoinedReadline.pm ↑ Summary blib/lib/Perl/Lint/Policy/InputOutput/ProhibitReadlineInForLoop.pm »