File Coverage

blib/lib/Perl/Lint/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm
Criterion Covered Total %
statement 24 24 100.0
branch 5 6 83.3
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 35 37 94.5


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames;
2 133     133   90441 use strict;
  133         262  
  133         4753  
3 133     133   615 use warnings;
  133         213  
  133         3263  
4 133     133   1085 use Perl::Lint::Constants::Type;
  133         212  
  133         84984  
5 133     133   805 use parent "Perl::Lint::Policy";
  133         244  
  133         758  
6              
7             use constant {
8 133         26761 DESC => 'Special block name used as label',
9             EXPL => 'Use a label that cannot be confused with BEGIN, END, CHECK, INIT, or UNITCHECK blocks',
10 133     133   8992 };
  133         243  
11              
12             sub evaluate {
13 4     4 0 7 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 4         6 my @violations;
16 4         17 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 120         86 my $token_type = $token->{type};
18              
19 120 100       228 if ($token_type == MOD_WORD) {
20 20 100       37 if ($tokens->[++$i]->{type} == COLON) {
21 15 50       21 if ($tokens->[++$i]->{type} == LEFT_BRACE) {
22 15         58 push @violations, {
23             filename => $file,
24             line => $token->{line},
25             description => DESC,
26             explanation => EXPL,
27             policy => __PACKAGE__,
28             };
29             }
30             }
31             }
32             }
33              
34 4         17 return \@violations;
35             }
36              
37             1;
38