line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# (c) 2009 by Murat Uenalan. All rights reserved. Note: This program is |
3
|
|
|
|
|
|
|
# free software; you can redistribute it and/or modify it under the same |
4
|
|
|
|
|
|
|
# terms as perl itself |
5
|
|
|
|
|
|
|
package Class::Maker::Basic::Handler::Attributes; |
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
4895
|
use Class::Maker::Basic::Constructor; #qw(defaults); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $DEBUG = 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $name; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
return \&Class::Maker::Basic::Constructor::new; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub simple_new |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
return \&Class::Maker::Basic::Constructor::simple_new; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub debug_verbose |
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
my $name = $name; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return sub |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
warn "$name: it works..." if $DEBUG; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# The scheme is as following: |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
# - First a package that handles the handler calls internally is created, |
39
|
|
|
|
|
|
|
# such as the following package Class::Maker::Basic::Handler::Attributes::default; |
40
|
|
|
|
|
|
|
# But for accession of these a proxy method is called that is 'sub default' that installs the sub with the approriate name |
41
|
|
|
|
|
|
|
# that is defined in the package Class::Maker::Basic::Handler::Attributes::name scalar. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# create an "lvalue" attribute handler, which also accepts |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
# $this->member = 'syntax' instead normal $this->member( 'syntax' ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
package Class::Maker::Basic::Handler::Attributes::default; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get : method |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
my $this = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $name = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return $this->{$name}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set : method |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
my $this = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $name = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $this->{$name} = shift; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# when setting the value via the constructor |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub init : method |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub reset : method |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# do reset to default value from instantiation |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub default |
81
|
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
my $name = $name; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return sub : lvalue |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
my $this = shift; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $name = $name; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
warn __PACKAGE__.":".__LINE__." setting method $name" if $DEBUG; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
if( @_ ) |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::default::set( $this, $name, shift ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::default::get( $this, $name ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$this->{$name}; |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
package Class::Maker::Basic::Handler::Attributes::array; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Carp; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get : method |
112
|
|
|
|
|
|
|
{ |
113
|
|
|
|
|
|
|
my $this = shift; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $name = shift; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return $this->{$name}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub set : method |
121
|
|
|
|
|
|
|
{ |
122
|
|
|
|
|
|
|
my $this = shift; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $name = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
use Carp qw(cluck); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
cluck "Array reference expected" unless ref( $_[0] ) eq 'ARRAY'; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
return @{ $this->{$name} } = @{ $_[0] }; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# when setting the value via the constructor |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub init : method |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
my $this = shift; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $name = shift; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
return $this->{$name} = shift; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub reset : method |
145
|
|
|
|
|
|
|
{ |
146
|
|
|
|
|
|
|
# do reset to default value from instantiation |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub array |
151
|
|
|
|
|
|
|
{ |
152
|
|
|
|
|
|
|
my $name = $name; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
return sub |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
my $this = shift; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $name = $name; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
warn __PACKAGE__.":".__LINE__." setting method $name" if $DEBUG; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::array::init( $this, $name, [] ) unless exists $this->{$name}; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::array::set( $this, $name, @_ ) if @_; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
if( wantarray ) |
168
|
|
|
|
|
|
|
{ |
169
|
|
|
|
|
|
|
return @{ Class::Maker::Basic::Handler::Attributes::array::get( $this, $name ) }; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
return Class::Maker::Basic::Handler::Attributes::array::get( $this, $name ); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
{ |
177
|
|
|
|
|
|
|
package Class::Maker::Basic::Handler::Attributes::hash; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use Carp; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub get : method |
182
|
|
|
|
|
|
|
{ |
183
|
|
|
|
|
|
|
my $this = shift; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $name = shift; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
return $this->{$name}; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub set : method |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
my $this = shift; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my $name = shift; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Carp::cluck "Hash reference expected" unless ref( $_[0] ) eq 'HASH'; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
return %{ $this->{$name} } = %{ $_[0] }; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# when setting the value via the constructor |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub init : method |
204
|
|
|
|
|
|
|
{ |
205
|
|
|
|
|
|
|
my $this = shift; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my $name = shift; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
return $this->{$name} = shift ; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub reset : method |
213
|
|
|
|
|
|
|
{ |
214
|
|
|
|
|
|
|
# do reset to default value from instantiation |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub hash |
219
|
|
|
|
|
|
|
{ |
220
|
|
|
|
|
|
|
my $name = $name; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
return sub |
223
|
|
|
|
|
|
|
{ |
224
|
|
|
|
|
|
|
my $this = shift; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
my $name = $name; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
warn __PACKAGE__.":".__LINE__." setting method $name" if $DEBUG; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::hash::init( $this, $name, {} ) unless exists $this->{$name}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Class::Maker::Basic::Handler::Attributes::hash::set( $this, $name, @_ ) if @_; |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
if( wantarray ) |
235
|
|
|
|
|
|
|
{ |
236
|
|
|
|
|
|
|
return %{ Class::Maker::Basic::Handler::Attributes::hash::get( $this, $name ) }; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
return Class::Maker::Basic::Handler::Attributes::hash::get( $this, $name ); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
1; |