lib/Data/ObjectStore.pm

filter: Statementstmt 79.8% 782 / 980 Branchbran 70.3% 228 / 324 Conditioncond 86.2% 75 / 87 MC/DCmcdc 74.0% 37 / 50 Subroutinesub 90.5% 124 / 137 Podpod 100% 19 / 19 totaltotal 79.2% 1265 / 1597 CC 220 SCAR 27.1
CC
220
Cov
78%
_transfer_obj
132.0
NEXTKEY
98.3
STORE
53.8
CRAP 15.1
« script/class_mapper.pl ↑ Summary lib/Data/ObjectStore/Cache.pm »
1 package Data::ObjectStore;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Data::RecordStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Data::ObjectStore::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 $VERSION = '2.13';
19  
20 2 our $DEBUG = 0;
21 2 our $UPGRADING;
22  
23 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 DATA_PROVIDER => 0,
25 DIRTY => 1,
26 WEAK => 2,
27 STOREINFO => 3,
28 OPTIONS => 4,
29 CACHE => 5,
30
31 ID => 0,
32 DATA => 1,
33 METADATA => 3,
34 LEVEL => 4,
35 DIRTY_BIT => 5, #for objs
36 2 };
37 2 my( @METAFIELDS ) = qw( created updated );
38  
39 34 ▶sub open_store {
Subroutine open_store: called CC=8 SCAR=20.9
Pod documented
40 34 my( $cls, @options ) = @_;
41  
42 34 ▶ die "Data::ObjectStore->open_store requires at least one argument" if 0 == @options;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == @options 1 33 34
43
44 33 ▶ if( 1 == @options ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == @options) 21 12 33
45 21 unshift @options, 'DATA_PROVIDER';
46 }
47 33 my( %options ) = @options;
48  
49 33 my $data_provider = $options{DATA_PROVIDER};
50 33 ▶ if( ! ref( $data_provider ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data_provider) 31 2 33
51 # the default record store Data::RecordStore
52 31 $options{BASE_PATH} = "$data_provider/RECORDSTORE";
53 31 $data_provider = Data::RecordStore->open_store( %options );
54 }
55 31 ▶ my $cache = $options{CACHE} ? ref( $options{CACHE} ) ? $options{CACHE} : Data::ObjectStore::Cache->new( $options{CACHE} ) : undef;
Branch: 2 branches
BranchTrueFalseTotal
$options{'CACHE'} ? : 1 30 31
ref $options{'CACHE'} ? : 1 0 1
56 31 my $store = bless [
57 $data_provider,
58 {}, #DIRTY CACHE
59 {}, #WEAK CACHE
60 undef,
61 \%options,
62 $cache,
63 ], $cls;
64  
65 31 ▶ if( ! $UPGRADING ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Data::ObjectStore::UPGRADING) 31 0 31
66 31 $store->[STOREINFO] = $store->_fetch_store_info_node;
67 31 $store->load_root_container;
68 31 ▶ if( $store->get_store_version < 1.2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store->get_store_version < "1.2") 0 31 31
69 0 die "Unable to open store of version ".$store->get_store_version.". Please run upgrade_store.";
70 }
71 31 $store->save;
72 }
73 31 return $store;
74 } #open_store
75  
76 0 ▶sub data_store {
Subroutine data_store: not called CC=1 SCAR=6.9
Pod documented
77 0 return shift->[DATA_PROVIDER];
78 }
79  
80 2 ▶sub empty_cache {
Subroutine empty_cache: called CC=2 SCAR=6.9
Pod documented
81 2 my( $self ) = @_;
82 2 ▶ if( $self->[CACHE] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[5]) 1 1 2
83 1 $self->[CACHE]->empty;
84 }
85 }
86  
87 # locks the given lock names
88 1 ▶sub lock {
Subroutine lock: called CC=1 SCAR=0.0
Pod documented
89 1 my( $self, @locknames ) = @_;
90 1 $self->[DATA_PROVIDER]->lock( @locknames );
91 }
92  
93 # unlocks all locks
94 1 ▶sub unlock {
Subroutine unlock: called CC=1 SCAR=0.0
Pod documented
95 1 my $self = shift;
96 1 $self->[DATA_PROVIDER]->unlock;
97 }
98  
99 # quick purge is not careful with memory.
100 4 ▶sub quick_purge {
Subroutine quick_purge: called CC=6 SCAR=17.9
Pod documented
101 4 my $self = shift;
102 4 my( %keep );
103 4 my( @working ) = ( 1 );
104  
105 4 my $data_provider = $self->[DATA_PROVIDER];
106 4 my $highest = $data_provider->entry_count;
107  
108 4 ▶ while( @working ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@working) 17 4 21
109 17 my $try = shift @working;
110  
111 17 $keep{$try}++;
112  
113 17 my $obj = $self->_knot( $try );
114 17 my $d = $obj->[DATA];
115 17 my %placed;
116 push @working, (
117 20 ▶ grep { ! $keep{$_} && 0 == $placed{$_}++ }
Condition100%3/3
!$keep{$_} && 0 == $placed{$_}++
!ll&&!rl&&r
6113
MC/DC100%2/2
!$keep{$_} && 0 == $placed{$_}++
!$keep{$_} 0 == $placed{$_}++
Truth table100%3/3
not(A) && B
A= !$keep{$_}B= 0 == $placed{$_}++
ABresult
0X0
100
111
118 20 map { substr( $_, 1 ) }
119 17 ▶ grep { /^r/ }
Branch: 1 branch
BranchTrueFalseTotal
ref $d eq 'ARRAY' ? : 4 13 17
120 (ref( $d ) eq 'ARRAY' ? @$d : values( %$d ) ));
121 }
122  
123 4 my $pcount;
124 4 ▶ for( my $i=1; $i<=$highest; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $highest) 27 4 31
125 27 ▶ if( ! $keep{$i} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep{$i}) 12 15 27
126 12 $data_provider->delete_record( $i );
127 12 ++$pcount;
128 }
129 }
130
131 4 return $pcount;
132 } #quick_purge
133  
134  
135 0 ▶sub upgrade_store {
Subroutine upgrade_store: not called CC=3 SCAR=24.8
Pod documented
136 0 my( $source_path, $dest_path ) = @_;
137  
138 0 ▶ die "upgrade_store destination '$dest_path' already has a store" if -e "$dest_path/RECORDSTORE";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$dest_path/RECORDSTORE" 0 0 0
139  
140 #
141 # Fetch the info directly from the record store and examine it manually.
142 #
143 0 my $from_recstore = Data::RecordStore->open_store( "$source_path/RECORDSTORE" );
144  
145 0 my $info = $from_recstore->fetch( 1 );
146 0 my( $vers ) = ( $info =~ /[ \`]ObjectStore_version\`v([^\`]*)/ );
147  
148 0 ▶ if( $vers >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vers >= 2) 0 0 0
149 0 die "Store already at version 2 or above. No upgrade needed\n";
150 }
151  
152  
153 # allows store to open old versions
154 # prevents store from creating root objects when created
155 0 $UPGRADING = 1;
156  
157 0 my $dest_store = Data::ObjectStore->open_store( "$dest_path" );
158 0 my $source_store = Data::ObjectStore->open_store( "$source_path" );
159  
160 #
161 # Clones all objects (that connect to the root) from the source
162 # store to the destination store. For this upgrade, the only thing
163 # that is missing is the object META data.
164 #
165 0 ▶ sub _transfer_obj {
Subroutine _transfer_obj: not called CC=11 SCAR=48.8
166 0 my( $source_store, $dest_store, $id, $i ) = @_;
167 0 my $ind = ' 'x$i;
168  
169 0 my $obj = $dest_store->fetch( $id );
170  
171 0 ▶ if( $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 0 0 0
172 0 return $obj;
173 } # obj
174  
175 0 my $source_thing = $source_store->_knot( $id );
176  
177 0 my $clone = ref( $source_thing )->_reconstitute( $dest_store,
178 $id,
179 _thaw( $source_thing->_freezedry ),
180 {} );
181
182 0 my $clone_thing = $dest_store->_knot( $clone );
183 0 ▶ if( ref($clone_thing) !~ /^(ARRAY|HASH|Data::ObjectStore::Hash|Data::ObjectStore::Array)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($clone_thing) =~ /^(ARRAY|HASH|Data::ObjectStore::Hash|Data::ObjectStore::Array)$/) 0 0 0
184 0 $clone_thing->[DIRTY_BIT] = 1;
185 }
186 0 my $odata = $clone_thing->[DATA];
187  
188 0 my $meta = $clone_thing->[METADATA];
189 0 my $time = time;
190 0 $meta->{created} = $time;
191 0 $meta->{updated} = $time;
192  
193 0 $dest_store->save( $clone );
194  
195 0 my( @connections );
196 0 ▶ if ( ref($odata) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $odata eq 'ARRAY') { } 0 0 0
197 0 for (0..$#$odata) {
198 0 my $oid = $odata->[$_];
199 0 ▶ if ( $oid > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid > 0) 0 0 0
200 0 $odata->[$_] = "r$oid";
201 0 ▶ if ( $oid != $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid != $id) 0 0 0
202 0 push @connections, $oid;
203 }
204 }
205 }
206 }
207 else {
208 0 for my $key (keys %$odata) {
209 0 ▶ if ( $odata->{$key} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($odata->{$key} > 0) 0 0 0
210 0 my $oid = $odata->{$key};
211 0 $odata->{$key} = "r$oid";
212 0 ▶ if ( $oid != $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid != $id) 0 0 0
213 0 push @connections, $oid;
214 }
215 }
216 }
217 }
218 0 $dest_store->save( $clone );
219  
220 0 for my $oid (@connections) {
221 0 my $connect_obj = _transfer_obj( $source_store, $dest_store, $oid, 1 + $i );
222 0 my $connect_thing = $dest_store->_knot( $connect_obj );
223 0 $dest_store->save( $connect_obj );
224 }
225  
226 0 $dest_store->fetch( $id );
227 } #_transfer_obj
228  
229 0 my $info_node = _transfer_obj( $source_store, $dest_store, 1, 0 );
230 0 $info_node->set_ObjectStore_version( $Data::RecordStore::VERSION );
231 0 $dest_store->save( $info_node );
232  
233 0 $UPGRADING = 0;
234 } #upgrade_store
235  
236 75 ▶sub load_root_container {
Subroutine load_root_container: called CC=2 SCAR=6.9
Pod documented
237 75 my $self = shift;
238 75 my $info_node = $self->_fetch_store_info_node;
239 75 my $root = $info_node->get_root;
240 75 ▶ unless( $root ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($root) 15 60 75
241 15 $root = $self->create_container;
242 15 $info_node->set_root( $root );
243 15 $self->save;
244 }
245 75 return $root;
246 } #load_root_container
247  
248  
249 39 ▶sub info {
Subroutine info: called CC=1 SCAR=0.0
Pod documented
250 39 my $node = shift->[STOREINFO];
251 my $info = {
252 39 map { $_ => $node->get($_) }
253 qw( db_version ObjectStore_version created_time last_update_time )
254 };
255 39 $info;
256 } #info
257  
258  
259 2 ▶sub get_db_version {
Subroutine get_db_version: called CC=1 SCAR=0.0
Pod documented
260 2 shift->info->{db_version};
261 }
262  
263  
264 31 ▶sub get_store_version {
Subroutine get_store_version: called CC=1 SCAR=0.0
Pod documented
265 31 shift->info->{ObjectStore_version};
266 }
267  
268 4 ▶sub get_created_time {
Subroutine get_created_time: called CC=1 SCAR=0.0
Pod documented
269 4 shift->info->{created_time};
270 }
271  
272 2 ▶sub get_last_update_time {
Subroutine get_last_update_time: called CC=1 SCAR=0.0
Pod documented
273 2 shift->info->{last_update_time};
274 }
275  
276 36 ▶sub create_container {
Subroutine create_container: called CC=5 SCAR=16.1
Pod documented
277 # works with create_container( { my data } ) or create_container( 'myclass', { my data } )
278 36 my( $self, $class, $data ) = @_;
279 36 ▶ if( ref( $class ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 9 27 36
280 9 $data = $class;
281 9 $class = 'Data::ObjectStore::Container';
282 }
283 36 ▶ $class //= 'Data::ObjectStore::Container';
Condition100%2/2
$class //= "Data::ObjectStore::Container"
l!l
1224
MC/DC100%1/1
$class //= "Data::ObjectStore::Container"
$class
Truth table100%2/2
A
A= $class
Aresult
11
00
284  
285 36 ▶ if( $class !~ /^Data::ObjectStore::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^Data::ObjectStore::/) 3 33 36
286 3 my $clname = $class;
287 3 $clname =~ s/::/\//g;
288 3 require "$clname.pm";
289 }
290  
291 36 my $id = $self->_new_id;
292  
293 36 my $time = time;
294 36 my $obj = bless [ $id,
295 undef,
296 $self,
297 { created => $time,
298 updated => $time },
299 ], $class;
300 36 $self->_store_weak( $id, $obj );
301 36 $self->_dirty( $id );
302  
303 36 for my $fld (keys %$data) {
304 28 $obj->set( $fld, $data->{$fld} );
305 }
306  
307 36 $obj->_init(); #called the first time the object is created.
308 36 $obj->[DIRTY_BIT] = 1;
309 36 $obj;
310 } #create_container
311  
312 70 ▶sub save {
Subroutine save: called CC=6 SCAR=17.9
Pod documented
313 70 my( $self, $ref, $class_override ) = @_;
314 70 ▶ if( ref( $ref ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref) 2 68 70
315 2 return $self->_save( $ref, $class_override );
316 }
317 68 my $node = $self->_fetch_store_info_node;
318 68 my $now = time;
319  
320 68 ▶ unless( $self->[OPTIONS]{NO_TRANSACTIONS} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[4]{"NO_TRANSACTIONS"}) 68 0 68
321 68 $self->[DATA_PROVIDER]->use_transaction;
322 }
323  
324 68 my( @dirty ) = keys %{$self->[DIRTY]};
325
326 68 for my $id ( @dirty ) {
327 6794 my $obj = $self->[DIRTY]{$id};
328 # assings id if none were given
329 6794 $self->_knot( $obj );
330 } #each dirty
331  
332 68 ( @dirty ) = keys %{$self->[DIRTY]};
333 68 for my $id ( @dirty ) {
334 6794 my $obj = delete $self->[DIRTY]{$id};
335 6794 $self->_save( $obj );
336 } #each dirty
337  
338 68 $node->set_last_update_time( $now );
339 68 $self->_save( $node );
340  
341 68 ▶ unless( $self->[OPTIONS]{NO_TRANSACTIONS} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[4]{"NO_TRANSACTIONS"}) 68 0 68
342 68 $self->[DATA_PROVIDER]->commit_transaction;
343 }
344 68 $self->[DIRTY] = {};
345 68 return 1;
346 } #save
347  
348 6864 ▶sub _save {
Subroutine _save: called CC=5 SCAR=16.2
349 6864 my( $self, $obj, $class_override ) = @_;
350 6864 my $thingy = $self->_knot( $obj );
351 6864 ▶ if( ref($thingy) !~ /^(ARRAY|HASH|Data::ObjectStore::Hash|Data::ObjectStore::Array)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($thingy) =~ /^(ARRAY|HASH|Data::ObjectStore::Hash|Data::ObjectStore::Array)$/) 135 6729 6864
352 135 ▶ if( !$thingy->[DIRTY_BIT] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thingy->[5]) 0 135 135
353 0 return;
354 }
355 135 $thingy->[DIRTY_BIT] = 0;
356 }
357 6864 my $id = $thingy->[ID];
358 6864 delete $self->[DIRTY]{$id}; # need the upgrading cas?
359  
360 #
361 # Save to the record store.
362 #
363 6864 my $text_rep = $thingy->_freezedry;
364 6864 ▶ my( @meta ) = $class_override ? $class_override : ref( $thingy );
Branch: 1 branch
BranchTrueFalseTotal
$class_override ? : 0 6864 6864
365 6864 for my $fld (@METAFIELDS) {
366 13728 my $val = $thingy->[METADATA]{$fld};
367 13728 push @meta, $val;
368 }
369 6864 my $meta_string = join('|', @meta );
370 6864 $self->[DATA_PROVIDER]->stow( "$meta_string $text_rep", $id );
371
372 } #_save
373  
374 2 ▶sub existing_id {
Subroutine existing_id: called CC=3 SCAR=11.0
Pod documented
375 2 my( $self, $obj ) = @_;
376 2 ▶ return undef unless ref($obj);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj 1 1 2
377 1 my $tied = $self->_knot( $obj );
378 1 ▶ return $tied ? $tied->[ID] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tied ? : 0 1 1
379 }
380  
381 8 ▶sub _has_dirty {
Subroutine _has_dirty: called CC=1 SCAR=0.0
382 8 my $self = shift;
383 8 scalar( keys %{$self->[DIRTY]});
384 }
385  
386 70538 ▶sub _knot {
Subroutine _knot: called CC=8 SCAR=21.2
387 70538 my( $self, $item ) = @_;
388 70538 my $r = ref( $item );
389 70538 ▶ if( $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 70521 17 70538
390 70521 ▶ if( $r eq 'ARRAY' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($r eq 'ARRAY') { } 68643 1878 70521
elsif ($r eq 'HASH') { } 1398 480 1878
elsif ($r eq 'Data::ObjectStore::Array' or $r eq 'Data::ObjectStore::Hash' or $r->isa('Data::ObjectStore::Container')) { } 478 2 480
391 68643 return tied @$item;
392 }
393 elsif( $r eq 'HASH' ) {
394 1398 return tied %$item;
395 }
396 ▶ elsif( $r eq 'Data::ObjectStore::Array' ||
Condition50%3/6
$r eq "Data::ObjectStore::Array" or $r eq "Data::ObjectStore::Hash" or $r->isa("Data::ObjectStore::Container")
l!l&&r!l&&!r
04782
$r eq "Data::ObjectStore::Array" or $r eq "Data::ObjectStore::Hash"
l!l&&r!l&&!r
00480
MC/DC33%1/3
$r eq "Data::ObjectStore::Array" or $r eq "Data::ObjectStore::Hash" or $r->isa("Data::ObjectStore::Container")
$r eq "Data::ObjectStore::Array" $r eq "Data::ObjectStore::Hash" $r->isa("Data::ObjectStore::Container")
Truth table50%2/4
A or B or C
A= $r eq "Data::ObjectStore::Array"B= $r eq "Data::ObjectStore::Hash"C= $r->isa("Data::ObjectStore::Container")
ABCresult
1XX1
01X1
0011
0000
397 $r eq 'Data::ObjectStore::Hash' ||
398 $r->isa( 'Data::ObjectStore::Container' ) ) {
399 478 return $item;
400 }
401 2 return undef;
402 }
403 17 ▶ if( $item > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item > 0) 17 0 17
404 17 my $xout = $self->_xform_out( $item );
405 17 my $zout = $self->_knot( $xout );
406 17 return $zout;
407 }
408 0 return undef;
409 }
410  
411 #
412 # The store info node records useful information about the store
413 #
414 174 ▶sub _fetch_store_info_node {
Subroutine _fetch_store_info_node: called CC=2 SCAR=6.9
415 174 my( $self ) = @_;
416 174 my $node = $self->fetch( 1 );
417 174 ▶ unless( $node ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 15 159 174
418 15 my $first_id = $self->_new_id;
419 15 my $now = time;
420 15 $node = bless [ 1, {}, $self, { created => $now, updated => $now } ], 'Data::ObjectStore::Container';
421 15 $self->_store_weak( 1, $node );
422 15 $self->_dirty( 1 );
423 15 $node->[DIRTY_BIT] = 1;
424 15 $node->set_db_version( $Data::RecordStore::VERSION );
425 15 $node->set_ObjectStore_version( $Data::ObjectStore::VERSION );
426 15 $node->set_created_time( $now );
427 15 $node->set_last_update_time( $now );
428 }
429 174 $node;
430 } #_fetch_store_info_node
431  
432 146 ▶sub _thaw {
Subroutine _thaw: called CC=6 SCAR=17.9
433 146 my( $dryfroze ) = @_;
434  
435 # so foo` or foo\\` but not foo\\\`
436 # also this will never start with a `
437 146 my $pieces = [ split /\`/, $dryfroze, -1 ];
438  
439  
440 # check to see if any of the parts were split on escapes
441 # like mypart`foo`oo (should be translated to mypart\`foo\`oo
442 146 ▶ if ( 0 < grep { /\\$/ } @$pieces ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < grep({/\\$/;} @$pieces)) 33 113 146
443  
444 33 my $newparts = [];
445  
446 33 my $is_hanging = 0;
447 33 my $working_part = '';
448  
449 33 for my $part (@$pieces) {
450  
451 # if the part ends in a hanging escape
452 398 ▶ if ( $part =~ /(^|[^\\])((\\\\)+)?[\\]$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($part =~ /(^|[^\\])((\\\\)+)?[\\]$/) { } 123 275 398
elsif ($is_hanging) { } 95 180 275
453 123 ▶ if ( $is_hanging ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_hanging) { } 28 95 123
454 28 $working_part .= "`$part";
455 } else {
456 95 $working_part = $part;
457 }
458 123 $is_hanging = 1;
459 } elsif ( $is_hanging ) {
460 95 my $newpart = "$working_part`$part";
461 95 $newpart =~ s/\\`/`/gs;
462 95 $newpart =~ s/\\\\/\\/gs;
463 95 push @$newparts, $newpart;
464 95 $is_hanging = 0;
465 } else {
466 # normal part
467 180 push @$newparts, $part;
468 }
469 }
470 33 $pieces = $newparts;
471  
472 } #if there were escaped ` characters
473  
474 146 $pieces;
475 } #_thaw
476  
477  
478 50280 ▶sub fetch {
Subroutine fetch: called CC=11 SCAR=25.8
Pod documented
479 50280 my( $self, $id, $force ) = @_;
480 50280 ▶ my $ref = $self->[DIRTY]{$id} // $self->[WEAK]{$id};
Condition100%3/3
$self->[1]{$id} // $self->[2]{$id}
l!l&&r!l&&!r
49968141171
MC/DC100%2/2
$self->[1]{$id} // $self->[2]{$id}
$self->[1]{$id} $self->[2]{$id}
Truth table100%3/3
A // B
A= $self->[1]{$id}B= $self->[2]{$id}
ABresult
1X1
011
000
481
482 50280 ▶ return $ref if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 50109 171 50280
483  
484 171 my $stowed = $self->[DATA_PROVIDER]->fetch( $id );
485 171 ▶ return undef unless $stowed;
Branch: 1 branch
BranchTrueFalseTotal
unless $stowed 23 148 171
486  
487 148 my $pos = index( $stowed, ' ' );
488 148 ▶ die "Data::ObjectStore::_fetch : Malformed record '$stowed'" if $pos == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == -1 2 146 148
489  
490 146 my $metastr = substr $stowed, 0, $pos;
491 146 my( $class, @meta ) = split /\|/, $metastr;
492  
493 146 my $meta = {};
494 146 for my $fldi (0..$#METAFIELDS) {
495 292 my $fld = $METAFIELDS[$fldi];
496 292 my $val = $meta[$fldi];
497 292 $meta->{$fld} = $val;
498 }
499  
500 146 my $dryfroze = substr $stowed, $pos + 1;
501  
502 146 ▶ if( $class !~ /^Data::ObjectStore::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^Data::ObjectStore::/) 2 144 146
503 2 my $clname = $class;
504 2 $clname =~ s/::/\//g;
505  
506 2 eval {
507 2 require "$clname.pm";
508 2 ▶ unless( $class->can( '_reconstitute' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("_reconstitute")) 0 2 2
509 0 ▶ if( $force ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force) { } 0 0 0
510 0 warn "Forcing '$class' to be 'Data::ObjectStore::Container'";
511 0 $class = 'Data::ObjectStore::Container';
512 } else {
513 0 die "Object in the store was marked as '$class' but that is not a 'Data::ObjectStore::Container'";
514 }
515 }
516 };
517 2 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
518 0 ▶ if( $force ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force) { } 0 0 0
519 0 warn "Forcing '$class' to be 'Data::ObjectStore::Container'";
520 0 $class = 'Data::ObjectStore::Container';
521 } else {
522 0 die $@;
523 }
524 }
525 }
526  
527 146 my $pieces = _thaw( $dryfroze );
528  
529 146 my $ret = $class->_reconstitute( $self, $id, $pieces, $meta );
530 146 $self->_store_weak( $id, $ret );
531 146 return $ret;
532 } #_fetch
533  
534 #
535 # Convert from reference, scalar or undef to value marker
536 #
537 21810 ▶sub _xform_in {
Subroutine _xform_in: called CC=3 SCAR=11.0
538 21810 my( $self, $val ) = @_;
539 21810 ▶ if( ref( $val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) 81 21729 21810
540 81 my $id = $self->_get_id( $val );
541 81 return $id, "r$id";
542 }
543 21729 ▶ return 0, (defined $val ? "v$val" : 'u');
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 21720 9 21729
544 }
545  
546 #
547 # Convert from value marker to reference, scalar or undef
548 #
549 3593 ▶sub _xform_out {
Subroutine _xform_out: called CC=5 SCAR=16.1
550 3593 my( $self, $val ) = @_;
551  
552 3593 ▶ return undef unless defined( $val ) && $val ne 'u';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and $val ne "u" 891 2702 3593
Condition100%3/3
defined $val and $val ne "u"
!ll&&!rl&&r
863282702
MC/DC100%2/2
defined $val and $val ne "u"
defined $val $val ne "u"
Truth table100%3/3
A and B
A= defined $valB= $val ne "u"
ABresult
0X0
100
111
553  
554 2702 ▶ if( index($val,'v') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($val, "v") == 0) 2479 223 2702
555 2479 return substr( $val, 1 );
556 }
557 223 ▶ if( $val =~ /^r(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^r(\d+)/) 206 17 223
558 206 return $self->fetch( $1 );
559 }
560 17 return $self->fetch( $val );
561 }
562  
563 6927 ▶sub _store_weak {
Subroutine _store_weak: called CC=2 SCAR=6.9
564 6927 my( $self, $id, $ref ) = @_;
565  
566 6927 ▶ if( $self->[CACHE] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[5]) 3 6924 6927
567 3 $self->[CACHE]->stow( $id, $ref );
568 }
569
570 6927 $self->[WEAK]{$id} = $ref;
571  
572 6927 weaken( $self->[WEAK]{$id} );
573  
574 } #_store_weak
575  
576 56841 ▶sub _dirty {
Subroutine _dirty: called CC=2 SCAR=6.9
577 56841 my( $self, $id ) = @_;
578 56841 my $item = $self->[WEAK]{$id};
579 56841 $self->[DIRTY]{$id} = $item;
580 56841 $item = $self->_knot( $item );
581 56841 ▶ if( $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item) 56839 2 56841
582 56839 $item->[METADATA]{updated} = time();
583 }
584 } #_dirty
585  
586  
587 6781 ▶sub _new_id {
Subroutine _new_id: called CC=1 SCAR=0.0
588 6781 my( $self ) = @_;
589 6781 my $newid = $self->[DATA_PROVIDER]->next_id;
590 6781 $newid;
591 } #_new_id
592  
593 0 ▶sub _meta {
Subroutine _meta: not called CC=1 SCAR=6.9
594 0 my( $self, $thingy ) = @_;
595 return {
596 created => $thingy->[METADATA]{created},
597 updated => $thingy->[METADATA]{updated},
598 0 };
599 } #_meta
600  
601 0 ▶sub last_updated {
Subroutine last_updated: not called CC=2 SCAR=17.9
Pod documented
602 0 my( $self, $obj ) = @_;
603 0 $obj = $self->_knot( $obj );
604 0 ▶ return undef unless $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
605 0 $self->_meta( $obj )->{updated};
606 }
607  
608 0 ▶sub created {
Subroutine created: not called CC=2 SCAR=17.9
Pod documented
609 0 my( $self, $obj ) = @_;
610 0 $obj = $self->_knot( $obj );
611 0 ▶ return undef unless $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
612 0 $self->_meta( $obj )->{created};
613 }
614  
615 # returns the id of the refernce, injesting it if
616 # necessary.
617 # used by tests
618 89 ▶sub _get_id {
Subroutine _get_id: called CC=9 SCAR=22.0
619 89 my( $self, $ref ) = @_;
620  
621 89 my $class = ref( $ref );
622 89 my $thingy;
623 89 ▶ if ( $class eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'ARRAY') { } 23 66 89
elsif ($class eq 'HASH') { } 9 57 66
624 23 $thingy = tied @$ref;
625 23 ▶ if ( ! $thingy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thingy) 11 12 23
626 11 my $id = $self->_new_id;
627 11 my( @items ) = @$ref;
628 11 tie @$ref, 'Data::ObjectStore::Array', $self, $id, { created => time, updated => time}, 0, $Data::ObjectStore::Array::MAX_BLOCKS;
629 11 my $tied = tied @$ref;
630  
631 11 $self->_store_weak( $id, $ref );
632 11 $self->_dirty( $id );
633 11 push @$ref, @items;
634 11 return $id;
635 }
636 12 $ref = $thingy;
637 12 $class = ref( $ref );
638 }
639 elsif ( $class eq 'HASH' ) {
640 9 $thingy = tied %$ref;
641 9 ▶ if ( ! $thingy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thingy) 7 2 9
642 7 my $id = $self->_new_id;
643 7 my( %items ) = %$ref;
644 7 tie %$ref, 'Data::ObjectStore::Hash', $self, $id, { created => time, updated => time};
645 7 my $tied = tied %$ref;
646  
647 7 $self->_store_weak( $id, $ref );
648 7 $self->_dirty( $id );
649 7 for my $key (keys( %items) ) {
650 6 $ref->{$key} = $items{$key};
651 }
652 7 return $id;
653 }
654 2 $ref = $thingy;
655 2 $class = ref( $ref );
656 }
657 else {
658 57 $thingy = $ref;
659 }
660  
661 71 ▶ die "Data::ObjectStore::_get_id : Cannot ingest object that is not a hash, array or objectstore obj" unless ( $class eq 'Data::ObjectStore::Hash' || $class eq 'Data::ObjectStore::Array' || $ref->isa( 'Data::ObjectStore::Container' ) ); # new id is created upon create container for all Data::ObjectStore::Container instances.
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "Data::ObjectStore::Hash" or $class eq "Data::ObjectStore::Array" or $ref->isa("Data::ObjectStore::Container") 0 71 71
Condition83%5/6
$class eq "Data::ObjectStore::Hash" or $class eq "Data::ObjectStore::Array" or $ref->isa("Data::ObjectStore::Container")
l!l&&r!l&&!r
14570
$class eq "Data::ObjectStore::Hash" or $class eq "Data::ObjectStore::Array"
l!l&&r!l&&!r
21257
MC/DC0%0/3
$class eq "Data::ObjectStore::Hash" or $class eq "Data::ObjectStore::Array" or $ref->isa("Data::ObjectStore::Container")
$class eq "Data::ObjectStore::Hash" $class eq "Data::ObjectStore::Array" $ref->isa("Data::ObjectStore::Container")
Truth table75%3/4
A or B or C
A= $class eq "Data::ObjectStore::Hash"B= $class eq "Data::ObjectStore::Array"C= $ref->isa("Data::ObjectStore::Container")
ABCresult
1XX1
01X1
0011
0000
662  
663 71 return $ref->[ID];
664  
665 } #_get_id
666  
667 # END PACKAGE Data::ObjectStore
668  
669 # --------------------------------------------------------------------------------
670  
671 package Data::ObjectStore::Array;
672  
673  
674 ##################################################################################
675 # This module is used transparently by ObjectStore to link arrays into its graph #
676 # structure. This is not meant to be called explicitly or modified. #
677 ##################################################################################
678  
679 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
680 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
681 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
682 2 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
683 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
684  
685 2 ▶use Tie::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
686  
687 2 $Data::ObjectStore::Array::MAX_BLOCKS = 1_000_000;
688  
689  
690 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
691 2 ID => 0,
692 DATA => 1,
693 DSTORE => 2,
694 METADATA => 3,
695 LEVEL => 4,
696 BLOCK_COUNT => 5,
697 BLOCK_SIZE => 6,
698 ITEM_COUNT => 7,
699 UNDERNEATH => 8,
700  
701 WEAK => 2,
702 2 };
703  
704 0 ▶sub store {
Subroutine store: not called CC=1 SCAR=6.9
705 0 shift->[DSTORE];
706 }
707  
708 6724 ▶sub _freezedry {
Subroutine _freezedry: called CC=9 SCAR=22.0
709 6724 my $self = shift;
710 6724 my @items;
711 6724 ▶ my $stuff_count = $self->[BLOCK_COUNT] > $self->[ITEM_COUNT] ? $self->[ITEM_COUNT] : $self->[BLOCK_COUNT];
Branch: 1 branch
BranchTrueFalseTotal
$self->[5] > $self->[7] ? : 32 6692 6724
712 6724 ▶ if( $stuff_count > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stuff_count > 0) 6705 19 6724
713 6705 ▶ @items = map { if( defined($_) && $_=~ /[\\\`]/ ) { $_ =~ s/[\\]/\\\\/gs; s/`/\\`/gs; } defined($_) ? $_ : 'u' } map { $self->[DATA][$_] } (0..($stuff_count-1));
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_ and $_ =~ /[\\\`]/) 6 26813 26819
defined $_ ? : 26783 36 26819
Condition100%3/3
defined $_ and $_ =~ /[\\\`]/
!ll&&!rl&&r
36267776
MC/DC100%2/2
defined $_ and $_ =~ /[\\\`]/
defined $_ $_ =~ /[\\\`]/
Truth table100%3/3
A and B
A= defined $_B= $_ =~ /[\\\`]/
ABresult
0X0
100
111
714 }
715  
716 6724 ▶ join( "`",
Condition100%6/6
$self->[4] || 0
l!l
16925032
$self->[7] || 0
l!l
670519
$self->[8] || 0
l!l
671212
MC/DC100%1/1
$self->[4] || 0
$self->[4]
MC/DC100%1/1
$self->[7] || 0
$self->[7]
MC/DC100%1/1
$self->[8] || 0
$self->[8]
Truth table100%2/2
A
A= $self->[4]
Aresult
11
00
Truth table100%2/2
A
A= $self->[7]
Aresult
11
00
Truth table100%2/2
A
A= $self->[8]
Aresult
11
00
717 $self->[LEVEL] || 0,
718 $self->[BLOCK_COUNT],
719 $self->[ITEM_COUNT] || 0,
720 $self->[UNDERNEATH] || 0,
721 @items,
722 );
723 }
724  
725 45 ▶sub _reconstitute {
Subroutine _reconstitute: called CC=1 SCAR=0.0
726 45 my( $cls, $store, $id, $data, $meta ) = @_;
727 45 my $arry = [];
728 45 tie @$arry, $cls, $store, $id, $meta, @$data;
729 45 return $arry;
730 }
731  
732 6768 ▶sub TIEARRAY {
Subroutine TIEARRAY: called CC=2 SCAR=6.9
733 6768 my( $class, $obj_store, $id, $meta, $level, $block_count, $item_count, $underneath, @list ) = @_;
734 6768 ▶ $item_count //= 0;
Condition100%2/2
$item_count //= 0
l!l
576711
MC/DC100%1/1
$item_count //= 0
$item_count
Truth table100%2/2
A
A= $item_count
Aresult
11
00
735 6768 my $block_size = $block_count ** $level;
736  
737 6768 my $blocks = [@list];
738 # $#$blocks = $block_count - 1;
739  
740 # once the array is tied, an additional data field will be added
741 # so obj will be [ $id, $storage, $obj_store ]
742 # die if $id == 1;
743 6768 my $obj = bless [
744 $id,
745 $blocks,
746 $obj_store,
747 $meta,
748 $level,
749 $block_count,
750 $block_size,
751 $item_count,
752 $underneath,
753 ], $class;
754  
755 6768 return $obj;
756 } #TIEARRAY
757  
758 32373 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.0
759 32373 my( $self, $idx ) = @_;
760  
761 32373 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[7]) 12727 19646 32373
762 12727 return undef;
763 }
764  
765 19646 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) 1586 18060 19646
766 1586 return $self->[DSTORE]->_xform_out( $self->[DATA][$idx] );
767 }
768  
769 18060 my $block = $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) );
770 18060 return $block->FETCH( $idx % $self->[BLOCK_SIZE] );
771  
772 } #FETCH
773  
774 608 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
775 608 shift->[ITEM_COUNT];
776 }
777  
778 6 ▶sub _embiggen {
Subroutine _embiggen: called CC=2 SCAR=6.9
779 6 my( $self, $size ) = @_;
780 6 my $store = $self->[DSTORE];
781  
782 6 ▶ while( $size > $self->[BLOCK_SIZE] * $self->[BLOCK_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $self->[6] * $self->[5]) 12 6 18
783  
784 #
785 # before embiggen ...
786 # DATA = [ 1,2,3,4,5,6 ]
787 # after embiggen
788 # newblock = []
789 # newblockid = 7
790 # DATA = [ 7 ]
791 #
792  
793 #
794 # need to tie a new block, not use _getblock
795 # becaues we do squirrely things with its tied guts
796 #
797 12 my $newblock = [];
798 12 my $newid = $store->_new_id;
799 12 my $meta = { %{$self->[METADATA]} };
800 12 $meta->{updated} = time;
801 12 tie @$newblock, 'Data::ObjectStore::Array', $store, $newid, $meta, $self->[LEVEL], $self->[BLOCK_COUNT], $self->[ITEM_COUNT], 1;
802 12 $store->_store_weak( $newid, $newblock );
803 12 $store->_dirty( $newid );
804  
805 12 my $tied = tied @$newblock;
806  
807 12 $tied->[DATA] = [@{$self->[DATA]}];
808  
809 12 $self->[DATA] = [ "r$newid" ];
810  
811 12 $self->[BLOCK_SIZE] *= $self->[BLOCK_COUNT];
812 12 $self->[LEVEL]++;
813 12 $store->_dirty( $self->[ID] );
814 }
815  
816 } #_embiggen
817  
818 #
819 # get a block at the given block index. Returns undef
820 # if there isn't one ther, or creates and returns
821 # one if passed do create
822 #
823 56574 ▶sub _getblock {
Subroutine _getblock: called CC=4 SCAR=13.9
824 56574 my( $self, $block_idx ) = @_;
825  
826 56574 ▶ my $block_id = $self->[DATA][$block_idx] // 'r0';
Condition100%2/2
$self->[1][$block_idx] // "r0"
l!l
498746700
MC/DC100%1/1
$self->[1][$block_idx] // "r0"
$self->[1][$block_idx]
Truth table100%2/2
A
A= $self->[1][$block_idx]
Aresult
11
00
827 56574 $block_id = substr( $block_id, 1 );
828 56574 my $store = $self->[DSTORE];
829  
830 56574 ▶ if( $block_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_id > 0) 49874 6700 56574
831 49874 my $block = $store->fetch( $block_id );
832 49874 return tied(@$block);
833 }
834  
835 6700 $block_id = $store->_new_id;
836 6700 my $block = [];
837 6700 my $level = $self->[LEVEL] - 1;
838 6700 my $meta = { %{$self->[METADATA]} };
839 6700 tie @$block, 'Data::ObjectStore::Array', $store, $block_id, $meta, $level, $self->[BLOCK_COUNT];
840  
841 6700 my $tied = tied( @$block );
842  
843 6700 $tied->[UNDERNEATH] = 1;
844 6700 ▶ if( $block_idx >= ($self->[BLOCK_COUNT] - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_idx >= $self->[5] - 1) 1672 5028 6700
845 1672 $tied->[ITEM_COUNT] = $self->[BLOCK_SIZE];
846 }
847  
848 6700 $store->_store_weak( $block_id, $block );
849 6700 $store->_dirty( $block_id );
850 6700 $store->_dirty( $self->[ID] );
851 6700 $self->[DATA][$block_idx] = "r$block_id";
852 6700 return $tied;
853  
854 } #_getblock
855  
856 49040 ▶sub STORE {
Subroutine STORE: called CC=8 SCAR=21.0
857 49040 my( $self, $idx, $val ) = @_;
858  
859 49040 ▶ if( $idx >= $self->[BLOCK_COUNT]*$self->[BLOCK_SIZE] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[5] * $self->[6]) 0 49040 49040
860 0 $self->_embiggen( $idx + 1 );
861 0 $self->STORE( $idx, $val );
862 0 return;
863 }
864  
865 49040 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[7]) 26786 22254 49040
866 26786 $self->_storesize( $idx + 1 );
867 26786 my $store = $self->[DSTORE];
868 26786 $store->_dirty( $self->[ID] );
869 }
870  
871 49040 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) 13180 35860 49040
872 13180 my( $xid, $xin ) = $self->[DSTORE]->_xform_in( $val );
873 13180 ▶ if( $xid > 0 && $xid < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xid > 0 and $xid < 3) 2 13178 13180
Condition100%3/3
$xid > 0 and $xid < 3
!ll&&!rl&&r
1317622
MC/DC100%2/2
$xid > 0 and $xid < 3
$xid > 0 $xid < 3
Truth table100%3/3
A and B
A= $xid > 0B= $xid < 3
ABresult
0X0
100
111
874 2 die "cannot store a root node in a list";
875 }
876 13178 my $store = $self->[DSTORE];
877 13178 ▶ my $xold = $self->[DATA][$idx] // 0;
Condition100%2/2
$self->[1][$idx] // 0
l!l
8413094
MC/DC100%1/1
$self->[1][$idx] // 0
$self->[1][$idx]
Truth table100%2/2
A
A= $self->[1][$idx]
Aresult
11
00
878 13178 ▶ if( $xold ne $xin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xold ne $xin) 13178 0 13178
879 13178 $self->[DATA][$idx] = $xin;
880 13178 $store->_dirty( $self->[ID] );
881 }
882  
883 13178 return;
884 }
885  
886 35860 my $block = $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) );
887 35860 $block->STORE( $idx % $self->[BLOCK_SIZE], $val );
888  
889 } #STORE
890  
891 29469 ▶sub _storesize {
Subroutine _storesize: called CC=1 SCAR=0.0
892 29469 my( $self, $size ) = @_;
893 29469 $self->[ITEM_COUNT] = $size;
894 }
895  
896 0 ▶sub STORESIZE {
Subroutine STORESIZE: not called CC=2 SCAR=17.9
897 0 my( $self, $size ) = @_;
898  
899 # fixes the size of the array if the array were to shrink
900 0 my $current_oversize = $self->[ITEM_COUNT] - $size;
901 0 ▶ if( $current_oversize > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_oversize > 0) 0 0 0
902 0 $self->SPLICE( $size, $current_oversize );
903 } #if the array shrinks
904  
905 0 $self->_storesize( $size );
906  
907 } #STORESIZE
908  
909 20 ▶sub EXISTS {
Subroutine EXISTS: called CC=3 SCAR=11.0
910 20 my( $self, $idx ) = @_;
911 20 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[7]) 2 18 20
912 2 return 0;
913 }
914 18 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) 6 12 18
915 6 return defined($self->[DATA][$idx]);
916 }
917 12 return $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) )->EXISTS( $idx % $self->[BLOCK_SIZE] );
918  
919 } #EXISTS
920  
921 2 ▶sub DELETE {
Subroutine DELETE: called CC=4 SCAR=18.5
922 2 my( $self, $idx ) = @_;
923  
924 2 my $store = $self->[DSTORE];
925 2 my $del = $self->FETCH( $idx );
926 2 $self->STORE( $idx, undef );
927 2 ▶ if( $idx == $self->[ITEM_COUNT] - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == $self->[7] - 1) 0 2 2
928 0 $self->[ITEM_COUNT]--;
929 0 ▶ while( $self->[ITEM_COUNT] > 0 && ! defined( $self->FETCH( $self->[ITEM_COUNT] - 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7] > 0 and not defined $self->FETCH($self->[7] - 1)) 0 0 0
Condition0%0/3
$self->[7] > 0 and not defined $self->FETCH($self->[7] - 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[7] > 0 and not defined $self->FETCH($self->[7] - 1)
$self->[7] > 0 not defined $self->FETCH($self->[7] - 1)
Truth table0%0/3
A and not(B)
A= $self->[7] > 0B= not defined $self->FETCH($self->[7] - 1)
ABresult
0X0
100
111
930 0 $self->[ITEM_COUNT]--;
931 }
932  
933 }
934 2 $store->_dirty( $self->[ID] );
935  
936 2 return $del;
937  
938 } #DELETE
939  
940 2 ▶sub CLEAR {
Subroutine CLEAR: called CC=3 SCAR=11.0
941 2 my $self = shift;
942 2 ▶ if( $self->[ITEM_COUNT] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7] > 0) 2 0 2
943 2 my $store = $self->[DSTORE];
944 2 for( 0..$self->[ITEM_COUNT] ) {
945 38 my $del = $self->FETCH( $_ );
946 }
947 2 $self->[ITEM_COUNT] = 0;
948 2 $self->[DATA] = [];
949 2 $self->[DSTORE]->_dirty( $self->[ID] );
950 }
951 }
952 46 ▶sub PUSH {
Subroutine PUSH: called CC=2 SCAR=6.9
953 46 my( $self, @vals ) = @_;
954 46 ▶ return unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 11 35 46
955 35 $self->SPLICE( $self->[ITEM_COUNT], 0, @vals );
956 }
957 4 ▶sub POP {
Subroutine POP: called CC=2 SCAR=7.1
958 4 my $self = shift;
959 4 my $idx = $self->[ITEM_COUNT] - 1;
960 4 ▶ if( $idx < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < 0) 0 4 4
961 0 return undef;
962 }
963 4 my $pop = $self->FETCH( $idx );
964 4 $self->STORE( $idx, undef );
965 4 $self->[ITEM_COUNT]--;
966 4 return $pop;
967 }
968 2 ▶sub SHIFT {
Subroutine SHIFT: called CC=2 SCAR=7.0
969 2 my( $self ) = @_;
970 2 ▶ return undef unless $self->[ITEM_COUNT];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[7] 0 2 2
971 2 my( $ret ) = $self->SPLICE( 0, 1 );
972 2 $ret;
973 }
974  
975 2 ▶sub UNSHIFT {
Subroutine UNSHIFT: called CC=2 SCAR=7.1
976 2 my( $self, @vals ) = @_;
977 2 ▶ return unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 0 2 2
978 2 return $self->SPLICE( 0, 0, @vals );
979 }
980  
981 2697 ▶sub SPLICE {
Subroutine SPLICE: called CC=26 SCAR=32.7
982 2697 my( $self, $offset, $remove_length, @vals ) = @_;
983  
984 # if no arguments given, clear the array
985 2697 ▶ if( ! defined( $offset ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $offset) 0 2697 2697
986 0 $offset = 0;
987 0 $remove_length = $self->[ITEM_COUNT];
988 }
989
990 # if negative, the offset is from the end
991 2697 ▶ if( $offset < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < 0) 0 2697 2697
992 0 $offset = $self->[ITEM_COUNT] + $offset;
993 }
994  
995 # if negative, remove everything except the abs($remove_length) at
996 # the end of the list
997 2697 ▶ if( $remove_length < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length < 0) 0 2697 2697
998 0 $remove_length = ($self->[ITEM_COUNT] - $offset) + $remove_length;
999 }
1000  
1001 2697 ▶ return () unless $remove_length || @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless $remove_length or @vals 0 2697 2697
Condition66%2/3
$remove_length or @vals
l!l&&r!l&&!r
70419930
MC/DC0%0/2
$remove_length or @vals
$remove_length @vals
Truth table66%2/3
A or B
A= $remove_lengthB= @vals
ABresult
1X1
011
000
1002  
1003 # check for removal past end
1004 2697 ▶ if( $offset > ($self->[ITEM_COUNT] - 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > $self->[7] - 1) 2017 680 2697
1005 2017 $remove_length = 0;
1006 2017 $offset = $self->[ITEM_COUNT];
1007 }
1008 2697 ▶ if( $remove_length > ($self->[ITEM_COUNT] - $offset) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length > $self->[7] - $offset) 2 2695 2697
1009 2 $remove_length = $self->[ITEM_COUNT] - $offset;
1010 }
1011  
1012 #
1013 # embiggen to delta size if this would grow. Also use the
1014 # calculated size as a check for correctness.
1015 #
1016 2697 my $new_size = $self->[ITEM_COUNT];
1017 2697 $new_size -= $remove_length;
1018 2697 $new_size += @vals;
1019  
1020 2697 ▶ if( $new_size > $self->[BLOCK_SIZE] * $self->[BLOCK_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_size > $self->[6] * $self->[5]) 6 2691 2697
1021 6 $self->_embiggen( $new_size );
1022 }
1023  
1024 2697 my $store = $self->[DSTORE];
1025 2697 my $BLOCK_COUNT = $self->[BLOCK_COUNT];
1026 2697 my $BLOCK_SIZE = $self->[BLOCK_SIZE]; # embiggen may have changed this, so dont set this before the embiggen call
1027  
1028 2697 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) 1789 908 2697
1029 # lowest level, must fit in the size. The end recursion and easy case.
1030 1789 my $blocks = $self->[DATA];
1031 1789 my( @invals ) = ( map { ($store->_xform_in($_))[1] } @vals );
1032 1789 for my $inval (@invals) {
1033 7031 my( $inid ) = ( $inval =~ /^r(\d+)/ );
1034  
1035 7031 ▶ if( $inid && $inid < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inid and $inid < 3) 2 7029 7031
Condition100%3/3
$inid and $inid < 3
!ll&&!rl&&r
7017122
MC/DC100%2/2
$inid and $inid < 3
$inid $inid < 3
Truth table100%3/3
A and B
A= $inidB= $inid < 3
ABresult
0X0
100
111
1036 2 die "cannot store a root node in a list";
1037 }
1038 }
1039 1787 my @raw_return = splice @$blocks, $offset, $remove_length, @invals;
1040 1787 my @ret;
1041 1787 for my $rr (@raw_return) {
1042 52 push @ret, $store->_xform_out($rr);
1043 }
1044 1787 $self->_storesize( $new_size );
1045 1787 $store->_dirty( $self->[ID] );
1046 1787 return @ret;
1047 } # LEVEL == 0 case
1048  
1049 908 my( @removed );
1050 908 ▶ while( @vals && $remove_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals and $remove_length) 13098 908 14006
Condition100%3/3
@vals and $remove_length
!ll&&!rl&&r
22268613098
MC/DC100%2/2
@vals and $remove_length
@vals $remove_length
Truth table100%3/3
A and B
A= @valsB= $remove_length
ABresult
0X0
100
111
1051 #
1052 # harmony case. doesn't change the size. eats up vals and remove length
1053 # until one is zero
1054 #
1055 13098 push @removed, $self->FETCH( $offset );
1056 13098 $self->STORE( $offset++, shift @vals );
1057 13098 $remove_length--;
1058 }
1059  
1060 908 ▶ if( $remove_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length) 10 898 908
1061  
1062 10 ▶ for( my $idx=$offset; $idx<($offset+$remove_length); $idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < $offset + $remove_length) 526 10 536
1063 526 push @removed, $self->FETCH( $idx );
1064 }
1065  
1066 10 my $things_to_move = $self->[ITEM_COUNT] - ($offset+$remove_length);
1067 10 my $to_idx = $offset;
1068 10 my $from_idx = $to_idx + $remove_length;
1069 10 for( 1..$things_to_move ) {
1070 66 $self->STORE( $to_idx, $self->FETCH( $from_idx ) );
1071 66 $to_idx++;
1072 66 $from_idx++;
1073 }
1074 } # has things to remove
1075  
1076 908 ▶ if( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 686 222 908
1077 #
1078 # while there are any in the insert list, grab all the items in the next block if any
1079 # and append to the insert list, then splice in the insert list to the beginning of
1080 # the block. There still may be items in the insert list, so repeat until it is done
1081 #
1082  
1083 686 my $block_idx = int( $offset / $BLOCK_SIZE );
1084 686 my $block_off = $offset % $BLOCK_SIZE;
1085  
1086 686 ▶ while( @vals && ($self->[ITEM_COUNT] > $block_idx*$BLOCK_SIZE+$block_off) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals and $self->[7] > $block_idx * $BLOCK_SIZE + $block_off) 4 686 690
Condition100%3/3
@vals and $self->[7] > $block_idx * $BLOCK_SIZE + $block_off
!ll&&!rl&&r
26844
MC/DC100%2/2
@vals and $self->[7] > $block_idx * $BLOCK_SIZE + $block_off
@vals $self->[7] > $block_idx * $BLOCK_SIZE + $block_off
Truth table100%3/3
A and B
A= @valsB= $self->[7] > $block_idx * $BLOCK_SIZE + $block_off
ABresult
0X0
100
111
1087 4 my $block = $self->_getblock( $block_idx );
1088 4 my $bubble_size = $block->FETCHSIZE - $block_off;
1089 4 ▶ if( $bubble_size > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bubble_size > 0) 4 0 4
1090 4 my @bubble = $block->SPLICE( $block_off, $bubble_size );
1091 4 push @vals, @bubble;
1092 }
1093 4 ▶ my $can_insert = @vals > ($BLOCK_SIZE-$block_off) ? ($BLOCK_SIZE-$block_off) : @vals;
Branch: 1 branch
BranchTrueFalseTotal
@vals > $BLOCK_SIZE - $block_off ? : 2 2 4
1094 4 $block->SPLICE( $block_off, 0, splice( @vals, 0, $can_insert ) );
1095 4 $block_idx++;
1096 4 $block_off = 0;
1097 }
1098 686 ▶ while( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 2638 674 3312
1099 2638 my $block = $self->_getblock( $block_idx );
1100 2638 my $remmy = $BLOCK_SIZE - $block_off;
1101 2638 ▶ if( $remmy > @vals ) { $remmy = @vals; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remmy > @vals) 38 2600 2638
1102  
1103 2638 $block->SPLICE( $block_off, $block->[ITEM_COUNT], splice( @vals, 0, $remmy) );
1104 2626 $block_idx++;
1105 2626 $block_off = 0;
1106 }
1107  
1108 } # has vals
1109  
1110 896 $self->_storesize( $new_size );
1111  
1112 896 return @removed;
1113  
1114 } #SPLICE
1115  
1116 0 ▶sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=0.0
1117 }
1118  
1119 6765 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1120 6765 my $self = shift;
1121 6765 delete $self->[DSTORE]->[WEAK]{$self->[ID]};
1122 }
1123  
1124 # END PACKAGE Data::ObjectStore::Array
1125  
1126 # --------------------------------------------------------------------------------
1127  
1128 package Data::ObjectStore::Hash;
1129  
1130 ##################################################################################
1131 # This module is used transparently by ObjectStore to link hashes into its #
1132 # graph structure. This is not meant to be called explicitly or modified. #
1133 ##################################################################################
1134  
1135 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1136 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1137  
1138 2 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1139 2 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1140 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
1141  
1142 2 ▶use Tie::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
1143  
1144 2 $Data::ObjectStore::Hash::BUCKET_SIZE = 29;
1145 2 $Data::ObjectStore::Hash::MAX_SIZE = 1_062_599;
1146  
1147 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
1148 2 ID => 0,
1149 DATA => 1,
1150 DSTORE => 2,
1151 METADATA => 3,
1152 LEVEL => 4,
1153 BUCKETS => 5,
1154 SIZE => 6,
1155 NEXT => 7,
1156 2 };
1157  
1158 0 ▶sub store {
Subroutine store: not called CC=1 SCAR=6.9
1159 0 shift->[DSTORE];
1160 }
1161  
1162 5 ▶sub _freezedry {
Subroutine _freezedry: called CC=3 SCAR=11.0
1163 5 my $self = shift;
1164 5 my $r = $self->[DATA];
1165 join( "`",
1166 $self->[LEVEL],
1167 $self->[BUCKETS],
1168 $self->[SIZE],
1169 5 ▶ map { if( $_=~ /[\\\`]/ ) { s/[\\]/\\\\/gs; s/`/\\`/gs; } $_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ =~ /[\\\`]/) 6 2734 2740
$self->[4] ? : 0 5 5
1170 $self->[LEVEL] ? @$r : %$r
1171 );
1172 }
1173  
1174 8 ▶sub _reconstitute {
Subroutine _reconstitute: called CC=1 SCAR=0.0
1175 8 my( $cls, $store, $id, $data, $meta ) = @_;
1176 8 my $hash = {};
1177 8 tie %$hash, $cls, $store, $id, $meta, @$data;
1178  
1179 8 return $hash;
1180 }
1181  
1182 15 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=5 SCAR=16.1
1183 15 my( $class, $obj_store, $id, $meta, $level, $buckets, $size, @fetch_buckets ) = @_;
1184 15 ▶ $level //= 0;
Condition100%2/2
$level //= 0
l!l
87
MC/DC100%1/1
$level //= 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
1185 15 ▶ $size ||= 0;
Condition100%2/2
$size ||= 0
l!l
87
MC/DC100%1/1
$size ||= 0
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
1186 15 ▶ unless( $buckets ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($buckets) 7 8 15
1187 7 $buckets = $Data::ObjectStore::Hash::BUCKET_SIZE;
1188 }
1189 15 ▶ bless [ $id,
Branch: 1 branch
BranchTrueFalseTotal
$level ? : 0 15 15
1190 $level ? [@fetch_buckets] : {@fetch_buckets},
1191 $obj_store,
1192 $meta,
1193 $level,
1194 $buckets,
1195 $size,
1196 [undef,undef],
1197 ], $class;
1198 } #TIEHASH
1199  
1200 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=3 SCAR=24.8
1201 0 my $self = shift;
1202 0 ▶ if( $self->[SIZE] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6] > 0) 0 0 0
1203 0 $self->[SIZE] = 0;
1204 0 my $store = $self->[DSTORE];
1205 0 $store->_dirty( $self->[ID] );
1206 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) { } 0 0 0
1207 0 %{$self->[DATA]} = ();
1208 } else {
1209 0 @{$self->[DATA]} = ();
1210 }
1211 }
1212 } #CLEAR
1213  
1214 2 ▶sub DELETE {
Subroutine DELETE: called CC=4 SCAR=16.5
1215 2 my( $self, $key ) = @_;
1216  
1217 2 ▶ return undef unless $self->EXISTS( $key );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->EXISTS($key) 0 2 2
1218  
1219 2 $self->[SIZE]--;
1220  
1221 2 my $data = $self->[DATA];
1222 2 my $store = $self->[DSTORE];
1223  
1224 2 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) { } 2 0 2
1225 2 $store->_dirty( $self->[ID] );
1226 2 my $delin = delete $data->{$key};
1227 2 return $store->_xform_out( $delin );
1228 } else {
1229 0 my $hval = 0;
1230 0 foreach (split //,$key) {
1231 0 $hval = $hval*33 - ord($_);
1232 }
1233 0 $hval = $hval % $self->[BUCKETS];
1234 0 my $store = $self->[DSTORE];
1235 0 return $store->_knot( $store->fetch( substr($data->[$hval], 1 ) ))->DELETE( $key );
1236 }
1237 } #DELETE
1238  
1239  
1240 2748 ▶sub EXISTS {
Subroutine EXISTS: called CC=4 SCAR=24.4
1241 2748 my( $self, $key ) = @_;
1242  
1243 2748 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) { } 2748 0 2748
1244 2748 return exists $self->[DATA]{$key};
1245 } else {
1246 0 my $data = $self->[DATA];
1247 0 my $hval = 0;
1248 0 foreach (split //,$key) {
1249 0 $hval = $hval*33 - ord($_);
1250 }
1251 0 $hval = $hval % $self->[BUCKETS];
1252 0 my $hash_id = substr($data->[$hval],1);
1253 0 ▶ if( $hash_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_id > 0) 0 0 0
1254 0 my $hash = $self->[DSTORE]->fetch( $hash_id );
1255 0 my $tied = tied %$hash;
1256 0 return $tied->EXISTS( $key );
1257 }
1258  
1259 }
1260 0 return 0;
1261 } #EXISTS
1262  
1263 1393 ▶sub FETCH {
Subroutine FETCH: called CC=4 SCAR=22.2
1264 1393 my( $self, $key ) = @_;
1265 1393 my $data = $self->[DATA];
1266  
1267 1393 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) { } 1393 0 1393
1268 1393 return $self->[DSTORE]->_xform_out( $data->{$key} );
1269 } else {
1270 0 my $hval = 0;
1271 0 foreach (split //,$key) {
1272 0 $hval = $hval*33 - ord($_);
1273 }
1274 0 $hval = $hval % $self->[BUCKETS];
1275 0 my $hash = $self->[DSTORE]->_knot(substr($data->[$hval],1));
1276 0 ▶ if( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) 0 0 0
1277 0 return $hash->FETCH( $key );
1278 }
1279 }
1280 0 return undef;
1281 } #FETCH
1282  
1283 1382 ▶sub STORE {
Subroutine STORE: called CC=12 SCAR=39.9
1284 1382 my( $self, $key, $val ) = @_;
1285 1382 my $data = $self->[DATA];
1286  
1287 1382 my $store = $self->[DSTORE];
1288 1382 my( $xid, $xin ) = $store->_xform_in( $val );
1289 1382 ▶ if( $xid > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xid > 0) 9 1373 1382
1290 9 ▶ if( $xid < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xid < 3) 4 5 9
1291 4 $self->[SIZE]--;
1292 4 die "cannot store a root node in a hash";
1293 }
1294 }
1295  
1296 #
1297 # EMBIGGEN TEST
1298 #
1299 1378 ▶ unless( $self->EXISTS( $key ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->EXISTS($key)) 1372 6 1378
1300 1372 $self->[SIZE]++;
1301 }
1302  
1303
1304 1378 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) { } 1378 0 1378
1305 1378 my $oldin = $data->{$key};
1306 1378 ▶ if( $xin ne $oldin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xin ne $oldin) 1378 0 1378
1307 1378 $data->{$key} = $xin;
1308 1378 $store->_dirty( $self->[ID] );
1309  
1310 1378 ▶ if( $self->[SIZE] > $Data::ObjectStore::Hash::MAX_SIZE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6] > $Data::ObjectStore::Hash::MAX_SIZE) 0 1378 1378
1311  
1312 # do the thing converting this to a deeper level
1313 0 $self->[LEVEL] = 1;
1314 0 my( @newhash );
1315  
1316 0 my( @newids ) = ( 0 ) x $Data::ObjectStore::Hash::BUCKET_SIZE;
1317 0 $self->[BUCKETS] = $Data::ObjectStore::Hash::BUCKET_SIZE;
1318 0 for my $key (keys %$data) {
1319 0 my $hval = 0;
1320 0 foreach (split //,$key) {
1321 0 $hval = $hval*33 - ord($_);
1322 }
1323 0 $hval = $hval % $self->[BUCKETS];
1324 0 my $hash = $newhash[$hval];
1325 0 ▶ if( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) { } 0 0 0
1326 0 my $tied = tied %$hash;
1327 0 $tied->STORE( $key, $store->_xform_out($data->{$key}) );
1328 } else {
1329 0 $hash = {};
1330 0 my $hash_id = $store->_new_id;
1331 tie %$hash, 'Data::ObjectStore::Hash',
1332 0 $store, $hash_id, {%{$self->[METADATA]}},
1333 0 0, 0, 1, $key, $data->{$key};
1334 0 $store->_store_weak( $hash_id, $hash );
1335 0 $store->_dirty( $hash_id );
1336 0 $newhash[$hval] = $hash;
1337 0 $newids[$hval] = "r$hash_id";
1338 }
1339  
1340 }
1341 0 $self->[DATA] = \@newids;
1342 0 $data = $self->[DATA];
1343 # here is the problem. this isnt in weak yet!
1344 # this is a weak reference problem and the problem is at NEXTKEY with
1345 # LEVEL 0 hashes that are loaded from LEVEL 1 hashes that are loaded from
1346 # LEVEL 2 hashes. The level 1 hash is loaded and dumped as needed, not keeping
1347 # the ephermal info (or is that sort of chained..hmm)
1348 0 $store->_dirty( $self->[ID] );
1349  
1350 } # EMBIGGEN CHECK
1351 }
1352 }
1353 else { #
1354
1355 0 my $store = $self->[DSTORE];
1356 0 my $hval = 0;
1357 0 foreach (split //,$key) {
1358 0 $hval = $hval*33 - ord($_);
1359 }
1360 0 $hval = $hval % $self->[BUCKETS];
1361 0 my $hash_id = substr($data->[$hval],1);
1362 0 my $hash;
1363 # check if there is a subhash created here
1364 0 ▶ if( $hash_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_id > 0) { } 0 0 0
1365 # subhash was already created, so store the new val in it
1366 0 $hash = $store->fetch( $hash_id );
1367 0 my $tied = tied %$hash;
1368 0 $tied->STORE( $key, $val );
1369 } else {
1370 # subhash not already created, so create then store the new val in it
1371 # really improbable case.
1372 0 $hash = {};
1373 0 $hash_id = $store->_new_id;
1374  
1375 0 tie %$hash, 'Data::ObjectStore::Hash', $store, $hash_id, {%{$self->[METADATA]}}, 0, 0, 1, $key, $xin;
1376  
1377 0 $store->_store_weak( $hash_id, $hash );
1378 0 $store->_dirty( $hash_id );
1379 0 $data->[$hval] = "r$hash_id";
1380 }
1381 }
1382  
1383 } #STORE
1384  
1385 6 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=3 SCAR=12.0
1386 6 my $self = shift;
1387  
1388 6 my $data = $self->[DATA];
1389 6 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[4] == 0) 6 0 6
1390 6 my $a = scalar keys %$data; #reset
1391 6 my( $k, $val ) = each %$data;
1392 6 ▶ return wantarray ? ( $k => $self->[DSTORE]->_xform_out( $val ) ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
1393 }
1394 0 $self->[NEXT] = [undef,undef];
1395 0 return $self->NEXTKEY;
1396 }
1397  
1398 2740 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=12 SCAR=45.9
1399 2740 my $self = shift;
1400 2740 my $data = $self->[DATA];
1401 2740 my $lvl = $self->[LEVEL];
1402 2740 ▶ if( $lvl == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl == 0) { } 2740 0 2740
1403 2740 my( $k, $val ) = each %$data;
1404 2740 ▶ return wantarray ? ( $k => $self->[DSTORE]->_xform_out($val) ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2740 2740
1405 }
1406 else {
1407 0 my $store = $self->[DSTORE];
1408  
1409 0 my $at_start = ! defined( $self->[NEXT][0] );
1410  
1411 0 ▶ if( $at_start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at_start) 0 0 0
1412 0 $self->[NEXT][0] = 0;
1413 0 $self->[NEXT][1] = undef;
1414 }
1415  
1416 0 my $hash = $self->[NEXT][1];
1417 0 ▶ $at_start ||= ! $hash;
Condition0%0/3
$at_start ||= !$hash
l!l&&r!l&&!r
000
MC/DC0%0/2
$at_start ||= !$hash
$at_start !$hash
Truth table0%0/3
A ||= not(B)
A= $at_startB= !$hash
ABresult
1X1
011
000
1418 0 ▶ unless( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash) 0 0 0
1419 0 my $hash_id = substr( $data->[$self->[NEXT][0]], 1 );
1420 0 ▶ $hash = $store->fetch( $hash_id ) if $hash_id > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_id > 1 0 0 0
1421 }
1422  
1423 0 ▶ if( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) 0 0 0
1424 0 my $tied = tied( %$hash );
1425 0 ▶ my( $k, $v ) = $at_start ? $tied->FIRSTKEY : $tied->NEXTKEY;
Branch: 1 branch
BranchTrueFalseTotal
$at_start ? : 0 0 0
1426 0 ▶ if( defined( $k ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 0 0 0
1427 0 $self->[NEXT][1] = $hash; #to keep the weak reference
1428 0 ▶ return wantarray ? ( $k => $v ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1429 }
1430 }
1431  
1432 0 $self->[NEXT][1] = undef;
1433 0 $self->[NEXT][0]++;
1434  
1435 0 ▶ if( $self->[NEXT][0] > $#$data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7][0] > $data->$#*) 0 0 0
1436 0 $self->[NEXT][0] = undef;
1437 0 return undef;
1438 }
1439 # recursion case, the next bucket has been incremented
1440 0 return $self->NEXTKEY;
1441 }
1442  
1443 } #NEXTKEY
1444  
1445 13 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1446 13 my $self = shift;
1447  
1448 #remove all WEAK_REFS to the buckets
1449 13 undef $self->[DATA];
1450  
1451 13 delete $self->[DSTORE]->[Data::ObjectStore::WEAK]{$self->[ID]};
1452 }
1453  
1454 # END PACKAGE Data::ObjectStore::Hash
1455  
1456 # --------------------------------------------------------------------------------
1457  
1458  
1459 package Data::ObjectStore::Container;
1460  
1461 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1462 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1463 2 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1464 2 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1465  
1466 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
1467 2 ID => 0,
1468 DATA => 1,
1469 DSTORE => 2,
1470 METADATA => 3,
1471 VOLATILE => 4,
1472 DIRTY_BIT => 5,
1473 2 };
1474  
1475 #
1476 # The string version of the objectstore object is simply its id. This allows
1477 # object ids to easily be stored as hash keys.
1478 #
1479 use overload
1480 697 ▶ '""' => sub { my $self = shift; $self->[ID] },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
1481 5 ▶ eq => sub { ref($_[1]) && $_[1]->[ID] == $_[0]->[ID] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][0] == $_[0][0] 4 1 5
1482 3 ▶ ne => sub { ! ref($_[1]) || $_[1]->[ID] != $_[0]->[ID] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] or $_[1][0] != $_[0][0] 1 2 3
1483 3 ▶ '==' => sub { ref($_[1]) && $_[1]->[ID] == $_[0]->[ID] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][0] == $_[0][0] 2 1 3
1484 3 ▶ '!=' => sub { ! ref($_[1]) || $_[1]->[ID] != $_[0]->[ID] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] or $_[1][0] != $_[0][0] 1 2 3
1485 2 fallback => 1;
1486  
1487  
1488 199 ▶sub set {
Subroutine set: called CC=7 SCAR=19.5
1489 199 my( $self, $fld, $val ) = @_;
1490  
1491  
1492 199 my $store = $self->[DSTORE];
1493 199 my( $inid, $inval ) = $store->_xform_in( $val );
1494 199 ▶ if( $self->[ID] > 2 && $inid > 0 && $inid < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[0] > 2 and $inid > 0 and $inid < 3) 2 197 199
Condition100%6/6
$self->[0] > 2 and $inid > 0 and $inid < 3
!ll&&!rl&&r
18982
$self->[0] > 2 and $inid > 0
!ll&&!rl&&r
1622710
MC/DC100%3/3
$self->[0] > 2 and $inid > 0 and $inid < 3
$self->[0] > 2 $inid > 0 $inid < 3
Truth table100%4/4
A and B and C
A= $self->[0] > 2B= $inid > 0C= $inid < 3
ABCresult
0XX0
10X0
1100
1111
1495 2 die "cannot store a root node in a container";
1496 }
1497  
1498 197 my $oldval = $self->[DATA]{$fld};
1499  
1500 197 ▶ if( ! defined $self->[DATA]{$fld} || $oldval ne $inval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->[1]{$fld} or $oldval ne $inval) 197 0 197
Condition66%2/3
not defined $self->[1]{$fld} or $oldval ne $inval
l!l&&r!l&&!r
125720
MC/DC0%0/2
not defined $self->[1]{$fld} or $oldval ne $inval
not defined $self->[1]{$fld} $oldval ne $inval
Truth table66%2/3
not(A) or B
A= not defined $self->[1]{$fld}B= $oldval ne $inval
ABresult
1X1
011
000
1501 197 $store->_dirty( $self->[ID] );
1502 197 $self->[DIRTY_BIT] = 1;
1503 197 ▶ if( ! defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 3 194 197
1504 3 $self->[DATA]{$fld} = undef;
1505 3 return;
1506 }
1507 }
1508  
1509 194 $self->[DATA]{$fld} = $inval;
1510 194 return $store->_xform_out( $self->[DATA]{$fld} );
1511 } #set
1512  
1513 0 ▶sub remove_field {
Subroutine remove_field: not called CC=1 SCAR=6.9
1514 0 my( $self, $fld ) = @_;
1515 0 $self->[DSTORE]->_dirty( $self->[ID] );
1516 0 $self->[DIRTY_BIT] = 1;
1517 0 delete $self->[DATA]{$fld};
1518 }
1519  
1520 0 ▶sub fields {
Subroutine fields: not called CC=1 SCAR=6.9
1521 0 my $self = shift;
1522 0 return [keys %{$self->[DATA]}];
1523 } #fields
1524  
1525 351 ▶sub get {
Subroutine get: called CC=7 SCAR=19.5
1526 351 my( $self, $fld, $default ) = @_;
1527  
1528 351 my $cur = $self->[DATA]{$fld};
1529 351 my $store = $self->[DSTORE];
1530 351 ▶ if( ( ! defined( $cur ) || $cur eq 'u' ) && defined( $default ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($cur) || $cur eq "u" and defined $default) 18 333 351
Condition100%6/6
!defined($cur) || $cur eq "u" and defined $default
!ll&&!rl&&r
3161718
not defined $cur or $cur eq "u"
l!l&&r!l&&!r
314316
MC/DC100%3/3
!defined($cur) || $cur eq "u" and defined $default
not defined $cur $cur eq "u" defined $default
Truth table100%5/5
not(A) or B and C
A= not defined $curB= $cur eq "u"C= defined $default
ABCresult
00X0
1X00
0100
1X11
0111
1531 18 my( $xid, $xin ) = $store->_xform_in( $default );
1532 18 ▶ if( ref( $default ) && $self->[ID] > 2 && $xid < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $default and $self->[0] > 2 and $xid < 3) 2 16 18
Condition100%6/6
ref $default and $self->[0] > 2 and $xid < 3
!ll&&!rl&&r
1512
ref $default and $self->[0] > 2
!ll&&!rl&&r
4113
MC/DC100%3/3
ref $default and $self->[0] > 2 and $xid < 3
ref $default $self->[0] > 2 $xid < 3
Truth table100%4/4
A and B and C
A= ref $defaultB= $self->[0] > 2C= $xid < 3
ABCresult
0XX0
10X0
1100
1111
1533 2 die "cannot store a root node in a container";
1534 }
1535 16 $store->_dirty( $self->[ID] );
1536 16 $self->[DIRTY_BIT] = 1;
1537 16 $self->[DATA]{$fld} = $xin;
1538 }
1539 349 return $store->_xform_out( $self->[DATA]{$fld} );
1540  
1541 } #get
1542  
1543 1 ▶sub clearvol {
Subroutine clearvol: called CC=1 SCAR=0.0
1544 1 my( $self, $key ) = @_;
1545 1 delete $self->[VOLATILE]{$key};
1546 }
1547  
1548 2 ▶sub clearvols {
Subroutine clearvols: called CC=3 SCAR=11.0
1549 2 my( $self, @keys ) = @_;
1550 2 ▶ unless( @keys ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@keys) 1 1 2
1551 1 @keys = @{$self->vol_fields};
1552 }
1553 2 for my $key (@keys) {
1554 2 delete $self->[VOLATILE]{$key};
1555 }
1556 }
1557  
1558 12 ▶sub vol {
Subroutine vol: called CC=2 SCAR=6.9
1559 12 my( $self, $key, $val ) = @_;
1560 12 ▶ if( defined( $val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 6 6 12
1561 6 $self->[VOLATILE]{$key} = $val;
1562 }
1563 12 return $self->[VOLATILE]{$key};
1564 }
1565  
1566 4 ▶sub vol_fields {
Subroutine vol_fields: called CC=1 SCAR=0.0
1567 4 return [keys %{shift->[VOLATILE]}];
1568 }
1569  
1570 1 ▶sub lock {
Subroutine lock: called CC=1 SCAR=0.0
1571 1 shift->store->lock(@_);
1572 }
1573 1 ▶sub unlock {
Subroutine unlock: called CC=1 SCAR=0.0
1574 1 shift->store->unlock;
1575 }
1576  
1577 3 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
1578 3 return shift->[DSTORE];
1579 }
1580  
1581 #
1582 # Defines get_foo, set_foo, add_to_foolist, remove_from_foolist where foo
1583 # is any arbitrarily named field.
1584 #
1585 58 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=7 SCAR=19.5
1586 58 my( $s, $arg ) = @_;
1587 58 my $func = our $AUTOLOAD;
1588 58 ▶ if( $func =~/:add_to_(.*)/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($func =~ /:add_to_(.*)/) { } 2 56 58
elsif ($func =~ /:add_once_to_(.*)/) { } 1 55 56
elsif ($func =~ /:remove_from_(.*)/) { } 1 54 55
elsif ($func =~ /:remove_all_from_(.*)/) { } 1 53 54
elsif ($func =~ /:set_(.*)/) { } 26 27 53
elsif ($func =~ /:get_(.*)/) { } 26 1 27
1589 2 my( $fld ) = $1;
1590 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1591 11 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1592 11 my( $self, @vals ) = @_;
1593 11 my $get = "get_$fld";
1594 11 my $arry = $self->$get([]); # init array if need be
1595 11 push( @$arry, @vals );
1596 2 };
1597 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1598 2 goto &$AUTOLOAD;
1599 } #add_to
1600 elsif( $func =~/:add_once_to_(.*)/ ) {
1601 1 my( $fld ) = $1;
1602 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1603 3 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1604 3 my( $self, @vals ) = @_;
1605 3 my $get = "get_$fld";
1606 3 my $arry = $self->$get([]); # init array if need be
1607 3 for my $val ( @vals ) {
1608 9 ▶ unless( grep { $val eq $_ } @$arry ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$val eq $_;} @$arry) 2 7 9
1609 2 push @$arry, $val;
1610 }
1611 }
1612 1 };
1613 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1614 1 goto &$AUTOLOAD;
1615 } #add_once_to
1616 elsif( $func =~ /:remove_from_(.*)/ ) { #removes the first instance of the target thing from the list
1617 1 my $fld = $1;
1618 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1619 1 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1620 1 my( $self, @vals ) = @_;
1621 1 my $get = "get_$fld";
1622 1 my $arry = $self->$get([]); # init array if need be
1623 1 my( @ret );
1624 V:
1625 1 for my $val (@vals ) {
1626 3 for my $i (0..$#$arry) {
1627 11 ▶ if( $arry->[$i] eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arry->[$i] eq $val) 3 8 11
1628 3 push @ret, splice @$arry, $i, 1;
1629 3 next V;
1630 }
1631 }
1632 }
1633 1 return @ret;
1634 1 };
1635 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1636 1 goto &$AUTOLOAD;
1637 }
1638 elsif( $func =~ /:remove_all_from_(.*)/ ) { #removes the first instance of the target thing from the list
1639 1 my $fld = $1;
1640 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1641 1 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1642 1 my( $self, @vals ) = @_;
1643 1 my $get = "get_$fld";
1644 1 my $arry = $self->$get([]); # init array if need be
1645 1 my @ret;
1646 1 for my $val (@vals) {
1647 3 ▶ for( my $i=0; $i<=@$arry; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= @$arry) 23 3 26
1648 23 ▶ if( $arry->[$i] eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arry->[$i] eq $val) 7 16 23
1649 7 push @ret, splice @$arry, $i, 1;
1650 7 $i--;
1651 }
1652 }
1653 }
1654 1 return @ret;
1655 1 };
1656 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1657 1 goto &$AUTOLOAD;
1658 }
1659 elsif ( $func =~ /:set_(.*)/ ) {
1660 26 my $fld = $1;
1661 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1662 171 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1663 171 my( $self, $val ) = @_;
1664 171 $self->set( $fld, $val );
1665 26 };
1666 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1667 26 goto &$AUTOLOAD;
1668 }
1669 elsif( $func =~ /:get_(.*)/ ) {
1670 26 my $fld = $1;
1671 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1672 193 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1673 193 my( $self, $init_val ) = @_;
1674 193 $self->get( $fld, $init_val );
1675 26 };
1676 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1677 26 goto &$AUTOLOAD;
1678 }
1679 else {
1680 1 die "Data::ObjectStore::Container::$func : unknown function '$func'.";
1681 }
1682  
1683 } #AUTOLOAD
1684  
1685 # -----------------------
1686 #
1687 # Overridable Methods
1688 #
1689 # -----------------------
1690  
1691  
1692  
1693 36 ▶sub _init {}
Subroutine _init: called CC=1 SCAR=0.0
1694  
1695  
1696 93 ▶sub _load {}
Subroutine _load: called CC=1 SCAR=0.0
1697  
1698  
1699  
1700 # -----------------------
1701 #
1702 # Private Methods
1703 #
1704 # -----------------------
1705  
1706 135 ▶sub _freezedry {
Subroutine _freezedry: called CC=4 SCAR=13.9
1707 135 my $self = shift;
1708 135 ▶ join( "`", map { if( defined($_) && $_=~ /[\\\`]/ ) { s/[\\]/\\\\/gs; s/`/\\`/gs; } defined($_) ? $_ : 'u' } %{$self->[DATA]} );
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_ and $_ =~ /[\\\`]/) 25 949 974
defined $_ ? : 972 2 974
Condition100%3/3
defined $_ and $_ =~ /[\\\`]/
!ll&&!rl&&r
294725
MC/DC100%2/2
defined $_ and $_ =~ /[\\\`]/
defined $_ $_ =~ /[\\\`]/
Truth table100%3/3
A and B
A= defined $_B= $_ =~ /[\\\`]/
ABresult
0X0
100
111
1709 }
1710  
1711 93 ▶sub _reconstitute {
Subroutine _reconstitute: called CC=2 SCAR=6.9
1712 93 my( $cls, $store, $id, $data, $meta ) = @_;
1713 93 my $obj = [$id,{@$data},$store, $meta, {}];
1714 93 ▶ if( $cls ne 'Data::ObjectStore::Container' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cls ne "Data::ObjectStore::Container") 2 91 93
1715 2 my $clname = $cls;
1716 2 $clname =~ s/::/\//g;
1717  
1718 2 require "$clname.pm";
1719 }
1720  
1721 93 bless $obj, $cls;
1722  
1723 93 $obj->_load;
1724 93 $obj;
1725 }
1726  
1727 103 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1728 103 my $self = shift;
1729 103 delete $self->[DSTORE][Data::ObjectStore::WEAK]{$self->[ID]};
1730 }
1731  
1732 # END PACKAGE Data::ObjectStore::Container
1733  
1734 2 1;
1735  
1736 __END__
« script/class_mapper.pl ↑ Summary lib/Data/ObjectStore/Cache.pm »