« blib/lib/Perl/Lint/Policy/Modules/ProhibitEvilModules.pm
↑ Summary
blib/lib/Perl/Lint/Policy/Modules/RequireExplicitPackage.pm »
| 1 | package Perl::Lint::Policy::Modules::RequireEndWithOne; | ||
| 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 utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Perl::Lint::Constants::Type; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use parent "Perl::Lint::Policy"; | ||
| 7 | |||
| 8 | use constant { | ||
| 9 | DESC => 'Module does not end with "1;"', | ||
| 10 | EXPL => 'Must end with a recognizable true value', | ||
| 11 | }; | ||
| 12 | |||
| 13 | sub evaluate { | ||
| 14 | my ($class, $file, $tokens, $src, $args) = @_; | ||
| 15 | |||
| 16 | my @violations; | ||
| 17 | if ($src =~ /\A#!/) { # for shebang. If | ||
| 18 | return []; | ||
| 19 | } | ||
| 20 | |||
| 21 | my $last_token = $tokens->[-1]; | ||
| 22 | my $last_token_type = $last_token->{type}; | ||
| 23 | my $last_token_data = $last_token->{data}; | ||
| 24 | my $before_last_token = $tokens->[-2]; | ||
| 25 | my $before_last_token_type = $before_last_token->{type}; | ||
| 26 | my $before_last_token_data = $before_last_token->{data}; | ||
| 27 | my $extra_before_token = $tokens->[-3]; | ||
| 28 | |||
| 29 | if (!%$last_token || !%$before_last_token) { | ||
| 30 | return []; | ||
| 31 | } | ||
| 32 | |||
| 33 | if ( | ||
| 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 | push @violations, { | ||
| 51 | filename => $file, | ||
| 52 | line => $last_token->{line}, | ||
| 53 | description => DESC, | ||
| 54 | explanation => EXPL, | ||
| 55 | policy => __PACKAGE__, | ||
| 56 | }; | ||
| 57 | } | ||
| 58 | |||
| 59 | return \@violations; | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||