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