File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitVersionStrings.pm
Criterion Covered Total %
statement 27 27 100.0
branch 8 8 100.0
condition 12 12 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 53 54 98.1


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::ProhibitVersionStrings;
2 133     133   92610 use strict;
  133         258  
  133         4635  
3 133     133   599 use warnings;
  133         204  
  133         3457  
4 133     133   1009 use Perl::Lint::Constants::Type;
  133         206  
  133         82988  
5 133     133   755 use parent "Perl::Lint::Policy";
  133         215  
  133         749  
6              
7             use constant {
8 133         34854 DESC => 'Version string used',
9             EXPL => 'Use a real number instead',
10 133     133   8862 };
  133         248  
11              
12             sub evaluate {
13 5     5 0 11 my ($class, $file, $tokens, $args) = @_;
14              
15 5         7 my @violations;
16 5         23 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 200         222 my $token_type = $token->{type};
18              
19 200 100 100     1712 if (
      100        
      100        
      100        
20             $token_type == USE_DECL ||
21             $token_type == USED_NAME ||
22             $token_type == NAMESPACE ||
23             $token_type == REQUIRE_DECL ||
24             $token_type == REQUIRED_NAME
25             ) {
26 62         87 $token_type = $tokens->[$i+1]->{type};
27              
28 62 100       173 if ($token_type == DOUBLE) {
    100          
29 17         26 $token_type = $tokens->[$i+2]->{type};
30 17 100       44 if ($token_type == DOUBLE) {
31 11         69 push @violations, {
32             filename => $file,
33             line => $token->{line},
34             description => DESC,
35             explanation => EXPL,
36             policy => __PACKAGE__,
37             };
38             }
39             }
40             elsif ($token_type == VERSION_STRING) {
41 12         62 push @violations, {
42             filename => $file,
43             line => $token->{line},
44             description => DESC,
45             explanation => EXPL,
46             policy => __PACKAGE__,
47             };
48             }
49             }
50              
51             }
52              
53 5         29 return \@violations;
54             }
55              
56             1;
57