File Coverage

blib/lib/Perl/Lint/Policy/Objects/IndirectSyntax.pm
Criterion Covered Total %
statement 35 35 100.0
branch 5 6 83.3
condition 13 15 86.6
subroutine 8 8 100.0
pod 0 1 0.0
total 61 65 93.8


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Objects::IndirectSyntax;
2 134     134   68408 use strict;
  134         174  
  134         2960  
3 134     134   386 use warnings;
  134         147  
  134         3214  
4 134     134   415 use List::Util 1.38 qw/any/;
  134         3520  
  134         6109  
5 134     134   873 use Perl::Lint::Constants::Type;
  134         153  
  134         58382  
6 134     134   558 use parent "Perl::Lint::Policy";
  134         166  
  134         578  
7              
8             use constant {
9 134         30399 DESC => 'Subroutine "%s" called using indirect syntax',
10             EXPL => [349],
11 134     134   6601 };
  134         156  
12              
13             sub evaluate {
14 7     7 0 23 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 7         15 my @forbidden = ('new');
17 7         15 my $forbid_arg = $args->{indirect_syntax}->{forbid};
18 7 100 66     26 if ($forbid_arg && ref $forbid_arg eq 'ARRAY') {
19 1         1 push @forbidden, @{$forbid_arg};
  1         3  
20             }
21              
22 7         9 my @violations;
23 7         10 my $token_num = scalar @$tokens;
24 7         19 for (my $i = 0; $i < $token_num; $i++) {
25 262         187 my $token = $tokens->[$i];
26 262         216 my $token_data = $token->{data};
27 262 100 100 83   602 if ($token->{type} == KEY && any { $token_data eq $_ } @forbidden) {
  83         196  
28 22         31 my $token_type = $tokens->[++$i]->{type};
29 22 50 100     85 if ($token_type == KEY ||
      100        
      66        
30             $token_type == GLOBAL_VAR ||
31             $token_type == VAR ||
32             $token_type == LEFT_BRACE
33             ) {
34             push @violations, {
35             filename => $file,
36             line => $token->{line},
37 22         1315 description => sprintf(DESC, $token_data),
38             explanation => sprintf(EXPL, $token_data),
39             policy => __PACKAGE__,
40             };
41             }
42             }
43             }
44              
45 7         28 return \@violations;
46             }
47              
48             1;
49