« blib/lib/Perl/Lint/Policy/Subroutines/ProhibitExcessComplexity.pm
↑ Summary
blib/lib/Perl/Lint/Policy/Subroutines/ProhibitManyArgs.pm »
| 1 | package Perl::Lint::Policy::Subroutines::ProhibitExplicitReturnUndef; | ||
| 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 => '"return" statement with explicit "undef"', | ||
| 9 | EXPL => [199], | ||
| 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 ($token_type == RETURN) { | ||
| 20 | my $next_token = $tokens->[++$i]; | ||
| 21 | if ($next_token->{type} == DEFAULT && $next_token->{data} eq 'undef') { | ||
| 22 | push @violations, { | ||
| 23 | filename => $file, | ||
| 24 | line => $token->{line}, | ||
| 25 | description => DESC, | ||
| 26 | explanation => EXPL, | ||
| 27 | policy => __PACKAGE__, | ||
| 28 | }; | ||
| 29 | next; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | return \@violations; | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||