| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
######################################################################## |
|
2
|
|
|
|
|
|
|
# File: Base.pm |
|
3
|
|
|
|
|
|
|
# Author: David Winters |
|
4
|
|
|
|
|
|
|
# RCS: $Id: Base.pm,v 1.9 2000/02/08 02:36:40 winters Exp winters $ |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# An abstract base class for persistent datatype objects. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# Copyright (c) 1998-2000 David Winters. All rights reserved. |
|
9
|
|
|
|
|
|
|
# This program is free software; you can redistribute it |
|
10
|
|
|
|
|
|
|
# and/or modify it under the same terms as Perl itself. |
|
11
|
|
|
|
|
|
|
######################################################################## |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Persistent::DataType::Base; |
|
14
|
|
|
|
|
|
|
require 5.004; |
|
15
|
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
24
|
use strict; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
184
|
|
|
17
|
5
|
|
|
5
|
|
34
|
use vars qw($VERSION $REVISION); |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
281
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
3330
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
### copy version number from Persistent::Base class ### |
|
22
|
|
|
|
|
|
|
$VERSION = $Persistent::Base::VERSION; |
|
23
|
|
|
|
|
|
|
$REVISION = (qw$Revision: 1.9 $)[1]; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Persistent::DataType::Base - An Abstract DataType Base Class |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
### we are a subclass of ... ### |
|
32
|
|
|
|
|
|
|
use Persistent::DataType::Base; |
|
33
|
|
|
|
|
|
|
@ISA = qw(Persistent::DataType::Base); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 ABSTRACT |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This is an abstract base class used by the Persistent framework of |
|
38
|
|
|
|
|
|
|
classes to implement the attributes of objects. This class provides |
|
39
|
|
|
|
|
|
|
methods for implementing data types. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This class is not instantiated. Instead, it is inherited from or |
|
42
|
|
|
|
|
|
|
subclassed by DataType classes. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This class is part of the Persistent base package which is available |
|
45
|
|
|
|
|
|
|
from: |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
http://www.bigsnow.org/persistent |
|
48
|
|
|
|
|
|
|
ftp://ftp.bigsnow.org/pub/persistent |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Before we get started describing the methods in detail, it should be |
|
53
|
|
|
|
|
|
|
noted that all error handling in this class is done with exceptions. |
|
54
|
|
|
|
|
|
|
So you should wrap an eval block around all of your code. Please see |
|
55
|
|
|
|
|
|
|
the L documentation for more information on exception |
|
56
|
|
|
|
|
|
|
handling in Perl. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 METHODS |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
######################################################################## |
|
63
|
|
|
|
|
|
|
# |
|
64
|
|
|
|
|
|
|
# -------------- |
|
65
|
|
|
|
|
|
|
# PUBLIC METHODS |
|
66
|
|
|
|
|
|
|
# -------------- |
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
# NOTE: These methods do not need to be overridden in the subclasses. |
|
69
|
|
|
|
|
|
|
# However, you may certainly override these methods if you see |
|
70
|
|
|
|
|
|
|
# the need to. Perhaps, for performance or reuseability reasons. |
|
71
|
|
|
|
|
|
|
# |
|
72
|
|
|
|
|
|
|
######################################################################## |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
######################################################################## |
|
75
|
|
|
|
|
|
|
# Function: new |
|
76
|
|
|
|
|
|
|
# Description: Object constructor. |
|
77
|
|
|
|
|
|
|
# Parameters: @params = initialization parameters |
|
78
|
|
|
|
|
|
|
# Returns: $this = reference to the newly allocated object |
|
79
|
|
|
|
|
|
|
######################################################################## |
|
80
|
|
|
|
|
|
|
sub new { |
|
81
|
55
|
|
|
55
|
0
|
69
|
my $proto = shift; |
|
82
|
55
|
|
33
|
|
|
213
|
my $class = ref($proto) || $proto; |
|
83
|
|
|
|
|
|
|
|
|
84
|
55
|
|
|
|
|
82
|
my $this = {}; ### allocate a hash for the object's data ### |
|
85
|
55
|
|
|
|
|
118
|
bless $this, $class; |
|
86
|
55
|
|
|
|
|
145
|
$this->_trace(); |
|
87
|
55
|
|
|
|
|
168
|
$this->initialize(@_); ### call hook for subclass initialization ### |
|
88
|
|
|
|
|
|
|
|
|
89
|
55
|
|
|
|
|
191
|
return $this; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
######################################################################## |
|
93
|
|
|
|
|
|
|
# Function: DESTROY |
|
94
|
|
|
|
|
|
|
# Description: Object destructor. |
|
95
|
|
|
|
|
|
|
# Parameters: None |
|
96
|
|
|
|
|
|
|
# Returns: None |
|
97
|
|
|
|
|
|
|
######################################################################## |
|
98
|
|
|
|
|
|
|
sub DESTROY { |
|
99
|
55
|
|
|
55
|
|
67
|
my $this = shift; |
|
100
|
|
|
|
|
|
|
|
|
101
|
55
|
|
|
|
|
94
|
$this->_trace(); |
|
102
|
|
|
|
|
|
|
|
|
103
|
55
|
|
|
|
|
293
|
0; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
######################################################################## |
|
107
|
|
|
|
|
|
|
# debug |
|
108
|
|
|
|
|
|
|
######################################################################## |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 debug -- Accesses the Debugging Flag |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
### set the debugging flag ### |
|
113
|
|
|
|
|
|
|
$object->debug($flag); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
### get the debugging flag ### |
|
116
|
|
|
|
|
|
|
$flag = $object->debug(); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns (and optionally sets) the debugging flag of an object. This |
|
119
|
|
|
|
|
|
|
method does not throw Perl execeptions. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Parameters: |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over 4 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item I<$flag> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
If set to a true value then debugging is on, otherwise, a false value |
|
128
|
|
|
|
|
|
|
means off. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub debug { |
|
135
|
0
|
0
|
|
0
|
1
|
0
|
(@_ == 2) or croak 'Usage: $obj->debug($flag)'; |
|
136
|
0
|
|
|
|
|
0
|
my $this = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
$this->_trace(); |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
0
|
$this->{Debug} = shift if @_; |
|
141
|
0
|
|
|
|
|
0
|
$this->{Debug}; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
######################################################################## |
|
145
|
|
|
|
|
|
|
# |
|
146
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
147
|
|
|
|
|
|
|
# PUBLIC ABSTRACT METHODS TO BE OVERRIDDEN (REDEFINED) IN THE DERIVED CLASS |
|
148
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
149
|
|
|
|
|
|
|
# |
|
150
|
|
|
|
|
|
|
# NOTE: These methods MUST be overridden in the subclasses. |
|
151
|
|
|
|
|
|
|
# In order, for even a minimal subclass to work, you must |
|
152
|
|
|
|
|
|
|
# override these methods in the subclass. |
|
153
|
|
|
|
|
|
|
# |
|
154
|
|
|
|
|
|
|
######################################################################## |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
######################################################################## |
|
157
|
|
|
|
|
|
|
# initialize |
|
158
|
|
|
|
|
|
|
######################################################################## |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 Constructor -- Creates a DataType Object |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
eval { |
|
163
|
|
|
|
|
|
|
my $datatype = new Persistent::DataType::Object(@args); |
|
164
|
|
|
|
|
|
|
}; |
|
165
|
|
|
|
|
|
|
croak "Exception caught: $@" if $@; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Initializes a data type object. This method throws Perl execeptions |
|
168
|
|
|
|
|
|
|
so use it with an eval block. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This method is abstract and needs implementing. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub initialize { |
|
175
|
0
|
0
|
|
0
|
0
|
0
|
(@_ > 0) or croak 'Usage: $obj->initialize(...args...)'; |
|
176
|
0
|
|
|
|
|
0
|
my $this = shift; |
|
177
|
0
|
0
|
|
|
|
0
|
ref($this) or croak "$this is not an object"; |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
$this->_trace(); |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
croak "method not implemented"; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
######################################################################## |
|
185
|
|
|
|
|
|
|
# value |
|
186
|
|
|
|
|
|
|
######################################################################## |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 value -- Accesses the Value of the DataType |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
eval { |
|
191
|
|
|
|
|
|
|
### set the value ### |
|
192
|
|
|
|
|
|
|
$datatype->value($new_value); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
### get the value ### |
|
195
|
|
|
|
|
|
|
$value = $datatype->value(); |
|
196
|
|
|
|
|
|
|
}; |
|
197
|
|
|
|
|
|
|
croak "Exception caught: $@" if $@; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns (and optionally sets) the value of a DataType object. This |
|
200
|
|
|
|
|
|
|
method throws Perl execeptions so use it with an eval block. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This method is abstract and needs implementing. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub value { |
|
207
|
0
|
0
|
|
0
|
1
|
0
|
(@_ > 0) or croak 'Usage: $obj->value(...args...)'; |
|
208
|
0
|
|
|
|
|
0
|
my $this = shift; |
|
209
|
0
|
0
|
|
|
|
0
|
ref($this) or croak "$this is not an object"; |
|
210
|
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
0
|
$this->_trace(); |
|
212
|
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
0
|
croak "method not implemented"; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
######################################################################## |
|
217
|
|
|
|
|
|
|
# get_compare_op |
|
218
|
|
|
|
|
|
|
######################################################################## |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 get_compare_op -- Returns the Comparison Operator |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
$cmp_op = $obj->get_compare_op(); |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Returns the comparison operator of a DataType object. This method |
|
225
|
|
|
|
|
|
|
does not throw Perl execeptions. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This method is abstract and needs implementing. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Can return a couple of different comparison operators: |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over 4 |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item 'cmp' |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
if the value of the object should be compared as a string. |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item '<=>' |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
if the value of the object should be compared as a number. |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub get_compare_op { |
|
246
|
0
|
0
|
|
0
|
1
|
0
|
(@_ == 1) or croak 'Usage: $obj->get_compare_op()'; |
|
247
|
0
|
|
|
|
|
0
|
my $this = shift; |
|
248
|
0
|
0
|
|
|
|
0
|
ref($this) or croak "$this is not an object"; |
|
249
|
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
0
|
$this->_trace(); |
|
251
|
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
0
|
croak "method not implemented"; |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
######################################################################## |
|
256
|
|
|
|
|
|
|
# |
|
257
|
|
|
|
|
|
|
# --------------- |
|
258
|
|
|
|
|
|
|
# PRIVATE METHODS |
|
259
|
|
|
|
|
|
|
# --------------- |
|
260
|
|
|
|
|
|
|
# |
|
261
|
|
|
|
|
|
|
# NOTE: These methods do not need to be overridden in the subclasses. |
|
262
|
|
|
|
|
|
|
# However, you may certainly override these methods if you see |
|
263
|
|
|
|
|
|
|
# the need to. |
|
264
|
|
|
|
|
|
|
# |
|
265
|
|
|
|
|
|
|
######################################################################## |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
######################################################################## |
|
268
|
|
|
|
|
|
|
# Function: _trace |
|
269
|
|
|
|
|
|
|
# Description: trace functions for debugging |
|
270
|
|
|
|
|
|
|
# Parameters: None |
|
271
|
|
|
|
|
|
|
# Returns: None |
|
272
|
|
|
|
|
|
|
######################################################################## |
|
273
|
|
|
|
|
|
|
sub _trace { |
|
274
|
915
|
|
|
915
|
|
1242
|
my $this = shift; |
|
275
|
|
|
|
|
|
|
|
|
276
|
915
|
50
|
|
|
|
2663
|
if ($this->{Debug}) { |
|
277
|
0
|
|
|
|
|
|
my $i = 1; |
|
278
|
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
my ($package, $filename, $line, $subroutine) = caller($i); |
|
280
|
0
|
|
|
|
|
|
my $msg = "$subroutine() ... "; |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
for ($i = 1; my $f = caller($i); $i++) {} |
|
283
|
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
($package, $filename, $line, $subroutine) = caller($i - 1); |
|
285
|
0
|
|
|
|
|
|
$msg .= "$subroutine() called from $filename $line\n"; |
|
286
|
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
warn $msg; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
### end of library ### |
|
292
|
|
|
|
|
|
|
1; |
|
293
|
|
|
|
|
|
|
__END__ |