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   13524 use strict;
  1         1  
  1         22  
2 1     1   3 use warnings;
  1         1  
  1         39  
3             package System::Sub::AutoLoad;
4             $System::Sub::AutoLoad::VERSION = '0.162800';
5 1     1   376 use System::Sub ();
  1         2  
  1         82  
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         4 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   4 no strict 'refs';
  1         1  
  1         36  
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         71  
36 1         2 *{$pkg.'::AUTOLOAD'} = \&_AUTOLOAD;
  1         1214  
37             }
38              
39             sub _AUTOLOAD
40             {
41 1     1   1907 my $fq_name = our $AUTOLOAD;
42              
43 1         35 my $options = delete $AutoLoad{$fq_name};
44 1 50       16 System::Sub->import($fq_name, $options ? ($options) : ());
45              
46 1     1   3 no strict 'refs';
  1         1  
  1         33  
47 1         3 goto &$fq_name
48             }
49              
50             1;
51             __END__