line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Objects::Collection::LazyObject; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Objects::Collection::Object - Lazy call. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Objects::Collection::Object; |
10
|
|
|
|
|
|
|
my $lazy = new Objects::Collection::LazyObject:: |
11
|
|
|
|
|
|
|
sub { new SomeClass:: %attr }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Lazy call. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
34481
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
103
|
|
20
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
124
|
|
21
|
3
|
|
|
3
|
|
25
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
82
|
|
22
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
233
|
|
23
|
|
|
|
|
|
|
$Objects::Collection::LazyObject::VERSION = '0.01'; |
24
|
3
|
|
|
3
|
|
15
|
no strict 'refs'; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
130
|
|
25
|
|
|
|
|
|
|
### install get/set accessors for this object. |
26
|
|
|
|
|
|
|
for my $key (qw/ ___sub_ref___ ___obj_ref___ /) { |
27
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
974
|
|
28
|
|
|
|
|
|
|
*{ __PACKAGE__ . "::$key" } = sub { |
29
|
5
|
|
|
5
|
|
6
|
my $self = shift; |
30
|
5
|
100
|
|
|
|
15
|
$self->{$key} = $_[0] if @_; |
31
|
5
|
|
|
|
|
21
|
return $self->{$key}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
1
|
|
|
1
|
0
|
1653
|
my $class = shift; |
37
|
1
|
50
|
|
|
|
6
|
$class = ref $class if ref $class; |
38
|
1
|
|
|
|
|
4
|
my $self = bless( {}, $class ); |
39
|
1
|
50
|
|
|
|
5
|
$self->___sub_ref___(shift) || return; |
40
|
1
|
|
|
|
|
7
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub ___get_object___ { |
44
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
45
|
2
|
|
|
|
|
4
|
my $obj = $self->___obj_ref___; |
46
|
2
|
100
|
|
|
|
6
|
unless ($obj) { |
47
|
1
|
|
50
|
|
|
3
|
$obj = $self->___sub_ref___->() |
48
|
|
|
|
|
|
|
|| die "can't do lazy call. need result"; |
49
|
1
|
|
|
|
|
15
|
$self->___obj_ref___($obj); |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
7
|
$obj; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub AUTOLOAD { |
55
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
56
|
2
|
50
|
|
|
|
7
|
return if $Objects::Collection::LazyObject::AUTOLOAD =~ /::(DESTROY)$/; |
57
|
2
|
|
|
|
|
9
|
( my $auto_sub ) = $Objects::Collection::LazyObject::AUTOLOAD =~ /.*::(.*)/; |
58
|
2
|
|
|
|
|
5
|
return $self->___get_object___->$auto_sub(@_); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |