File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitImplicitNewlines.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 4 100.0
condition 6 6 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::ProhibitImplicitNewlines;
2 133     133   138139 use strict;
  133         291  
  133         5842  
3 133     133   682 use warnings;
  133         216  
  133         4353  
4 133     133   1181 use Perl::Lint::Constants::Type;
  133         206  
  133         93882  
5 133     133   857 use parent "Perl::Lint::Policy";
  133         236  
  133         1167  
6              
7             use constant {
8 133         32473 DESC => 'Literal line breaks in a string',
9             EXPL => [60, 61],
10 133     133   9844 };
  133         341  
11              
12             sub evaluate {
13 4     4 0 9 my ($class, $file, $tokens, $args) = @_;
14              
15 4         8 my @violations;
16 4         17 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 110         94 my $token_type = $token->{type};
18 110 100 100     549 if (
      100        
19             $token_type == STRING ||
20             $token_type == RAW_STRING ||
21             $token_type == REG_EXP
22             ) {
23 18         22 my $string = $token->{data};
24 18 100       54 if ($string =~ /\r?\n/) {
25 10         154 push @violations, {
26             filename => $file,
27             line => $token->{line},
28             description => DESC,
29             explanation => EXPL,
30             policy => __PACKAGE__,
31             };
32             }
33             }
34             }
35              
36 4         21 return \@violations;
37             }
38              
39             1;
40