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   67720 use strict;
  133         192  
  133         3199  
3 133     133   430 use warnings;
  133         170  
  133         2440  
4 133     133   863 use Perl::Lint::Constants::Type;
  133         152  
  133         59016  
5 133     133   572 use parent "Perl::Lint::Policy";
  133         180  
  133         582  
6              
7             use constant {
8 133         27773 DESC => 'UNIVERSAL::isa should not be used as a function',
9             EXPL => 'Use eval{$obj->isa($pkg)} instead',
10 133     133   6865 };
  133         180  
11              
12             sub evaluate {
13 3     3 0 4 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 3         4 my @violations;
16 3         12 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     177 if ($token_type == KEY && $token_data eq 'isa') { # for isa()
    100 66        
21 6         8 $token = $tokens->[++$i];
22 6 50       10 if ($token->{type} == LEFT_PAREN) {
23             push @violations, {
24             filename => $file,
25             line => $token->{line},
26 6         21 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         4 $i += 2; # skip the name space resolver
34 3         3 $token = $tokens->[$i];
35 3 50 33     13 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         9 return \@violations;
50             }
51              
52             1;
53