line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Anansi::Singleton; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Anansi::Singleton - A base module definition where only a single object instance |
7
|
|
|
|
|
|
|
is allowed. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Anansi::Example; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use base qw(Anansi::Singleton); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub finalise { |
16
|
|
|
|
|
|
|
my ($self, %parameters) = @_; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub fixate { |
20
|
|
|
|
|
|
|
my ($self, %parameters) = @_; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub initialise { |
24
|
|
|
|
|
|
|
my ($self, %parameters) = @_; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub reinitialise { |
28
|
|
|
|
|
|
|
my ($self, %parameters) = @_; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package main; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Anansi::Example; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $object = Anansi::Example->new(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This is a base module definition that manages the creation and destruction of |
44
|
|
|
|
|
|
|
module object instances that are not repeatable including embedded objects and |
45
|
|
|
|
|
|
|
ensures that destruction can only occur when all duplicate object instances are |
46
|
|
|
|
|
|
|
no longer used. Uses L, L and L. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
66635
|
use base qw(Anansi::Class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
505
|
|
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
7518
|
use Anansi::ObjectManager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
387
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $NAMESPACE = {}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 Anansi::Class |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
See L for details. A parent module of |
69
|
|
|
|
|
|
|
L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head3 DESTROY |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
See L for details. Overridden |
77
|
|
|
|
|
|
|
by L. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head3 finalise |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
See L for details. A virtual |
85
|
|
|
|
|
|
|
method. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head3 implicate |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L for details. A |
93
|
|
|
|
|
|
|
virtual method. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 import |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See L for details. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head3 initialise |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
See L for details. A |
108
|
|
|
|
|
|
|
virtual method. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head3 new |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
See L for details. Overridden by |
116
|
|
|
|
|
|
|
L. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head3 old |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See L for details. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head3 used |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
See L for details. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head3 uses |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
See L for details. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 using |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
See L for details. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 DESTROY |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item self I<(Blessed Hash, Required)> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
An object of this namespace. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Overrides L. Performs module |
160
|
|
|
|
|
|
|
object instance clean-up actions. Either calls the |
161
|
|
|
|
|
|
|
L method prior to dereferencing an instance |
162
|
|
|
|
|
|
|
of the object where more than one instance exists or the |
163
|
|
|
|
|
|
|
L method prior to dereferencing the last |
164
|
|
|
|
|
|
|
instance. Indirectly called by the perl interpreter. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub DESTROY { |
170
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
171
|
0
|
|
|
|
|
|
my $objectManager = Anansi::ObjectManager->new(); |
172
|
0
|
0
|
|
|
|
|
if(1 == $objectManager->registrations($self)) { |
|
|
0
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
$self->finalise(); |
174
|
0
|
|
|
|
|
|
$objectManager->obsolete( |
175
|
|
|
|
|
|
|
USER => $self, |
176
|
|
|
|
|
|
|
); |
177
|
0
|
|
|
|
|
|
$objectManager->unregister($self); |
178
|
|
|
|
|
|
|
} elsif(1 < $objectManager->registrations($self)) { |
179
|
0
|
|
|
|
|
|
$self->fixate(); |
180
|
0
|
|
|
|
|
|
$objectManager->unregister($self); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 fixate |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$OBJECT->fixate(); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$OBJECT->SUPER::fixate(); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item self I<(Blessed Hash, Required)> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
An object of this namespace. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item parameters I<(Hash, Optional)> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Named parameters. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
A virtual method. Called just prior to module instance object destruction where |
204
|
|
|
|
|
|
|
there are multiple instances of the object remaining. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub fixate { |
210
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 new |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $object = Anansi::Example->new(); |
217
|
|
|
|
|
|
|
my $object = Anansi::Example->new( |
218
|
|
|
|
|
|
|
SETTING => 'example', |
219
|
|
|
|
|
|
|
); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over 4 |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item class I<(Blessed Hash B String, Required)> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Either an object or a string of this namespace. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item parameters I<(Hash, Optional)> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Named parameters. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=back |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Overrides L. Instantiates or |
234
|
|
|
|
|
|
|
reinstantiates an object instance of a module. Either calls the |
235
|
|
|
|
|
|
|
L method with the supplied I |
236
|
|
|
|
|
|
|
after the object is first instantiated or the |
237
|
|
|
|
|
|
|
L method after subsequent |
238
|
|
|
|
|
|
|
instantiations. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub new { |
244
|
0
|
|
|
0
|
1
|
|
my ($class, %parameters) = @_; |
245
|
0
|
0
|
|
|
|
|
return if(ref($class) =~ /^(ARRAY|CODE|FORMAT|GLOB|HASH|IO|LVALUE|REF|Regexp|SCALAR|VSTRING)$/i); |
246
|
0
|
0
|
|
|
|
|
$class = ref($class) if(ref($class) !~ /^$/); |
247
|
0
|
0
|
|
|
|
|
if(!defined($NAMESPACE->{$class})) { |
248
|
0
|
|
|
|
|
|
my $self = { |
249
|
|
|
|
|
|
|
NAMESPACE => $class, |
250
|
|
|
|
|
|
|
PACKAGE => __PACKAGE__, |
251
|
|
|
|
|
|
|
}; |
252
|
0
|
|
|
|
|
|
$NAMESPACE->{$class} = bless($self, $class); |
253
|
0
|
|
|
|
|
|
my $objectManager = Anansi::ObjectManager->new(); |
254
|
0
|
|
|
|
|
|
$objectManager->register($NAMESPACE->{$class}); |
255
|
0
|
|
|
|
|
|
$NAMESPACE->{$class}->initialise(%parameters); |
256
|
|
|
|
|
|
|
} else { |
257
|
0
|
|
|
|
|
|
my $objectManager = Anansi::ObjectManager->new(); |
258
|
0
|
|
|
|
|
|
$objectManager->register($NAMESPACE->{$class}); |
259
|
0
|
|
|
|
|
|
$NAMESPACE->{$class}->reinitialise(%parameters); |
260
|
|
|
|
|
|
|
} |
261
|
0
|
|
|
|
|
|
return $NAMESPACE->{$class}; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 reinitialise |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
$OBJECT->reinitialise(); |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
$OBJECT->SUPER::reinitialise(); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=over 4 |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item self I<(Blessed Hash, Required)> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
An object of this namespace. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item parameters I<(Hash, Optional)> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Named parameters. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=back |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
A virtual method. Called just after module instance object recreation. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub reinitialise { |
289
|
0
|
|
|
0
|
1
|
|
my ($self, %parameters) = @_; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head1 NOTES |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
This module is designed to make it simple, easy and quite fast to code your |
296
|
|
|
|
|
|
|
design in perl. If for any reason you feel that it doesn't achieve these goals |
297
|
|
|
|
|
|
|
then please let me know. I am here to help. All constructive criticisms are |
298
|
|
|
|
|
|
|
also welcomed. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 AUTHOR |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Kevin Treleaven treleaven I net> |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=cut |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
1; |
311
|
|
|
|
|
|
|
|