File Coverage

blib/lib/Perl/Lint/Policy/BuiltinFunctions/RequireSimpleSortBlock.pm
Criterion Covered Total %
statement 39 39 100.0
branch 14 14 100.0
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 61 63 96.8


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::BuiltinFunctions::RequireSimpleSortBlock;
2 133     133   67344 use strict;
  133         181  
  133         3173  
3 133     133   440 use warnings;
  133         168  
  133         2713  
4 133     133   816 use Perl::Lint::Constants::Type;
  133         163  
  133         58524  
5 133     133   586 use parent "Perl::Lint::Policy";
  133         178  
  133         555  
6              
7             use constant {
8 133         31197 DESC => 'Sort blocks should have a single statement',
9             EXPL => [149],
10 133     133   6291 };
  133         190  
11              
12             sub evaluate {
13 4     4 0 7 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 4         5 my @violations;
16 4         14 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 76         54 my $token_type = $token->{type};
18 76         43 my $token_data = $token->{data};
19              
20 76 100 66     171 if ($token_type == BUILTIN_FUNC && $token_data eq 'sort') {
21 21         15 $token = $tokens->[++$i];
22 21 100       29 if ($token->{type} == LEFT_PAREN) {
23 6         7 $token = $tokens->[++$i];
24             }
25              
26 21         14 my $token_type = $token->{type};
27              
28 21 100       25 if ($token_type != LEFT_BRACE) {
29 5         9 next;
30             }
31              
32 16         7 my $left_brace_num = 1;
33 16         15 my $concat_stmt = ''; # XXX
34 16         22 for ($i++; $token = $tokens->[$i]; $i++) {
35 240         177 $token_type = $token->{type};
36              
37 240 100       259 if ($token_type == LEFT_BRACE) {
    100          
38 14         18 $left_brace_num++;
39             }
40             elsif ($token_type == RIGHT_BRACE) {
41 30 100       41 if (--$left_brace_num <= 0) {
42 16 100       38 if (scalar(@_ = split /;/, $concat_stmt) > 1) { # XXX
43             push @violations, {
44             filename => $file,
45             line => $token->{line},
46 6         17 description => DESC,
47             explanation => EXPL,
48             policy => __PACKAGE__,
49             };
50             }
51 16         28 last;
52             }
53             }
54             else {
55 196         255 $concat_stmt .= $token->{data};
56             }
57             }
58             }
59             }
60              
61 4         15 return \@violations;
62             }
63              
64             1;
65