line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PObject::Driver; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Driver.pm,v 1.19 2003/11/07 00:36:21 sherzodr Exp |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
89
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
188
|
|
8
|
3
|
|
|
3
|
|
16
|
use Log::Agent; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
283
|
|
9
|
3
|
|
|
3
|
|
17
|
use vars ('$VERSION'); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
455
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '2.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Preloaded methods go here. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
3
|
|
|
3
|
0
|
8
|
my $class = shift; |
17
|
3
|
|
33
|
|
|
23
|
$class = ref($class) || $class; |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
117
|
logtrc 3, "%s->new()", $class; |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
322
|
my $self = { |
22
|
|
|
|
|
|
|
_stash => { }, |
23
|
|
|
|
|
|
|
}; |
24
|
3
|
|
|
|
|
14
|
return bless($self, $class) |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub errstr { |
32
|
1
|
|
|
1
|
1
|
3
|
my ($self, $errstr) = @_; |
33
|
1
|
|
33
|
|
|
4
|
my $class = ref($self) || $self; |
34
|
|
|
|
|
|
|
|
35
|
3
|
|
|
3
|
|
23
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
4003
|
|
36
|
1
|
50
|
|
|
|
4
|
if ( defined $errstr ) { |
37
|
1
|
|
|
|
|
2
|
${ "$class\::errstr" } = $errstr |
|
1
|
|
|
|
|
5
|
|
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
2
|
return ${ "$class\::errstr" } |
|
1
|
|
|
|
|
4
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub stash { |
46
|
0
|
|
|
0
|
1
|
0
|
my ($self, $key, $value) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
0
|
if ( defined($key) && defined($value) ) { |
49
|
0
|
|
|
|
|
0
|
$self->{_stash}->{$key} = $value |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
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
|
5
|
|
|
5
|
1
|
10
|
my $self = shift; |
108
|
5
|
|
33
|
|
|
20
|
my $class = ref($self) || $self; |
109
|
5
|
|
|
|
|
13
|
my ($object_name, $props, $terms) = @_; |
110
|
|
|
|
|
|
|
|
111
|
5
|
|
|
|
|
157
|
logtrc 3, "%s->remove_all(%s)", $class, join ", ", @_; |
112
|
|
|
|
|
|
|
|
113
|
5
|
|
|
|
|
502
|
my $data_set = $self->load_ids($object_name, $props, $terms); |
114
|
5
|
|
|
|
|
18
|
for ( @$data_set ) { |
115
|
5
|
|
|
|
|
26
|
$self->remove($object_name, $props, $_) |
116
|
|
|
|
|
|
|
} |
117
|
5
|
|
|
|
|
24
|
return 1 |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub count { |
124
|
15
|
|
|
15
|
1
|
22
|
my $self = shift; |
125
|
15
|
|
33
|
|
|
45
|
my $class = ref($self) || $self; |
126
|
15
|
|
|
|
|
27
|
my ($object_name, $props, $terms) = @_; |
127
|
|
|
|
|
|
|
|
128
|
15
|
|
|
|
|
486
|
logtrc 3, "%s->count(%s)", $class, join ", ", @_; |
129
|
|
|
|
|
|
|
|
130
|
15
|
|
|
|
|
1682
|
my $data_set = $self->load_ids($object_name, $props, $terms); |
131
|
15
|
|
100
|
|
|
171
|
return scalar( @$data_set ) || 0 |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _filter_by_args { |
144
|
17
|
|
|
17
|
|
35
|
my ($self, $data_set, $args) = @_; |
145
|
|
|
|
|
|
|
|
146
|
17
|
50
|
|
|
|
74
|
unless ( keys %$args ) { |
147
|
0
|
|
|
|
|
0
|
return $data_set |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
# if sorting column was defined |
150
|
17
|
50
|
|
|
|
57
|
if ( defined $args->{'sort'} ) { |
151
|
|
|
|
|
|
|
# default to 'asc' sorting direction if it was not specified |
152
|
17
|
|
100
|
|
|
76
|
$args->{direction} ||= 'asc'; |
153
|
|
|
|
|
|
|
# and sort the data set |
154
|
17
|
100
|
|
|
|
140
|
if ( $args->{direction} eq 'desc' ) { |
155
|
6
|
|
|
|
|
32
|
$data_set = [ sort {$b->{$args->{'sort'}} cmp $a->{$args->{'sort'}} } @$data_set] |
|
16
|
|
|
|
|
65
|
|
156
|
|
|
|
|
|
|
} else { |
157
|
11
|
|
|
|
|
55
|
$data_set = [ sort {$a->{$args->{'sort'}} cmp $b->{$args->{'sort'}} } @$data_set] |
|
16
|
|
|
|
|
70
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
# if 'limit' was defined |
161
|
17
|
100
|
|
|
|
54
|
if ( defined $args->{limit} ) { |
162
|
|
|
|
|
|
|
# default to 0 for 'offset' if 'offset' was not set |
163
|
9
|
|
100
|
|
|
45
|
$args->{offset} ||= 0; |
164
|
|
|
|
|
|
|
# and splice the data set |
165
|
9
|
|
|
|
|
51
|
return [splice(@$data_set, $args->{offset}, $args->{limit})] |
166
|
|
|
|
|
|
|
} |
167
|
8
|
|
|
|
|
23
|
return $data_set |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _matches_terms { |
176
|
93
|
|
|
93
|
|
123
|
my $self = shift; |
177
|
93
|
|
33
|
|
|
251
|
my $class = ref($self) || $self; |
178
|
93
|
|
|
|
|
147
|
my ($data, $terms) = @_; |
179
|
|
|
|
|
|
|
|
180
|
93
|
|
|
|
|
3141
|
logtrc 3, "%s->_matches_terms(@_)", $class; |
181
|
93
|
100
|
|
|
|
9000
|
unless ( keys %$terms ) { |
182
|
48
|
|
|
|
|
284
|
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
|
|
|
|
|
156
|
while ( my ($column, $value) = each %$terms ) { |
188
|
48
|
|
|
|
|
69
|
$^W = 0; |
189
|
48
|
100
|
|
|
|
169
|
if ( $data->{$column} ne $value ) { |
190
|
24
|
|
|
|
|
301
|
return 0 |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
21
|
|
|
|
|
88
|
return 1 |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub freeze { |
200
|
11
|
|
|
11
|
1
|
27
|
my ($self, $object_name, $props, $data) = @_; |
201
|
|
|
|
|
|
|
|
202
|
11
|
|
|
|
|
16
|
my $rv = undef; |
203
|
11
|
50
|
|
|
|
75
|
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
|
11
|
|
|
|
|
2549
|
require Storable; |
217
|
11
|
|
|
|
|
7016
|
$rv = Storable::freeze( $data ) |
218
|
|
|
|
|
|
|
} |
219
|
11
|
|
|
|
|
1022
|
return $rv |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub thaw { |
226
|
142
|
|
|
142
|
1
|
305
|
my ($self, $object_name, $props, $datastr) = @_; |
227
|
|
|
|
|
|
|
|
228
|
142
|
50
|
|
|
|
650
|
unless ( $datastr ) { |
229
|
|
|
|
|
|
|
return undef |
230
|
0
|
|
|
|
|
0
|
} |
231
|
|
|
|
|
|
|
|
232
|
142
|
|
|
|
|
162
|
my $rv = undef; |
233
|
142
|
50
|
|
|
|
722
|
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
|
142
|
|
|
|
|
1084
|
require Storable; |
245
|
142
|
|
|
|
|
442
|
$rv = Storable::thaw( $datastr ); |
246
|
|
|
|
|
|
|
} |
247
|
142
|
|
|
|
|
3333
|
return $rv |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |
257
|
|
|
|
|
|
|
__END__ |