File Coverage

blib/lib/System/Sub/AutoLoad.pm
Criterion Covered Total %
statement 27 36 75.0
branch 1 6 16.6
condition 0 6 0.0
subroutine 8 9 88.8
pod n/a
total 36 57 63.1


line stmt bran cond sub pod time code
1 1     1   14015 use strict;
  1         1  
  1         31  
2 1     1   3 use warnings;
  1         2  
  1         47  
3             package System::Sub::AutoLoad;
4             $System::Sub::AutoLoad::VERSION = '0.150960';
5 1     1   349 use System::Sub ();
  1         3  
  1         77  
6              
7             sub _croak
8             {
9 0     0   0 require Carp;
10 0         0 goto &Carp::croak
11             }
12              
13             # Storage for sub options until they are installed with the AUTOLOAD
14             my %AutoLoad;
15              
16             sub import
17             {
18 1     1   7 my $pkg = caller;
19 1         1 shift;
20              
21 1         3 while (@_) {
22 0         0 my $name = shift;
23 0 0 0     0 _croak "invalid arg: SCALAR expected" unless defined ref $name && ! ref $name;
24 0         0 my $fq_name = $pkg.'::'.$name;
25              
26 0 0 0     0 $AutoLoad{$fq_name} = shift if @_ && ref $_[0];
27              
28             # Create a forward declaration that will be usable by the Perl
29             # parser. See subs.pm
30 1     1   5 no strict 'refs';
  1         1  
  1         32  
31 0         0 *{$fq_name} = \&{$fq_name};
  0         0  
  0         0  
32             }
33              
34             # Install the AUTOLOAD sub
35 1     1   3 no strict 'refs';
  1         1  
  1         66  
36 1         2 *{$pkg.'::AUTOLOAD'} = \&_AUTOLOAD;
  1         1334  
37             }
38              
39             sub _AUTOLOAD
40             {
41 1     1   2258 my $fq_name = our $AUTOLOAD;
42              
43 1         37 my $options = delete $AutoLoad{$fq_name};
44 1 50       21 System::Sub->import($fq_name, $options ? ($options) : ());
45              
46 1     1   3 no strict 'refs';
  1         2  
  1         31  
47 1         5 goto &$fq_name
48             }
49              
50             1;
51             __END__