line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Accessor::Lazy;
|
2
|
1
|
|
|
1
|
|
26075
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
29
|
use 5.006;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Class::Accessor';
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
572
|
|
5
|
|
|
|
|
|
|
$Class::Accessor::Lazy::VERSION = '0.35';
|
6
|
1
|
|
|
1
|
|
632
|
use Class::Accessor::Lazy::Original;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
81
|
|
7
|
1
|
|
|
1
|
|
685
|
use Class::Accessor::Lazy::Fast;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Carp qw(confess);
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new
|
11
|
|
|
|
|
|
|
{
|
12
|
|
|
|
|
|
|
my($proto, $fields) = @_;
|
13
|
|
|
|
|
|
|
my($class) = ref $proto || $proto;
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $self = $class->SUPER::new($fields);
|
16
|
|
|
|
|
|
|
$self->{'__lazy_inits'} = {};
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return $self;
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub mk_lazy_accessors {
|
22
|
|
|
|
|
|
|
my($self, @fields) = @_;
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $self->_mk_lazy_accessors('rw', @fields);
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
sub mk_lazy_ro_accessors {
|
27
|
|
|
|
|
|
|
my($self, @fields) = @_;
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return $self->_mk_lazy_accessors('ro', @fields);
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
*make_lazy_accessor = \&Class::Accessor::Lazy::Original::make_accessor;
|
34
|
|
|
|
|
|
|
*make_lazy_ro_accessor = \&Class::Accessor::Lazy::Original::make_ro_accessor;
|
35
|
|
|
|
|
|
|
*make_lazy_wo_accessor = \&Class::Accessor::Lazy::Original::make_wo_accessor;
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
{
|
38
|
|
|
|
|
|
|
no strict 'refs';
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub follow_best_practice {
|
41
|
|
|
|
|
|
|
my $self = shift;
|
42
|
|
|
|
|
|
|
my $class = ref $self || $self;
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$class->SUPER::follow_best_practice();
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $self;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _mk_accessors {
|
50
|
|
|
|
|
|
|
my $self = shift;
|
51
|
|
|
|
|
|
|
my $class = ref $self || $self;
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$class->SUPER::_mk_accessors(@_);
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $self;
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _mk_lazy_accessors {
|
59
|
|
|
|
|
|
|
my $self = shift;
|
60
|
|
|
|
|
|
|
my($access, @fields) = @_;
|
61
|
|
|
|
|
|
|
my $class = ref $self || $self;
|
62
|
|
|
|
|
|
|
my $ra = $access eq 'rw' || $access eq 'ro';
|
63
|
|
|
|
|
|
|
my $wa = $access eq 'rw' || $access eq 'wo';
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
foreach my $field (@fields) {
|
66
|
|
|
|
|
|
|
my $accessor_name = $self->accessor_name_for($field);
|
67
|
|
|
|
|
|
|
my $mutator_name = $self->mutator_name_for($field);
|
68
|
|
|
|
|
|
|
if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTROY' ) {
|
69
|
|
|
|
|
|
|
$self->_carp("Having a data accessor named DESTROY in '$class' is unwise.");
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $lazy;
|
73
|
|
|
|
|
|
|
if ($accessor_name eq $mutator_name) {
|
74
|
|
|
|
|
|
|
my $accessor;
|
75
|
|
|
|
|
|
|
if ($ra && $wa) {
|
76
|
|
|
|
|
|
|
$accessor = $self->make_lazy_accessor($field);
|
77
|
|
|
|
|
|
|
$lazy = 1;
|
78
|
|
|
|
|
|
|
} elsif ($ra) {
|
79
|
|
|
|
|
|
|
$accessor = $self->make_lazy_ro_accessor($field);
|
80
|
|
|
|
|
|
|
$lazy = 1;
|
81
|
|
|
|
|
|
|
} else {
|
82
|
|
|
|
|
|
|
$accessor = $self->make_lazy_wo_accessor($field);
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $fullname = "${class}::$accessor_name";
|
86
|
|
|
|
|
|
|
my $subnamed = 0;
|
87
|
|
|
|
|
|
|
unless (defined &{$fullname}) {
|
88
|
|
|
|
|
|
|
subname($fullname, $accessor) if defined &subname;
|
89
|
|
|
|
|
|
|
$subnamed = 1;
|
90
|
|
|
|
|
|
|
*{$fullname} = $accessor;
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
if ($accessor_name eq $field) {
|
93
|
|
|
|
|
|
|
# the old behaviour
|
94
|
|
|
|
|
|
|
my $alias = "${class}::_${field}_accessor";
|
95
|
|
|
|
|
|
|
subname($alias, $accessor) if defined &subname and not $subnamed;
|
96
|
|
|
|
|
|
|
*{$alias} = $accessor unless defined &{$alias};
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
} else {
|
99
|
|
|
|
|
|
|
my $fullaccname = "${class}::$accessor_name";
|
100
|
|
|
|
|
|
|
my $fullmutname = "${class}::$mutator_name";
|
101
|
|
|
|
|
|
|
if ($ra and not defined &{$fullaccname}) { # guess, we need warning here, that accessor exists
|
102
|
|
|
|
|
|
|
my $accessor = $self->make_lazy_ro_accessor($field);
|
103
|
|
|
|
|
|
|
$lazy = 1;
|
104
|
|
|
|
|
|
|
subname($fullaccname, $accessor) if defined &subname;
|
105
|
|
|
|
|
|
|
*{$fullaccname} = $accessor;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
if ($wa and not defined &{$fullmutname}) { # guess, we need warning here, that mutator exists
|
108
|
|
|
|
|
|
|
my $mutator = $self->make_lazy_wo_accessor($field);
|
109
|
|
|
|
|
|
|
subname($fullmutname, $mutator) if defined &subname;
|
110
|
|
|
|
|
|
|
*{$fullmutname} = $mutator;
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if( $lazy )
|
115
|
|
|
|
|
|
|
{
|
116
|
|
|
|
|
|
|
my $init_method = "${class}::_lazy_init_$field";
|
117
|
|
|
|
|
|
|
unless (defined &{$init_method} ){
|
118
|
|
|
|
|
|
|
$self->_croak("Unable to create lazy accessor '$field' without defined init method $init_method");
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
}
|
122
|
|
|
|
|
|
|
return $self;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1;
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__
|