« blib/lib/Perl/Lint/Policy/BuiltinFunctions/RequireGlobFunction.pm
↑ Summary
blib/lib/Perl/Lint/Policy/ClassHierarchies/ProhibitAutoloading.pm »
| 1 | package Perl::Lint::Policy::BuiltinFunctions::RequireSimpleSortBlock; | ||
| 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 => 'Sort blocks should have a single statement', | ||
| 9 | EXPL => [149], | ||
| 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 'sort') { | ||
| 21 | $token = $tokens->[++$i]; | ||
| 22 | if ($token->{type} == LEFT_PAREN) { | ||
| 23 | $token = $tokens->[++$i]; | ||
| 24 | } | ||
| 25 | |||
| 26 | my $token_type = $token->{type}; | ||
| 27 | |||
| 28 | if ($token_type != LEFT_BRACE) { | ||
| 29 | next; | ||
| 30 | } | ||
| 31 | |||
| 32 | my $left_brace_num = 1; | ||
| 33 | my $concat_stmt = ''; # XXX | ||
| 34 | for ($i++; $token = $tokens->[$i]; $i++) { | ||
| 35 | $token_type = $token->{type}; | ||
| 36 | |||
| 37 | if ($token_type == LEFT_BRACE) { | ||
| 38 | $left_brace_num++; | ||
| 39 | } | ||
| 40 | elsif ($token_type == RIGHT_BRACE) { | ||
| 41 | if (--$left_brace_num <= 0) { | ||
| 42 | if (scalar(@_ = split /;/, $concat_stmt) > 1) { # XXX | ||
| 43 | push @violations, { | ||
| 44 | filename => $file, | ||
| 45 | line => $token->{line}, | ||
| 46 | description => DESC, | ||
| 47 | explanation => EXPL, | ||
| 48 | policy => __PACKAGE__, | ||
| 49 | }; | ||
| 50 | } | ||
| 51 | last; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | else { | ||
| 55 | $concat_stmt .= $token->{data}; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | return \@violations; | ||
| 62 | } | ||
| 63 | |||
| 64 | 1; | ||
| 65 | |||