line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Object::Lazy; ## no critic (TidyCode)
|
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
246714
|
use strict;
|
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
474
|
|
4
|
14
|
|
|
14
|
|
62
|
use warnings;
|
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
546
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.15';
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
61
|
use Carp qw(confess);
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
656
|
|
9
|
14
|
|
|
14
|
|
6667
|
use Try::Tiny;
|
|
14
|
|
|
|
|
15524
|
|
|
14
|
|
|
|
|
727
|
|
10
|
14
|
|
|
14
|
|
4961
|
use Object::Lazy::Validate;
|
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
9135
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { ## no critic (ArgUnpacking)
|
13
|
17
|
|
|
17
|
1
|
2448
|
my ($class, $params) = Object::Lazy::Validate::validate_new(@_);
|
14
|
|
|
|
|
|
|
|
15
|
17
|
|
|
|
|
108
|
$params = Object::Lazy::Validate::init($params);
|
16
|
16
|
|
|
|
|
145
|
my $self = bless $params, $class;
|
17
|
16
|
100
|
|
|
|
102
|
if ( exists $params->{ref} ) {
|
18
|
1
|
|
|
|
|
3
|
Object::Lazy::Ref::register($self);
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
16
|
|
|
|
|
46
|
return $self;
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $build_object = sub {
|
25
|
|
|
|
|
|
|
my ($self, $self_ref) = @_;
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
local *__ANON__ = 'BUILD_OBJECT'; ## no critic (LocalVars)
|
28
|
|
|
|
|
|
|
my $built_object = $self->{build}->();
|
29
|
|
|
|
|
|
|
# don't build a second time
|
30
|
|
|
|
|
|
|
$self->{build} = sub { return $built_object };
|
31
|
|
|
|
|
|
|
if ( ! $self->{is_built} ) {
|
32
|
|
|
|
|
|
|
$self->{is_built} = 1;
|
33
|
|
|
|
|
|
|
if ( exists $self->{logger} ) {
|
34
|
|
|
|
|
|
|
try {
|
35
|
|
|
|
|
|
|
confess('object built');
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
catch {
|
38
|
|
|
|
|
|
|
$self->{logger}->($_);
|
39
|
|
|
|
|
|
|
};
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
${$self_ref} = $built_object;
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $built_object;
|
45
|
|
|
|
|
|
|
};
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
|
0
|
sub DESTROY {} # is not AUTOLOAD
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub AUTOLOAD { ## no critic (Autoloading ArgUnpacking)
|
50
|
5
|
|
|
5
|
|
2411
|
my ($self, @params) = @_;
|
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
12
|
my $method = substr our $AUTOLOAD, 2 + length __PACKAGE__;
|
53
|
5
|
|
|
|
|
18
|
my $built_object = $build_object->($self, \$_[0]);
|
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
36
|
return $built_object->$method(@params);
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub isa { ## no critic (ArgUnpacking)
|
59
|
5
|
|
|
5
|
1
|
1875
|
my ($self, $class2check) = @_;
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @isa
|
62
|
5
|
|
|
|
|
13
|
= ref $self->{isa} eq 'ARRAY'
|
63
|
5
|
50
|
|
|
|
22
|
? @{ $self->{isa} }
|
64
|
|
|
|
|
|
|
: ( $self->{isa} );
|
65
|
5
|
100
|
100
|
|
|
39
|
if ( $self->{is_built} || ! @isa ) {
|
66
|
3
|
|
|
|
|
11
|
my $built_object = $build_object->($self, \$_[0]);
|
67
|
3
|
|
|
|
|
28
|
return $built_object->isa($class2check);
|
68
|
|
|
|
|
|
|
}
|
69
|
2
|
|
|
|
|
4
|
CLASS: for my $class (@isa) {
|
70
|
4
|
100
|
|
|
|
27
|
$class->isa($class2check) and return 1;
|
71
|
|
|
|
|
|
|
}
|
72
|
1
|
|
|
|
|
3
|
my %isa = map { ($_ => undef) } @isa;
|
|
2
|
|
|
|
|
5
|
|
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
5
|
return exists $isa{$class2check};
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub DOES { ## no critic (ArgUnpacking)
|
78
|
3
|
|
|
3
|
1
|
827
|
my ($self, $class2check) = @_;
|
79
|
|
|
|
|
|
|
|
80
|
3
|
50
|
|
|
|
25
|
UNIVERSAL->can('DOES')
|
81
|
|
|
|
|
|
|
or confess 'UNIVERSAL 1.04 (Perl 5.10) required for method DOES';
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @does
|
84
|
3
|
|
|
|
|
28
|
= ref $self->{DOES} eq 'ARRAY'
|
85
|
3
|
50
|
|
|
|
15
|
? @{ $self->{DOES} }
|
86
|
|
|
|
|
|
|
: ( $self->{DOES} );
|
87
|
3
|
|
|
|
|
7
|
my @isa_and_does = (
|
88
|
|
|
|
|
|
|
(
|
89
|
|
|
|
|
|
|
ref $self->{isa} eq 'ARRAY'
|
90
|
3
|
50
|
|
|
|
11
|
? @{ $self->{isa} }
|
91
|
|
|
|
|
|
|
: ( $self->{isa} )
|
92
|
|
|
|
|
|
|
),
|
93
|
|
|
|
|
|
|
@does,
|
94
|
|
|
|
|
|
|
);
|
95
|
3
|
100
|
66
|
|
|
17
|
if ( $self->{is_built} || ! @isa_and_does ) {
|
96
|
1
|
|
|
|
|
5
|
my $built_object = $build_object->($self, \$_[0]);
|
97
|
1
|
|
|
|
|
11
|
return $built_object->DOES($class2check);
|
98
|
|
|
|
|
|
|
}
|
99
|
2
|
|
|
|
|
3
|
CLASS: for my $class (@does) {
|
100
|
3
|
100
|
|
|
|
36
|
$class->DOES($class2check) and return 1;
|
101
|
|
|
|
|
|
|
}
|
102
|
0
|
|
|
|
|
0
|
my %isa_and_does = map { ($_ => undef) } @isa_and_does;
|
|
0
|
|
|
|
|
0
|
|
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
return exists $isa_and_does{$class2check};
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub can { ## no critic (ArgUnpacking)
|
108
|
3
|
|
|
3
|
1
|
105
|
my ($self, $method) = @_;
|
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
10
|
my $built_object = $build_object->($self, \$_[0]);
|
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
40
|
return $built_object->can($method);
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub VERSION { ## no critic (ArgUnpacking)
|
116
|
3
|
|
|
3
|
1
|
16
|
my ($self, @version) = @_;
|
117
|
|
|
|
|
|
|
|
118
|
3
|
50
|
|
|
|
12
|
if ( ! $self->{is_built} ) {
|
119
|
3
|
100
|
|
|
|
9
|
if ( defined $self->{VERSION} ) {
|
120
|
1
|
|
|
|
|
2
|
$Object::Lazy::Version::VERSION = $self->{VERSION};
|
121
|
1
|
|
|
|
|
11
|
return +( bless {}, 'Object::Lazy::Version' )->VERSION(@version);
|
122
|
|
|
|
|
|
|
}
|
123
|
2
|
100
|
|
|
|
7
|
if ( $self->{version_from} ) {
|
124
|
1
|
|
|
|
|
14
|
return +( bless {}, $self->{version_from} )->VERSION(@version);
|
125
|
|
|
|
|
|
|
}
|
126
|
|
|
|
|
|
|
}
|
127
|
1
|
|
|
|
|
4
|
my $built_object = $build_object->($self, \$_[0]);
|
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
24
|
return $built_object->VERSION(@version);
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# $Id$
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1;
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__
|