File Coverage

blib/lib/Perl/Lint/Policy/BuiltinFunctions/ProhibitStringySplit.pm
Criterion Covered Total %
statement 32 32 100.0
branch 10 10 100.0
condition 12 12 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 60 61 98.3


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::BuiltinFunctions::ProhibitStringySplit;
2 134     134   93652 use strict;
  134         287  
  134         4935  
3 134     134   664 use warnings;
  134         238  
  134         3522  
4 134     134   1000 use Perl::Lint::Constants::Type;
  134         227  
  134         82300  
5 134     134   853 use parent "Perl::Lint::Policy";
  134         239  
  134         969  
6              
7             use constant {
8 134         40950 DESC => 'String delimiter used with "split"',
9             EXPL => 'Express it as a regex instead',
10 134     134   20420 };
  134         294  
11              
12             sub evaluate {
13 7     7 0 23 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 7         15 my @violations;
16 7         43 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 312         315 my $token_type = $token->{type};
18 312         342 my $token_data = $token->{data};
19              
20 312 100 100     992 if ($token_type == BUILTIN_FUNC && $token_data eq 'split') {
21 55         69 $token = $tokens->[++$i];
22              
23 55 100       197 if ($token->{type} == LEFT_PAREN) {
24 28         36 $token = $tokens->[++$i];
25             }
26              
27 55         68 $token_type = $token->{type};
28 55         69 $token_data = $token->{data};
29              
30 55 100 100     367 if (
    100 100        
      100        
31             ($token_type == STRING || $token_type == RAW_STRING) &&
32             $token_data ne ' '
33             ) {
34 17         101 push @violations, {
35             filename => $file,
36             line => $token->{line},
37             description => DESC,
38             explanation => EXPL,
39             policy => __PACKAGE__,
40             };
41             }
42             elsif ($token_type == REG_QUOTE || $token_type == REG_DOUBLE_QUOTE) {
43 18         20 $i += 2;
44 18 100       54 if ($tokens->[$i]->{data} ne ' ') {
45 12         64 push @violations, {
46             filename => $file,
47             line => $token->{line},
48             description => DESC,
49             explanation => EXPL,
50             policy => __PACKAGE__,
51             };
52             }
53             }
54             }
55             }
56              
57 7         48 return \@violations;
58             }
59              
60             1;
61