« blib/lib/Perl/Lint/Policy/Subroutines/RequireArgUnpacking.pm
↑ Summary
blib/lib/Perl/Lint/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm »
| 1 | package Perl::Lint::Policy::TestingAndDebugging::ProhibitNoStrict; | ||
| 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 => 'Stricture disabled', | ||
| 10 | EXPL => [429], | ||
| 11 | }; | ||
| 12 | |||
| 13 | sub evaluate { | ||
| 14 | my ($class, $file, $tokens, $src, $args) = @_; | ||
| 15 | |||
| 16 | my @arg_allows; | ||
| 17 | if (my $this_policies_arg = $args->{prohibit_no_strict}) { | ||
| 18 | if (my $allow = $this_policies_arg->{allow}) { | ||
| 19 | @arg_allows = map { lc $_ } split(/[\s,]/, $allow); | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | my @violations; | ||
| 24 | my $token_num = scalar @$tokens; | ||
| 25 | for (my $i = 0; $i < $token_num; $i++) { | ||
| 26 | my $token = $tokens->[$i]; | ||
| 27 | my $token_type = $token->{type}; | ||
| 28 | |||
| 29 | if ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') { | ||
| 30 | $token = $tokens->[++$i]; | ||
| 31 | |||
| 32 | my @allows; | ||
| 33 | if ($token->{type} == KEY && $token->{data} eq 'strict') { | ||
| 34 | for ($i++; $i < $token_num; $i++) { | ||
| 35 | $token = $tokens->[$i]; | ||
| 36 | $token_type = $token->{type}; | ||
| 37 | |||
| 38 | if ($token_type == STRING || $token_type == RAW_STRING) { | ||
| 39 | push @allows, $token->{data}; | ||
| 40 | } | ||
| 41 | elsif ($token_type == REG_EXP) { | ||
| 42 | push @allows, split(/ /, $token->{data}); | ||
| 43 | } | ||
| 44 | elsif ($token_type == SEMI_COLON || !$tokens->[$i+1]) { | ||
| 45 | for my $arg_allow (@arg_allows) { | ||
| 46 | @allows = grep { $_ ne $arg_allow } @allows; | ||
| 47 | } | ||
| 48 | if (!@arg_allows || @allows) { | ||
| 49 | push @violations, { | ||
| 50 | filename => $file, | ||
| 51 | line => $token->{line}, | ||
| 52 | description => DESC, | ||
| 53 | explanation => EXPL, | ||
| 54 | policy => __PACKAGE__, | ||
| 55 | }; | ||
| 56 | last; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | return \@violations; | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; | ||
| 68 | |||