File Coverage

blib/lib/Perl/Lint/Policy/Modules/RequireEndWithOne.pm
Criterion Covered Total %
statement 33 34 97.0
branch 5 6 83.3
condition 18 24 75.0
subroutine 7 7 100.0
pod 0 1 0.0
total 63 72 87.5


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Modules::RequireEndWithOne;
2 133     133   99343 use strict;
  133         270  
  133         5061  
3 133     133   597 use warnings;
  133         210  
  133         3555  
4 133     133   1081 use utf8;
  133         211  
  133         1004  
5 133     133   3281 use Perl::Lint::Constants::Type;
  133         245  
  133         84665  
6 133     133   891 use parent "Perl::Lint::Policy";
  133         221  
  133         938  
7              
8             use constant {
9 133         42351 DESC => 'Module does not end with "1;"',
10             EXPL => 'Must end with a recognizable true value',
11 133     133   9484 };
  133         256  
12              
13             sub evaluate {
14 16     16 0 22 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 16         17 my @violations;
17 16 100       36 if ($src =~ /\A#!/) { # for shebang. If
18 1         11 return [];
19             }
20              
21 15         17 my $last_token = $tokens->[-1];
22 15         20 my $last_token_type = $last_token->{type};
23 15         16 my $last_token_data = $last_token->{data};
24 15         15 my $before_last_token = $tokens->[-2];
25 15         13 my $before_last_token_type = $before_last_token->{type};
26 15         14 my $before_last_token_data = $before_last_token->{data};
27 15         15 my $extra_before_token = $tokens->[-3];
28              
29 15 50 33     79 if (!%$last_token || !%$before_last_token) {
30 0         0 return [];
31             }
32              
33 15 100 66     712 if (
      66        
      100        
      100        
      66        
      100        
      66        
34             !(
35             $before_last_token_type == ASSIGN &&
36             $last_token_type == KEY &&
37             $last_token_data eq 'pod'
38             ) &&
39             !(
40             (
41             !$extra_before_token ||
42             $extra_before_token->{type} == SEMI_COLON ||
43             $extra_before_token->{type} == RIGHT_BRACE
44             ) &&
45             $before_last_token_type == INT &&
46             $last_token_type == SEMI_COLON &&
47             eval($before_last_token_data) == 1 ## no critic: to accept bin, oct and hex decimal
48             )
49             ) {
50 5         22 push @violations, {
51             filename => $file,
52             line => $last_token->{line},
53             description => DESC,
54             explanation => EXPL,
55             policy => __PACKAGE__,
56             };
57             }
58              
59 15         72 return \@violations;
60             }
61              
62             1;
63