line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PObject::Driver; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Driver.pm,v 1.19 2003/11/07 00:36:21 sherzodr Exp $ |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
22
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
144
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
5
|
|
|
5
|
|
19
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
290
|
|
8
|
5
|
|
|
5
|
|
25
|
use Log::Agent; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
422
|
|
9
|
5
|
|
|
5
|
|
23
|
use vars ('$VERSION'); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
802
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '2.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Preloaded methods go here. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
5
|
|
|
5
|
0
|
14
|
my $class = shift; |
17
|
5
|
|
33
|
|
|
35
|
$class = ref($class) || $class; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
203
|
logtrc 3, "%s->new()", $class; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
485
|
my $self = { |
22
|
|
|
|
|
|
|
_stash => { }, |
23
|
|
|
|
|
|
|
}; |
24
|
5
|
|
|
|
|
30
|
return bless($self, $class) |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
0
|
|
|
sub DESTROY { } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub errstr { |
32
|
1
|
|
|
1
|
1
|
2
|
my ($self, $errstr) = @_; |
33
|
1
|
|
33
|
|
|
4
|
my $class = ref($self) || $self; |
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
5
|
|
25
|
no strict 'refs'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
6214
|
|
36
|
1
|
50
|
|
|
|
4
|
if ( defined $errstr ) { |
37
|
1
|
|
|
|
|
1
|
${ "$class\::errstr" } = $errstr |
|
1
|
|
|
|
|
4
|
|
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
1
|
return ${ "$class\::errstr" } |
|
1
|
|
|
|
|
3
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub stash { |
46
|
1
|
|
|
1
|
1
|
4
|
my ($self, $key, $value) = @_; |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
33
|
|
|
5
|
if ( defined($key) && defined($value) ) { |
49
|
0
|
|
|
|
|
0
|
$self->{_stash}->{$key} = $value |
50
|
|
|
|
|
|
|
} |
51
|
1
|
|
|
|
|
7
|
return $self->{_stash}->{$key} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub dump { |
58
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
61
|
0
|
|
|
|
|
0
|
my $d = new Data::Dumper([$self], [ref $self]); |
62
|
0
|
|
|
|
|
0
|
return $d->Dump() |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub save { |
67
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
68
|
0
|
|
|
|
|
0
|
my ($object_name, $props, $columns) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
croak "'$object_name' object doesn't support 'save()' method" |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub load { |
74
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
75
|
0
|
|
|
|
|
0
|
my ($object_name, $props, $id) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
croak "'$object_name' doesn't support 'load()' method" |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_ids { |
83
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
84
|
0
|
|
|
|
|
0
|
my ($object_name, $props, $terms, $args) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
croak "'$object_name' doesn't support 'load()' method" |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub remove { |
92
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
93
|
0
|
|
|
|
|
0
|
my ($object_name, $props, $id) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
croak "'$object_name' doesn't support 'remove()' method" |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub drop_datasource { |
99
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
100
|
0
|
|
|
|
|
0
|
my ($object_name, $props) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
croak "'$object_name' doesn't support 'drop_datasource()' method" |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub remove_all { |
107
|
6
|
|
|
6
|
1
|
11
|
my $self = shift; |
108
|
6
|
|
33
|
|
|
24
|
my $class = ref($self) || $self; |
109
|
6
|
|
|
|
|
12
|
my ($object_name, $props, $terms) = @_; |
110
|
|
|
|
|
|
|
|
111
|
6
|
|
|
|
|
161
|
logtrc 3, "%s->remove_all(%s)", $class, join ", ", @_; |
112
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
487
|
my $data_set = $self->load_ids($object_name, $props, $terms); |
114
|
6
|
|
|
|
|
18
|
for ( @$data_set ) { |
115
|
6
|
|
|
|
|
30
|
$self->remove($object_name, $props, $_) |
116
|
|
|
|
|
|
|
} |
117
|
6
|
|
|
|
|
26
|
return 1 |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub count { |
124
|
17
|
|
|
17
|
1
|
25
|
my $self = shift; |
125
|
17
|
|
33
|
|
|
49
|
my $class = ref($self) || $self; |
126
|
17
|
|
|
|
|
23
|
my ($object_name, $props, $terms) = @_; |
127
|
|
|
|
|
|
|
|
128
|
17
|
|
|
|
|
400
|
logtrc 3, "%s->count(%s)", $class, join ", ", @_; |
129
|
|
|
|
|
|
|
|
130
|
17
|
|
|
|
|
1273
|
my $data_set = $self->load_ids($object_name, $props, $terms); |
131
|
17
|
|
100
|
|
|
148
|
return scalar( @$data_set ) || 0 |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _filter_by_args { |
144
|
15
|
|
|
15
|
|
18
|
my ($self, $data_set, $args) = @_; |
145
|
|
|
|
|
|
|
|
146
|
15
|
50
|
|
|
|
23
|
unless ( keys %$args ) { |
147
|
0
|
|
|
|
|
0
|
return $data_set |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
# if sorting column was defined |
150
|
15
|
50
|
|
|
|
33
|
if ( defined $args->{'sort'} ) { |
151
|
|
|
|
|
|
|
# default to 'asc' sorting direction if it was not specified |
152
|
15
|
|
100
|
|
|
36
|
$args->{direction} ||= 'asc'; |
153
|
|
|
|
|
|
|
# and sort the data set |
154
|
15
|
100
|
|
|
|
29
|
if ( $args->{direction} eq 'desc' ) { |
155
|
6
|
|
|
|
|
20
|
$data_set = [ sort {$b->{$args->{'sort'}} cmp $a->{$args->{'sort'}} } @$data_set] |
|
16
|
|
|
|
|
36
|
|
156
|
|
|
|
|
|
|
} else { |
157
|
9
|
|
|
|
|
27
|
$data_set = [ sort {$a->{$args->{'sort'}} cmp $b->{$args->{'sort'}} } @$data_set] |
|
16
|
|
|
|
|
41
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
# if 'limit' was defined |
161
|
15
|
100
|
|
|
|
34
|
if ( defined $args->{limit} ) { |
162
|
|
|
|
|
|
|
# default to 0 for 'offset' if 'offset' was not set |
163
|
7
|
|
100
|
|
|
28
|
$args->{offset} ||= 0; |
164
|
|
|
|
|
|
|
# and splice the data set |
165
|
7
|
|
|
|
|
27
|
return [splice(@$data_set, $args->{offset}, $args->{limit})] |
166
|
|
|
|
|
|
|
} |
167
|
8
|
|
|
|
|
18
|
return $data_set |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _matches_terms { |
176
|
95
|
|
|
95
|
|
107
|
my $self = shift; |
177
|
95
|
|
33
|
|
|
173
|
my $class = ref($self) || $self; |
178
|
95
|
|
|
|
|
98
|
my ($data, $terms) = @_; |
179
|
|
|
|
|
|
|
|
180
|
95
|
|
|
|
|
2041
|
logtrc 3, "%s->_matches_terms(@_)", $class; |
181
|
95
|
100
|
|
|
|
5669
|
unless ( keys %$terms ) { |
182
|
50
|
|
|
|
|
135
|
return 1 |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
# otherwise check this data set against all the terms |
185
|
|
|
|
|
|
|
# provided. If even one of those terms are not satisfied, |
186
|
|
|
|
|
|
|
# return false |
187
|
45
|
|
|
|
|
126
|
while ( my ($column, $value) = each %$terms ) { |
188
|
49
|
|
|
|
|
63
|
$^W = 0; |
189
|
49
|
100
|
|
|
|
129
|
if ( $data->{$column} ne $value ) { |
190
|
24
|
|
|
|
|
203
|
return 0 |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
21
|
|
|
|
|
59
|
return 1 |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub freeze { |
200
|
12
|
|
|
12
|
1
|
24
|
my ($self, $object_name, $props, $data) = @_; |
201
|
|
|
|
|
|
|
|
202
|
12
|
|
|
|
|
17
|
my $rv = undef; |
203
|
12
|
50
|
|
|
|
65
|
if ( $props->{serializer} eq "xml" ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
204
|
0
|
|
|
|
|
0
|
require Data::DumpXML; |
205
|
0
|
|
|
|
|
0
|
$rv = Data::DumpXML::dump_xml($data) |
206
|
|
|
|
|
|
|
} elsif ( $props->{serializer} eq "dumper" ) { |
207
|
0
|
|
|
|
|
0
|
require Data::Dumper; |
208
|
0
|
|
|
|
|
0
|
my $d = Data::Dumper->new([$data]); |
209
|
0
|
|
|
|
|
0
|
$d->Terse(1); |
210
|
0
|
|
|
|
|
0
|
$d->Indent(0); |
211
|
0
|
|
|
|
|
0
|
$rv = $d->Dump(); |
212
|
|
|
|
|
|
|
} elsif ( $props->{serializer} eq 'freezethaw' ) { |
213
|
0
|
|
|
|
|
0
|
require FreezeThaw; |
214
|
0
|
|
|
|
|
0
|
$rv = FreezeThaw::freeze($data) |
215
|
|
|
|
|
|
|
} else { |
216
|
12
|
|
|
|
|
2607
|
require Storable; |
217
|
12
|
|
|
|
|
11542
|
$rv = Storable::freeze( $data ) |
218
|
|
|
|
|
|
|
} |
219
|
12
|
|
|
|
|
727
|
return $rv |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub thaw { |
226
|
145
|
|
|
145
|
1
|
228
|
my ($self, $object_name, $props, $datastr) = @_; |
227
|
|
|
|
|
|
|
|
228
|
145
|
50
|
|
|
|
216
|
unless ( $datastr ) { |
229
|
|
|
|
|
|
|
return undef |
230
|
0
|
|
|
|
|
0
|
} |
231
|
|
|
|
|
|
|
|
232
|
145
|
|
|
|
|
142
|
my $rv = undef; |
233
|
145
|
50
|
|
|
|
465
|
if ( $props->{serializer} eq "xml" ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
234
|
0
|
|
|
|
|
0
|
require Data::DumpXML::Parser; |
235
|
0
|
|
|
|
|
0
|
my $p = Data::DumpXML::Parser->new(); |
236
|
0
|
|
|
|
|
0
|
warn "parsing '$datastr'"; |
237
|
0
|
|
|
|
|
0
|
$rv = $p->parse($datastr) |
238
|
|
|
|
|
|
|
} elsif ( $props->{serializer} eq "dumper" ) { |
239
|
0
|
|
|
|
|
0
|
$rv = eval $datastr; |
240
|
|
|
|
|
|
|
} elsif ( $props->{serializer} eq 'freezethaw' ) { |
241
|
0
|
|
|
|
|
0
|
require FreezeThaw; |
242
|
0
|
|
|
|
|
0
|
$rv = (FreezeThaw::thaw($datastr))[0] |
243
|
|
|
|
|
|
|
} else { |
244
|
145
|
|
|
|
|
592
|
require Storable; |
245
|
145
|
|
|
|
|
315
|
$rv = Storable::thaw( $datastr ); |
246
|
|
|
|
|
|
|
} |
247
|
145
|
|
|
|
|
2418
|
return $rv |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |
257
|
|
|
|
|
|
|
__END__ |