File Coverage

blib/lib/UNIVERSAL/canAUTOLOAD.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 6 83.3
condition 2 3 66.6
subroutine 4 4 100.0
pod 1 1 100.0
total 35 37 94.5


line stmt bran cond sub pod time code
1 1     1   23553 use strict;
  1         2  
  1         47  
2             package UNIVERSAL::canAUTOLOAD;
3 1     1   818 use Class::ISA;
  1         3243  
  1         44  
4             our $VERSION = '0.01';
5              
6 1     1   7 no warnings 'redefine';
  1         7  
  1         231  
7             sub UNIVERSAL::can {
8 6178     6178 1 25830 my ($referent, $want) = @_;
9              
10 6178   66     12474 my $class = ref $referent || $referent;
11 6178         14012 my @path = ( Class::ISA::self_and_super_path( $class ), 'UNIVERSAL' );
12              
13             # first look for a solid method
14 6178         404780 for my $search (@path) {
15 9484 100       8883 return \&{"$search\::$want"} if exists &{"$search\::$want"};
  5193         102219  
  9484         28068  
16             }
17              
18             # then look for an AUTOLOAD sub
19 985         4087 for my $search (@path) {
20 3928 100       3510 next unless exists &{"$search\::AUTOLOAD"};
  3928         10652  
21 3         10 my $code = "package $search;".
22             'sub { our $AUTOLOAD = "$class\::$want"; goto &AUTOLOAD }';
23 3 50       440 my $sub = eval $code or die "compiling '$code': $@";
24 3         16 return $sub;
25             }
26              
27             # no? give up
28 982         35851 return undef;
29             }
30              
31             1;
32             __END__