File Coverage

blib/lib/Class/Init.pm
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Class::Init;
2              
3 2     2   54299 use 5.008001;
  2         10  
  2         72  
4 2     2   11 use strict;
  2         2  
  2         69  
5 2     2   9 use warnings;
  2         7  
  2         58  
6              
7 2     2   5475 use NEXT;
  2         18875  
  2         736  
8              
9             our @EXPORT = qw( new );
10             our @EXPORT_OK = @EXPORT;
11              
12             require Exporter;
13             our @ISA = qw(Exporter);
14              
15             our $VERSION = '1.1';
16              
17              
18             # Preloaded methods go here.
19              
20             sub _constructor ($;@) {
21             # This gets called if all else fails to create $self.
22 3     3   12 return bless { @_[1..$#_] }, $_[0];
23             }
24              
25             sub new ($;@) {
26             # Set $self to our parent's idea of new(), or otherwise just a simple blessed hashref.
27 3     3 0 2220 my $self = $_[0]->_constructor(@_[1..$#_]);
28             # Scan the inheritance tree for initialization routines and execute them, top-down.
29 3         38 $self->EVERY::LAST::_init(@_[1..$#_]);
30 3 50       48 $self->_init(@_[1..$#_]) if defined &_init;
31              
32 3         19 $self;
33             }
34              
35             sub _init ($;%) {
36             # Install any default attributes into the object's hash.
37 1     1   2061 $_[0]->{$_[0+2*$_]} = $_[0]->{$_[1+2*$_]} for (1..($#_-1)/2);
38             }
39              
40             1;
41             __END__