« blib/lib/Perl/Lint/Policy/TestingAndDebugging/RequireTestLabels.pm
↑ Summary
blib/lib/Perl/Lint/Policy/TestingAndDebugging/RequireUseWarnings.pm »
| 1 | package Perl::Lint::Policy::TestingAndDebugging::RequireUseStrict; | ||
| 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 List::Util qw/any/; |
|
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 EQUIVALENT_PERL_VERSION => 5.011; | ||
| 9 | |||
| 10 | use constant { | ||
| 11 | DESC => 'Code before strictures are enabled', | ||
| 12 | EXPL => [429], | ||
| 13 | }; | ||
| 14 | |||
| 15 | sub evaluate { | ||
| 16 | my ($class, $file, $tokens, $src, $args) = @_; | ||
| 17 | |||
| 18 | my @marshals = ('strict', 'Moose', 'Moose::Role', 'Moose::Util::TypeConstraints'); | ||
| 19 | if (my $this_policies_arg = $args->{require_use_strict}) { | ||
| 20 | push @marshals, split / /, ($this_policies_arg->{equivalent_modules} || ''); | ||
| 21 | } | ||
| 22 | |||
| 23 | my @violations; | ||
| 24 | my $token_num = scalar @$tokens; | ||
| 25 | my $is_used_strict = 0; | ||
| 26 | TOP: for (my $i = 0; $i < $token_num; $i++) { | ||
| 27 | my $token = $tokens->[$i]; | ||
| 28 | my $token_type = $token->{type}; | ||
| 29 | |||
| 30 | if ($token_type == USE_DECL) { | ||
| 31 | my $next_token = $tokens->[$i+1]; | ||
| 32 | if ($next_token->{type} == DOUBLE) { | ||
| 33 | (my $next_token_data = $next_token->{data}) =~ s/_//g; | ||
| 34 | if ($next_token_data >= EQUIVALENT_PERL_VERSION) { | ||
| 35 | last; | ||
| 36 | } | ||
| 37 | next; | ||
| 38 | } | ||
| 39 | |||
| 40 | my $used_module = ''; | ||
| 41 | for ($i++; $i < $token_num; $i++) { | ||
| 42 | $token = $tokens->[$i]; | ||
| 43 | my $token_type = $token->{type}; | ||
| 44 | my $token_data = $token->{data}; | ||
| 45 | if ( | ||
| 46 | $token_type == USED_NAME || | ||
| 47 | $token_type == NAMESPACE || | ||
| 48 | $token_type == NAMESPACE_RESOLVER | ||
| 49 | ) { | ||
| 50 | $used_module .= $token_data; | ||
| 51 | } | ||
| 52 | else { | ||
| 53 | if (any {$_ eq $used_module} @marshals) { | ||
| 54 | last TOP; | ||
| 55 | } | ||
| 56 | next TOP; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | if ($token_type == PACKAGE) { | ||
| 62 | for ($i++; $i < $token_num; $i++) { | ||
| 63 | $token = $tokens->[$i]; | ||
| 64 | if ($token->{type} == SEMI_COLON) { | ||
| 65 | next TOP; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | push @violations, { | ||
| 71 | filename => $file, | ||
| 72 | line => $token->{line}, | ||
| 73 | description => DESC, | ||
| 74 | explanation => EXPL, | ||
| 75 | policy => __PACKAGE__, | ||
| 76 | }; | ||
| 77 | last; | ||
| 78 | } | ||
| 79 | |||
| 80 | return \@violations; | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; | ||
| 84 | |||