| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::Accessor; |
|
2
|
|
|
|
|
|
|
require 5.00502; |
|
3
|
6
|
|
|
6
|
|
48014
|
use strict; |
|
|
6
|
|
|
|
|
19
|
|
|
|
6
|
|
|
|
|
675
|
|
|
4
|
|
|
|
|
|
|
$Class::Accessor::VERSION = '0.50'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
|
7
|
|
|
|
|
|
|
return bless |
|
8
|
|
|
|
|
|
|
defined $_[1] |
|
9
|
11
|
100
|
33
|
11
|
1
|
9234
|
? {%{$_[1]}} # make a copy of $fields. |
|
|
8
|
|
|
|
|
70
|
|
|
10
|
|
|
|
|
|
|
: {}, |
|
11
|
|
|
|
|
|
|
ref $_[0] || $_[0]; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub mk_accessors { |
|
15
|
13
|
|
|
13
|
1
|
2503
|
my($self, @fields) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
13
|
|
|
|
|
49
|
$self->_mk_accessors('rw', @fields); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if (eval { require Sub::Name }) { |
|
21
|
|
|
|
|
|
|
Sub::Name->import; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
{ |
|
25
|
6
|
|
|
6
|
|
35
|
no strict 'refs'; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
5911
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub import { |
|
28
|
2
|
|
|
2
|
|
14
|
my ($class, @what) = @_; |
|
29
|
2
|
|
|
|
|
4
|
my $caller = caller; |
|
30
|
2
|
|
|
|
|
42
|
for (@what) { |
|
31
|
1
|
50
|
|
|
|
7
|
if (/^(?:antlers|moose-?like)$/i) { |
|
32
|
1
|
|
|
|
|
4
|
*{"${caller}::has"} = sub { |
|
33
|
5
|
|
|
5
|
|
1162
|
my ($f, %args) = @_; |
|
34
|
5
|
|
100
|
|
|
24
|
$caller->_mk_accessors(($args{is}||"rw"), $f); |
|
35
|
1
|
|
|
|
|
5
|
}; |
|
36
|
1
|
|
|
|
|
4
|
*{"${caller}::extends"} = sub { |
|
37
|
1
|
|
|
1
|
|
8
|
@{"${caller}::ISA"} = @_; |
|
|
1
|
|
|
|
|
7
|
|
|
38
|
1
|
50
|
|
|
|
3
|
unless (grep $_->can("_mk_accessors"), @_) { |
|
39
|
1
|
|
|
|
|
1
|
push @{"${caller}::ISA"}, $class; |
|
|
1
|
|
|
|
|
1232
|
|
|
40
|
|
|
|
|
|
|
} |
|
41
|
1
|
|
|
|
|
3
|
}; |
|
42
|
|
|
|
|
|
|
# we'll use their @ISA as a default, in case it happens to be |
|
43
|
|
|
|
|
|
|
# set already |
|
44
|
1
|
|
|
|
|
1
|
&{"${caller}::extends"}(@{"${caller}::ISA"}); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
4
|
|
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub follow_best_practice { |
|
50
|
3
|
|
|
3
|
1
|
953
|
my($self) = @_; |
|
51
|
3
|
|
33
|
|
|
11
|
my $class = ref $self || $self; |
|
52
|
3
|
|
|
|
|
6
|
*{"${class}::accessor_name_for"} = \&best_practice_accessor_name_for; |
|
|
3
|
|
|
|
|
13
|
|
|
53
|
3
|
|
|
|
|
6
|
*{"${class}::mutator_name_for"} = \&best_practice_mutator_name_for; |
|
|
3
|
|
|
|
|
11
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _mk_accessors { |
|
57
|
38
|
|
|
38
|
|
72
|
my($self, $access, @fields) = @_; |
|
58
|
38
|
|
33
|
|
|
122
|
my $class = ref $self || $self; |
|
59
|
38
|
|
100
|
|
|
100
|
my $ra = $access eq 'rw' || $access eq 'ro'; |
|
60
|
38
|
|
100
|
|
|
86
|
my $wa = $access eq 'rw' || $access eq 'wo'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
38
|
|
|
|
|
72
|
foreach my $field (@fields) { |
|
63
|
56
|
|
|
|
|
116
|
my $accessor_name = $self->accessor_name_for($field); |
|
64
|
56
|
|
|
|
|
125
|
my $mutator_name = $self->mutator_name_for($field); |
|
65
|
56
|
100
|
66
|
|
|
176
|
if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTROY' ) { |
|
66
|
4
|
|
|
|
|
25
|
$self->_carp("Having a data accessor named DESTROY in '$class' is unwise."); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
56
|
100
|
|
|
|
106
|
if ($accessor_name eq $mutator_name) { |
|
69
|
38
|
|
|
|
|
42
|
my $accessor; |
|
70
|
38
|
100
|
100
|
|
|
108
|
if ($ra && $wa) { |
|
|
|
100
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
54
|
$accessor = $self->make_accessor($field); |
|
72
|
|
|
|
|
|
|
} elsif ($ra) { |
|
73
|
8
|
|
|
|
|
27
|
$accessor = $self->make_ro_accessor($field); |
|
74
|
|
|
|
|
|
|
} else { |
|
75
|
8
|
|
|
|
|
32
|
$accessor = $self->make_wo_accessor($field); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
38
|
|
|
|
|
87
|
my $fullname = "${class}::$accessor_name"; |
|
78
|
38
|
|
|
|
|
47
|
my $subnamed = 0; |
|
79
|
38
|
100
|
|
|
|
54
|
unless (defined &{$fullname}) { |
|
|
38
|
|
|
|
|
172
|
|
|
80
|
32
|
50
|
|
|
|
66
|
subname($fullname, $accessor) if defined &subname; |
|
81
|
32
|
|
|
|
|
42
|
$subnamed = 1; |
|
82
|
32
|
|
|
|
|
39
|
*{$fullname} = $accessor; |
|
|
32
|
|
|
|
|
89
|
|
|
83
|
|
|
|
|
|
|
} |
|
84
|
38
|
50
|
|
|
|
82
|
if ($accessor_name eq $field) { |
|
85
|
|
|
|
|
|
|
# the old behaviour |
|
86
|
38
|
|
|
|
|
69
|
my $alias = "${class}::_${field}_accessor"; |
|
87
|
38
|
50
|
33
|
|
|
84
|
subname($alias, $accessor) if defined &subname and not $subnamed; |
|
88
|
38
|
50
|
|
|
|
51
|
*{$alias} = $accessor unless defined &{$alias}; |
|
|
38
|
|
|
|
|
160
|
|
|
|
38
|
|
|
|
|
137
|
|
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} else { |
|
91
|
18
|
|
|
|
|
27
|
my $fullaccname = "${class}::$accessor_name"; |
|
92
|
18
|
|
|
|
|
34
|
my $fullmutname = "${class}::$mutator_name"; |
|
93
|
18
|
100
|
66
|
|
|
33
|
if ($ra and not defined &{$fullaccname}) { |
|
|
12
|
|
|
|
|
60
|
|
|
94
|
12
|
|
|
|
|
32
|
my $accessor = $self->make_ro_accessor($field); |
|
95
|
12
|
50
|
|
|
|
31
|
subname($fullaccname, $accessor) if defined &subname; |
|
96
|
12
|
|
|
|
|
13
|
*{$fullaccname} = $accessor; |
|
|
12
|
|
|
|
|
47
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
18
|
100
|
66
|
|
|
41
|
if ($wa and not defined &{$fullmutname}) { |
|
|
12
|
|
|
|
|
65
|
|
|
99
|
12
|
|
|
|
|
33
|
my $mutator = $self->make_wo_accessor($field); |
|
100
|
12
|
50
|
|
|
|
29
|
subname($fullmutname, $mutator) if defined &subname; |
|
101
|
12
|
|
|
|
|
17
|
*{$fullmutname} = $mutator; |
|
|
12
|
|
|
|
|
65
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub mk_ro_accessors { |
|
110
|
10
|
|
|
10
|
1
|
78
|
my($self, @fields) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
10
|
|
|
|
|
26
|
$self->_mk_accessors('ro', @fields); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub mk_wo_accessors { |
|
116
|
10
|
|
|
10
|
1
|
58
|
my($self, @fields) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
10
|
|
|
|
|
23
|
$self->_mk_accessors('wo', @fields); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub best_practice_accessor_name_for { |
|
122
|
9
|
|
|
9
|
0
|
15
|
my ($class, $field) = @_; |
|
123
|
9
|
|
|
|
|
18
|
return "get_$field"; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub best_practice_mutator_name_for { |
|
127
|
9
|
|
|
9
|
0
|
12
|
my ($class, $field) = @_; |
|
128
|
9
|
|
|
|
|
40
|
return "set_$field"; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub accessor_name_for { |
|
132
|
38
|
|
|
38
|
1
|
62
|
my ($class, $field) = @_; |
|
133
|
38
|
|
|
|
|
64
|
return $field; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub mutator_name_for { |
|
137
|
38
|
|
|
38
|
1
|
60
|
my ($class, $field) = @_; |
|
138
|
38
|
|
|
|
|
62
|
return $field; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub set { |
|
142
|
11
|
|
|
11
|
1
|
26
|
my($self, $key) = splice(@_, 0, 2); |
|
143
|
|
|
|
|
|
|
|
|
144
|
11
|
100
|
|
|
|
26
|
if(@_ == 1) { |
|
|
|
50
|
|
|
|
|
|
|
145
|
9
|
|
|
|
|
26
|
$self->{$key} = $_[0]; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
elsif(@_ > 1) { |
|
148
|
2
|
|
|
|
|
8
|
$self->{$key} = [@_]; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
else { |
|
151
|
0
|
|
|
|
|
0
|
$self->_croak("Wrong number of arguments received"); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub get { |
|
156
|
19
|
|
|
19
|
1
|
32
|
my $self = shift; |
|
157
|
|
|
|
|
|
|
|
|
158
|
19
|
50
|
|
|
|
41
|
if(@_ == 1) { |
|
|
|
0
|
|
|
|
|
|
|
159
|
19
|
|
|
|
|
123
|
return $self->{$_[0]}; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
elsif( @_ > 1 ) { |
|
162
|
0
|
|
|
|
|
0
|
return @{$self}{@_}; |
|
|
0
|
|
|
|
|
0
|
|
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
else { |
|
165
|
0
|
|
|
|
|
0
|
$self->_croak("Wrong number of arguments received"); |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub make_accessor { |
|
170
|
10
|
|
|
10
|
1
|
19
|
my ($class, $field) = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
return sub { |
|
173
|
16
|
|
|
16
|
|
1827
|
my $self = shift; |
|
174
|
|
|
|
|
|
|
|
|
175
|
16
|
100
|
|
|
|
37
|
if(@_) { |
|
176
|
5
|
|
|
|
|
24
|
return $self->set($field, @_); |
|
177
|
|
|
|
|
|
|
} else { |
|
178
|
11
|
|
|
|
|
22
|
return $self->get($field); |
|
179
|
|
|
|
|
|
|
} |
|
180
|
10
|
|
|
|
|
33
|
}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub make_ro_accessor { |
|
184
|
7
|
|
|
7
|
1
|
16
|
my($class, $field) = @_; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return sub { |
|
187
|
8
|
|
|
8
|
|
21
|
my $self = shift; |
|
188
|
|
|
|
|
|
|
|
|
189
|
8
|
100
|
|
|
|
24
|
if (@_) { |
|
190
|
2
|
|
|
|
|
5
|
my $caller = caller; |
|
191
|
2
|
|
|
|
|
16
|
$self->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'"); |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
else { |
|
194
|
6
|
|
|
|
|
17
|
return $self->get($field); |
|
195
|
|
|
|
|
|
|
} |
|
196
|
7
|
|
|
|
|
41
|
}; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub make_wo_accessor { |
|
200
|
7
|
|
|
7
|
1
|
16
|
my($class, $field) = @_; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
return sub { |
|
203
|
7
|
|
|
7
|
|
1913
|
my $self = shift; |
|
204
|
|
|
|
|
|
|
|
|
205
|
7
|
100
|
|
|
|
18
|
unless (@_) { |
|
206
|
2
|
|
|
|
|
6
|
my $caller = caller; |
|
207
|
2
|
|
|
|
|
8
|
$self->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'"); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
else { |
|
210
|
5
|
|
|
|
|
17
|
return $self->set($field, @_); |
|
211
|
|
|
|
|
|
|
} |
|
212
|
7
|
|
|
|
|
43
|
}; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
|
216
|
6
|
|
|
6
|
|
41
|
use Carp (); |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
421
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub _carp { |
|
219
|
4
|
|
|
4
|
|
7
|
my ($self, $msg) = @_; |
|
220
|
4
|
|
33
|
|
|
463
|
Carp::carp($msg || $self); |
|
221
|
4
|
|
|
|
|
21
|
return; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub _croak { |
|
225
|
8
|
|
|
8
|
|
19
|
my ($self, $msg) = @_; |
|
226
|
8
|
|
33
|
|
|
736
|
Carp::croak($msg || $self); |
|
227
|
0
|
|
|
|
|
|
return; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1; |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
__END__ |