« blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitSpecialHeredocTerminator.pm
↑ Summary
blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireConstantVersion.pm »
| 1 | package Perl::Lint::Policy::ValuesAndExpressions::ProhibitVersionStrings; | ||
| 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 Perl::Lint::Constants::Type; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | use parent "Perl::Lint::Policy"; | ||
| 6 | |||
| 7 | use constant { | ||
| 8 | DESC => 'Version string used', | ||
| 9 | EXPL => 'Use a real number instead', | ||
| 10 | }; | ||
| 11 | |||
| 12 | sub evaluate { | ||
| 13 | my ($class, $file, $tokens, $args) = @_; | ||
| 14 | |||
| 15 | my @violations; | ||
| 16 | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||
| 17 | my $token_type = $token->{type}; | ||
| 18 | |||
| 19 | if ( | ||
| 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 | $token_type = $tokens->[$i+1]->{type}; | ||
| 27 | |||
| 28 | if ($token_type == DOUBLE) { | ||
| 29 | $token_type = $tokens->[$i+2]->{type}; | ||
| 30 | if ($token_type == DOUBLE) { | ||
| 31 | 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 | 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 | return \@violations; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||