File Coverage

blib/lib/Perl/Lint/Policy/RegularExpressions/ProhibitUnusualDelimiters.pm
Criterion Covered Total %
statement 30 30 100.0
branch 7 8 87.5
condition 23 24 95.8
subroutine 6 6 100.0
pod 0 1 0.0
total 66 69 95.6


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::RegularExpressions::ProhibitUnusualDelimiters;
2 134     134   69840 use strict;
  134         918  
  134         3118  
3 134     134   404 use warnings;
  134         156  
  134         2400  
4 134     134   789 use Perl::Lint::Constants::Type;
  134         165  
  134         60492  
5 134     134   556 use parent "Perl::Lint::Policy";
  134         154  
  134         580  
6              
7             use constant {
8 134         27321 DESC => 'Use only "//" or "{}" to delimit regexps',
9             EXPL => [246],
10 134     134   7325 };
  134         187  
11              
12             sub evaluate {
13 6     6 0 14 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 6         14 my $does_allow_all_brackets = $args->{prohibit_unusual_delimiters}->{allow_all_brackets};
16              
17 6         8 my @violations;
18 6         24 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
19 196         102 my $token_type = $token->{type};
20 196         144 my $token_data = $token->{data};
21              
22 196 100 100     576 if (
      100        
      100        
23             $token_type == REG_DELIM &&
24             $token_data ne '{' &&
25             $token_data ne '}' &&
26             $token_data ne '/'
27             ) {
28 37 100       44 if ($does_allow_all_brackets) {
29 15 50 100     64 if (
      100        
      100        
      100        
      66        
30             $token_data eq '(' || $token_data eq ')' ||
31             $token_data eq '[' || $token_data eq ']' ||
32             $token_data eq '<' || $token_data eq '>'
33             ) {
34 15         19 next;
35             }
36             }
37              
38             push @violations, {
39             filename => $file,
40             line => $token->{line},
41 22         51 description => DESC,
42             explanation => EXPL,
43             policy => __PACKAGE__,
44             };
45              
46 22         31 for ($i++; my $token = $tokens->[$i]; $i++) {
47 80         57 my $token_type = $token->{type};
48 80 100       143 last if $token_type == SEMI_COLON;
49             }
50             }
51             }
52              
53 6         22 return \@violations;
54             }
55              
56             1;
57