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