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   97905 use strict;
  133         284  
  133         5338  
3 133     133   661 use warnings;
  133         216  
  133         3418  
4 133     133   962 use Perl::Lint::Constants::Type;
  133         207  
  133         85315  
5 133     133   867 use parent "Perl::Lint::Policy";
  133         262  
  133         829  
6              
7             use constant {
8 133         42834 DESC => 'UNIVERSAL::isa should not be used as a function',
9             EXPL => 'Use eval{$obj->isa($pkg)} instead',
10 133     133   9635 };
  133         271  
11              
12             sub evaluate {
13 3     3 0 5 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 3         4 my @violations;
16 3         13 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 53         39 my $token_type = $token->{type};
18 53         47 my $token_data = $token->{data};
19              
20 53 100 66     198 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 6         24 push @violations, {
24             filename => $file,
25             line => $token->{line},
26             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       10 if ($tokens->[++$i]->{type} == LEFT_PAREN) {
37 1         6 push @violations, {
38             filename => $file,
39             line => $token->{line},
40             description => DESC,
41             explanation => EXPL,
42             policy => __PACKAGE__,
43             };
44             }
45             }
46             }
47             }
48              
49 3         10 return \@violations;
50             }
51              
52             1;
53