File Coverage

blib/lib/Perl/Lint/Policy/ControlStructures/ProhibitUnlessBlocks.pm
Criterion Covered Total %
statement 29 30 96.6
branch 9 12 75.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 44 49 89.8


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ControlStructures::ProhibitUnlessBlocks;
2 134     134   97764 use strict;
  134         243  
  134         5124  
3 134     134   596 use warnings;
  134         184  
  134         3641  
4 134     134   937 use Perl::Lint::Constants::Type;
  134         258  
  134         84671  
5 134     134   771 use parent "Perl::Lint::Policy";
  134         227  
  134         786  
6              
7             use constant {
8 134         34961 DESC => '"unless" block used',
9             EXPL => [97],
10 134     134   9447 };
  134         217  
11              
12             sub evaluate {
13 5     5 0 13 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 5         25 my @violations;
16 5         51 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 102         97 my $token_type = $token->{type};
18              
19 102 100       222 if ($token_type == UNLESS_STATEMENT) {
20 7 100       36 if ($tokens->[++$i]->{type} == LEFT_PAREN) {
21 6         22 my $left_paren_num = 1;
22 6         15 for ($i++; my $token = $tokens->[$i]; $i++) {
23 12         16 my $token_type = $token->{type};
24 12 50       49 if ($token_type == LEFT_PAREN) {
    100          
25 0         0 $left_paren_num++;
26             }
27             elsif ($token_type == RIGHT_PAREN) {
28 6 50       17 last if --$left_paren_num <= 0;
29             }
30             }
31 6 50       16 if ($tokens->[++$i]->{type} == LEFT_BRACE) {
32 6         39 push @violations, {
33             filename => $file,
34             line => $token->{line},
35             description => DESC,
36             explanation => EXPL,
37             policy => __PACKAGE__,
38             };
39             }
40             }
41             }
42             }
43              
44 5         24 return \@violations;
45             }
46              
47             1;
48