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   2225 use 5.006;
  2         8  
  2         80  
8 2     2   10 use strict;
  2         3  
  2         75  
9 2     2   10 use Class::Autouse ();
  2         4  
  2         76  
10              
11             our $VERSION;
12             BEGIN {
13 2     2   227 $VERSION = '2.01';
14             }
15              
16             # Anti-loop protection.
17             # Maintain flags for "is the class in the process of loading"
18             my %LOADING = ();
19              
20             sub import {
21             # If the parent value is ourselves, we were just
22             # 'use'd, not 'base'd.
23 3 100   3   4481 my $parent = $_[0] ne __PACKAGE__ ? shift : return 1;
24              
25             # Don't load if already loading
26 1 50       6 return 1 if $LOADING{$parent};
27              
28             # Autoload in our children
29 1         3 $LOADING{$parent} = 1;
30 1         10 Class::Autouse->autouse_recursive($parent);
31 1         4 delete $LOADING{$parent};
32              
33 1         11 return 1;
34             }
35              
36             1;