« blib/lib/Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm
↑ Summary
blib/lib/Perl/Lint/Policy/BuiltinFunctions/ProhibitReverseSortBlock.pm »
| 1 | package Perl::Lint::Policy::BuiltinFunctions::ProhibitLvalueSubstr; | ||
| 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 => 'Lvalue form of "substr" used', | ||
| 9 | EXPL => [165], | ||
| 10 | }; | ||
| 11 | |||
| 12 | sub evaluate { | ||
| 13 | my ($class, $file, $tokens, $src, $args) = @_; | ||
| 14 | |||
| 15 | my @violations; | ||
| 16 | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||
| 17 | my $token_type = $token->{type}; | ||
| 18 | my $token_data = $token->{data}; | ||
| 19 | |||
| 20 | if ($token_type == BUILTIN_FUNC && $token_data eq 'substr') { | ||
| 21 | $token = $tokens->[++$i]; | ||
| 22 | if ($token->{type} == LEFT_PAREN) { | ||
| 23 | my $left_paren_num = 1; | ||
| 24 | for ($i++; my $token = $tokens->[$i]; $i++) { | ||
| 25 | $token = $tokens->[++$i]; | ||
| 26 | $token_type = $token->{type}; | ||
| 27 | |||
| 28 | if ($token_type == LEFT_PAREN) { | ||
| 29 | $left_paren_num++; | ||
| 30 | } | ||
| 31 | elsif ($token_type == RIGHT_PAREN) { | ||
| 32 | if (--$left_paren_num <= 0) { | ||
| 33 | my $next_token = $tokens->[++$i]; | ||
| 34 | if ($next_token->{type} == ASSIGN) { | ||
| 35 | push @violations, { | ||
| 36 | filename => $file, | ||
| 37 | line => $token->{line}, | ||
| 38 | description => DESC, | ||
| 39 | explanation => EXPL, | ||
| 40 | policy => __PACKAGE__, | ||
| 41 | }; | ||
| 42 | } | ||
| 43 | last; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | elsif ($token_type == USE_DECL) { | ||
| 50 | $token = $tokens->[++$i]; | ||
| 51 | if ($token->{type} == DOUBLE) { | ||
| 52 | ($token_data = $token->{data}) =~ s/_//g; | ||
| 53 | if ($token_data <= 5.004) { | ||
| 54 | return []; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | return \@violations; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||