File Coverage

blib/lib/Perl/Lint/Policy/BuiltinFunctions/ProhibitUniversalIsa.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 10 80.0
condition 5 9 55.5
subroutine 6 6 100.0
pod 0 1 0.0
total 49 56 87.5


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::BuiltinFunctions::ProhibitUniversalIsa;
2 133     133   69632 use strict;
  133         194  
  133         3125  
3 133     133   419 use warnings;
  133         172  
  133         2458  
4 133     133   791 use Perl::Lint::Constants::Type;
  133         153  
  133         59074  
5 133     133   582 use parent "Perl::Lint::Policy";
  133         180  
  133         563  
6              
7             use constant {
8 133         27659 DESC => 'UNIVERSAL::isa should not be used as a function',
9             EXPL => 'Use eval{$obj->isa($pkg)} instead',
10 133     133   6403 };
  133         190  
11              
12             sub evaluate {
13 3     3 0 6 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 3         3 my @violations;
16 3         13 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 53         37 my $token_type = $token->{type};
18 53         33 my $token_data = $token->{data};
19              
20 53 100 66     178 if ($token_type == KEY && $token_data eq 'isa') { # for isa()
    100 66        
21 6         7 $token = $tokens->[++$i];
22 6 50       10 if ($token->{type} == LEFT_PAREN) {
23             push @violations, {
24             filename => $file,
25             line => $token->{line},
26 6         23 description => DESC,
27             explanation => EXPL,
28             policy => __PACKAGE__,
29             };
30             }
31             }
32             elsif ($token_type == NAMESPACE && $token_data eq 'UNIVERSAL') { # for UNIVERSAL::isa()
33 3         5 $i += 2; # skip the name space resolver
34 3         3 $token = $tokens->[$i];
35 3 50 33     12 if ($token->{type} == NAMESPACE && $token->{data} eq 'isa') {
36 3 100       8 if ($tokens->[++$i]->{type} == LEFT_PAREN) {
37             push @violations, {
38             filename => $file,
39             line => $token->{line},
40 1         5 description => DESC,
41             explanation => EXPL,
42             policy => __PACKAGE__,
43             };
44             }
45             }
46             }
47             }
48              
49 3         11 return \@violations;
50             }
51              
52             1;
53