File Coverage

blib/lib/Exporter/WithBase.pm
Criterion Covered Total %
statement 19 22 86.3
branch 3 6 50.0
condition 3 6 50.0
subroutine 5 5 100.0
pod n/a
total 30 39 76.9


line stmt bran cond sub pod time code
1 2     2   40188 use strict qw; # no refs
  2         3  
  2         68  
2 2     2   8 use warnings;
  2         3  
  2         204  
3              
4             package Exporter::WithBase;
5             # ABSTRACT: Like Exporter, but add a '-base' flag to declare a class as a child
6             $Exporter::WithBase::VERSION = '0.03';
7 2     2   14 use Exporter 5.57 ();
  2         48  
  2         320  
8              
9             sub import
10             {
11 2     2   12 my $caller = caller;
12             # If -base, inherit from Exporter
13 2 50 33     9 if (@_ >= 2 && $_[1] eq '-base') {
14 0         0 splice @_, 1, 1;
15 0 0       0 push @{"${caller}::ISA"}, $_[0] eq __PACKAGE__ ? 'Exporter' : $_[0];
  0         0  
16             }
17             # Inject _import as import
18 2         4 *{"${caller}::import"} = \&_import;
  2         91  
19             # No symbols to export
20             }
21              
22             sub _import
23             {
24 3 100 66 3   53 if (@_ >= 2 && $_[1] eq '-base') {
25 1         4 splice @_, 1, 1;
26 1         2 my $caller = caller;
27 1         2 push @{"${caller}::ISA"}, $_[0];
  1         15  
28             }
29 3         3124 goto &Exporter::import;
30             }
31              
32             1;
33             __END__