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   93882 use strict;
  134         272  
  134         4774  
3 134     134   697 use warnings;
  134         211  
  134         4480  
4 134     134   623 use List::Util 1.38 qw/any/;
  134         4586  
  134         8781  
5 134     134   1193 use Perl::Lint::Constants::Type;
  134         239  
  134         80735  
6 134     134   818 use parent "Perl::Lint::Policy";
  134         290  
  134         809  
7              
8             use constant {
9 134         39950 DESC => 'Subroutine "%s" called using indirect syntax',
10             EXPL => [349],
11 134     134   9490 };
  134         256  
12              
13             sub evaluate {
14 7     7 0 16 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 7         18 my @forbidden = ('new');
17 7         19 my $forbid_arg = $args->{indirect_syntax}->{forbid};
18 7 100 66     29 if ($forbid_arg && ref $forbid_arg eq 'ARRAY') {
19 1         2 push @forbidden, @{$forbid_arg};
  1         2  
20             }
21              
22 7         18 my @violations;
23 7         12 my $token_num = scalar @$tokens;
24 7         24 for (my $i = 0; $i < $token_num; $i++) {
25 262         205 my $token = $tokens->[$i];
26 262         220 my $token_data = $token->{data};
27 262 100 100 83   666 if ($token->{type} == KEY && any { $token_data eq $_ } @forbidden) {
  83         203  
28 22         24 my $token_type = $tokens->[++$i]->{type};
29 22 50 100     80 if ($token_type == KEY ||
      100        
      66        
30             $token_type == GLOBAL_VAR ||
31             $token_type == VAR ||
32             $token_type == LEFT_BRACE
33             ) {
34 22         144 push @violations, {
35             filename => $file,
36             line => $token->{line},
37             description => sprintf(DESC, $token_data),
38             explanation => sprintf(EXPL, $token_data),
39             policy => __PACKAGE__,
40             };
41             }
42             }
43             }
44              
45 7         33 return \@violations;
46             }
47              
48             1;
49