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