File Coverage

blib/lib/Class/Autouse/Parent.pm
Criterion Covered Total %
statement 16 16 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 24 25 96.0


line stmt bran cond sub pod time code
1             package Class::Autouse::Parent;
2              
3             # The package Class::Autouse::Parent can be inherited from to implement
4             # a parent class. That is, a class who's primary job is to load a series
5             # classes below it.
6              
7 2     2   31 use strict;
  2         39  
  2         34  
8 2     2   33 use Class::Autouse ();
  2         18  
  2         19  
9              
10 2     2   30 use vars qw{$VERSION};
  2         18  
  2         30  
11             BEGIN {
12 2     2   45 $VERSION = '1.27';
13             }
14              
15             # Maintain flags for "is the class in the process of loading"
16             my %LOADING = ();
17              
18             sub import {
19             # If the parent value is ourselves, we were just
20             # 'use'd, not 'base'd.
21 3 100   3   51 my $parent = $_[0] ne __PACKAGE__ ? shift : return 1;
22              
23             # Don't load if already loading
24 1 50       13 return 1 if $LOADING{$parent};
25              
26             # Autoload in our children
27 1         11 $LOADING{parent} = 1;
28 1         16 Class::Autouse->autouse_recursive( $parent );
29 1         12 delete $LOADING{parent};
30              
31 1         11 1;
32             }
33              
34             1;
35