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   41888 use strict;
  1         2  
  1         46  
2 1     1   6 use warnings;
  1         3  
  1         67  
3             package System::Sub::AutoLoad;
4             $System::Sub::AutoLoad::VERSION = '0.142280';
5 1     1   921 use System::Sub ();
  1         3  
  1         139  
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   12 my $pkg = caller;
19 1         1 shift;
20              
21 1         6 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   7 no strict 'refs';
  1         2  
  1         49  
31 0         0 *{$fq_name} = \&{$fq_name};
  0         0  
  0         0  
32             }
33              
34             # Install the AUTOLOAD sub
35 1     1   5 no strict 'refs';
  1         2  
  1         112  
36 1         2 *{$pkg.'::AUTOLOAD'} = \&_AUTOLOAD;
  1         2611  
37             }
38              
39             sub _AUTOLOAD
40             {
41 1     1   6469 my $fq_name = our $AUTOLOAD;
42              
43 1         209 my $options = delete $AutoLoad{$fq_name};
44 1 50       44 System::Sub->import($fq_name, $options ? ($options) : ());
45              
46 1     1   6 no strict 'refs';
  1         2  
  1         52  
47 1         9 goto &$fq_name
48             }
49              
50             1;
51             __END__