blib/lib/Yote.pm

filter: Statementstmt 17.7% 149 / 842 Branchbran 0.3% 1 / 296 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 64 Subroutinesub 43.1% 50 / 116 Podpod 100% 1 / 1 totaltotal 14.1% 201 / 1424 CC 203 SCAR 46.0
CC
203
Cov
12%
SPLICE
552.0
run_recycler
380.0
_fetch
210.0
CRAP 99.5
↑ Summary
1 package Yote;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = '3.0';
10 1 $Yote::DB_VERSION = 3;
11  
12 1 ▶sub open_store {
Subroutine open_store: called CC=1 SCAR=0.4
Pod documented
13 1 my $path = pop;
14 1 my $store = Yote::ObjStore->open_store( $path );
15 0 $store;
16 }
17  
18 # --------------------------------------------------------------------------------
19  
20 package Yote::ObjStore;
21  
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use Data::RecordStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 RECORD_STORE => 0,
35 DIRTY => 1,
36 WEAK => 2,
37 PATH => 3,
38 STOREINFO => 4,
39  
40 ID => 0,
41 DATA => 1,
42 LEVEL => 3,
43 1 };
44  
45 #
46 # Fetches the user facing root node. This node is
47 # off of the store info node as 'root'
48 #
49 0 ▶sub fetch_root {
Subroutine fetch_root: not called CC=2 SCAR=17.9
50 0 my $self = shift;
51 0 my $info_node = $self->_fetch_store_info_node;
52 0 my $root = $info_node->get_root;
53 0 ▶ unless( $root ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($root) 0 0 0
54 0 $root = $self->newobj;
55 0 $info_node->set_root( $root );
56 0 $self->stow_all;
57 }
58 0 $root;
59 } #fetch_root
60  
61 0 ▶sub _fetch_store_info_node {
Subroutine _fetch_store_info_node: not called CC=7 SCAR=40.3
62 0 my $self = shift;
63 0 my $node = $self->_fetch( 1 );
64 0 ▶ unless( $node ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 0 0
65 0 my $first_id = $self->_new_id;
66 0 ▶ die "Fetch STORE INFO NODE must have ID of 1, got '$first_id'" unless $first_id == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_id == 1 0 0 0
67 0 my $now = time;
68 0 $node = bless [ 1, {}, $self ], 'Yote::Obj';
69 0 $node->set_db_version( $Yote::DB_VERSION );
70 0 $node->set_yote_version( $Yote::VERSION );
71 0 $node->set_created_time( $now );
72 0 $node->set_last_update_time( $now );
73 0 $self->stow_all;
74 }
75  
76 # check to make sure that the db version is compatable with this.
77 0 ▶ if( $node->get_db_version < $Yote::DB_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_db_version < $Yote::DB_VERSION) 0 0 0
78 0 ▶ die "Unable to opening earlier database version ".($node->get_db_version || 'unknown').". Please run 'yote_db_convert $self->[PATH]'";
Condition0%0/2
$node->get_db_version || 'unknown'
l!l
00
MC/DC0%0/1
$node->get_db_version || 'unknown'
$node->get_db_version
Truth table0%0/2
A
A= $node->get_db_version
Aresult
11
00
79 }
80 0 ▶ if( $node->get_db_version > $Yote::DB_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_db_version > $Yote::DB_VERSION) 0 0 0
81 0 ▶ die "Unable to open more advance database version ".($node->get_db_version || 'unknown').". Upgrade yote to open";
Condition0%0/2
$node->get_db_version || 'unknown'
l!l
00
MC/DC0%0/1
$node->get_db_version || 'unknown'
$node->get_db_version
Truth table0%0/2
A
A= $node->get_db_version
Aresult
11
00
82 }
83  
84 0 $node;
85 } #_fetch_store_info_node
86  
87 #
88 # Returns a hash of the info set for this store
89 #
90 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
91 0 my $node = shift->[STOREINFO];
92 my $info = {
93 0 map { $_ => $node->get($_) }
94 qw( db_version yote_version created_time last_update_time )
95 };
96 0 $info;
97 } #info
98  
99 1 ▶sub open_store {
Subroutine open_store: called CC=3 SCAR=14.7
100 1 my( $cls, $base_path ) = @_;
101  
102 #
103 # Yote subpackages are not normally in %INC and should always be loaded.
104 #
105 1 for my $pkg ( qw( Yote::Obj Yote::Array Yote::Hash ) ) {
106 0 ▶ $INC{ $pkg } or eval("use $pkg");
Subroutine BEGIN: called CC=1 SCAR=1.8
Subroutine BEGIN: called CC=1 SCAR=1.8
Subroutine BEGIN: called CC=1 SCAR=1.8
Branch: 1 branch
BranchTrueFalseTotal
$INC{$pkg} or eval "use $pkg" 0 3 3
107 }
108  
109 1 my $store = bless [
110 Data::RecordStore->open( "$base_path/RECORDSTORE" ),
111 {}, #DIRTY CACHE
112 {}, #WEAK CACHE
113 $base_path
114 ], $cls;
115  
116 0 $store->[STOREINFO] = $store->_fetch_store_info_node;
117  
118 0 $store;
119  
120 } #open_store
121  
122 0 ▶sub newobj {
Subroutine newobj: not called CC=2 SCAR=17.9
123 # works with newobj( { my data } ) or newobj( 'myclass', { my data } )
124 0 my $self = shift;
125 0 my $data = pop;
126 0 ▶ my $class = pop || 'Yote::Obj';
Condition0%0/2
pop() || 'Yote::Obj'
l!l
00
MC/DC0%0/1
pop() || 'Yote::Obj'
pop()
Truth table0%0/2
A
A= pop()
Aresult
11
00
127  
128 0 my $id = $self->_new_id;
129 my $obj = bless [ $id,
130 0 { map { $_ => $self->_xform_in( $data->{$_} ) } keys %$data},
131 $self ], $class;
132 0 $self->_dirty( $obj, $id );
133 0 $self->_store_weak( $id, $obj );
134 0 $obj->_init(); #called the first time the object is created.
135 0 $obj;
136 } #newobj
137  
138 #
139 # Recycles and compacts store. IDs that were not found in the store
140 # are marked for reuse.
141 #
142 0 ▶sub run_recycler {
Subroutine run_recycler: not called CC=19 SCAR=59.4
143 0 my $self = shift;
144 0 $self->stow_all;
145 0 my $base_path = $self->[PATH];
146 0 my $recycle_tally = Data::RecordStore->open( "$base_path/RECYCLE" );
147  
148 # empty because this may have run recently
149 0 $self->[RECORD_STORE]->empty_recycler;
150 0 $recycle_tally->empty;
151  
152 0 $recycle_tally->stow( "1", 1 );
153 0 $recycle_tally->stow( "0", $self->[RECORD_STORE]->entry_count );
154  
155 0 my $item = $self->fetch_root;
156  
157 # add the ids from the weak references
158 0 my( @keep_ids ) = ( $item->id, keys %{$self->[WEAK]} );
159  
160  
161 0 ▶ while( @keep_ids ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keep_ids) 0 0 0
162 0 my $id = shift @keep_ids;
163  
164 0 $item = $self->_fetch( $id );
165 0 $recycle_tally->stow( 1, $id );
166 0 my $ref = ref($item);
167 0 ▶ if( $item eq 'Yote::Array' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($item eq 'Yote::Array') { } 0 0 0
elsif ($item eq 'Yote::Hash') { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref eq 'HASH') { } 0 0 0
168 0 my $tied = tied( @$item );
169 0 my $data = $tied->[DATA];
170 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } @$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
171 }
172 elsif( $item eq 'Yote::Hash' ) {
173 0 my $tied = tied( %$item );
174 0 my $data = $tied->[DATA];
175 0 ▶ if( $tied->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tied->[3] == 0) { } 0 0 0
176 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } values %$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
177 } else {
178 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } @$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
179 }
180 }
181 elsif( $ref eq 'ARRAY' ) {
182 0 my $tied = tied( @$item );
183 0 ▶ if( $tied ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tied) { } 0 0 0
184 0 my $data = $tied->[DATA];
185 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } @$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
186 } else {
187 0 push @keep_ids, grep { $recycle_tally->fetch($_) != 1 } map { $self->_get_id($_) } grep { ref( $_ ) } @$item;
188 }
189 }
190 elsif( $ref eq 'HASH' ) {
191 0 my $tied = tied( %$item );
192 0 ▶ if( $tied ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tied) { } 0 0 0
193 0 my $data = $tied->[DATA];
194 0 ▶ if( $tied->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tied->[3] == 0) { } 0 0 0
195 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } values %$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
196 } else {
197 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch( $_ ) != 1 } @$data;
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
198 }
199 } else {
200 0 push @keep_ids, grep { $recycle_tally->fetch($_) != 1 } map { $self->_get_id($_) } grep { ref( $_ ) } values %$item;
201 }
202 }
203 else {
204 0 ▶ push @keep_ids, grep { $_ > 1 && $recycle_tally->fetch($_) != 1 } values %{$item->[DATA]};
Condition0%0/3
$_ > 1 && $recycle_tally->fetch($_) != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > 1 && $recycle_tally->fetch($_) != 1
$_ > 1 $recycle_tally->fetch($_) != 1
Truth table0%0/3
A && B
A= $_ > 1B= $recycle_tally->fetch($_) != 1
ABresult
0X0
100
111
205 }
206 } #going through all keep_ids
207 0 undef $item;
208  
209 0 my $record_store = $self->[RECORD_STORE];
210 0 my $count = $record_store->entry_count;
211 0 ▶ for( my $i=1; $i<=$count; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $count) 0 0 0
212 0 ▶ if( $recycle_tally->fetch($i) != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recycle_tally->fetch($i) != 1) 0 0 0
213 0 $record_store->recycle_id( $i );
214 }
215 }
216 # empty to save space
217 0 $recycle_tally->empty;
218 } #run_recycler
219  
220 0 ▶sub stow_all {
Subroutine stow_all: not called CC=5 SCAR=34.0
221 0 my $self = shift;
222 0 for my $id ( keys %{$self->[DIRTY]} ) {
223 0 my $obj = $self->[DIRTY]{$id};
224 0 ▶ next unless $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
225 0 my $cls = ref( $obj );
226  
227 0 ▶ my $thingy = $cls eq 'HASH' ? tied( %$obj ) : $cls eq 'ARRAY' ? tied( @$obj ) : $obj;
Branch: 2 branches
BranchTrueFalseTotal
$cls eq 'HASH' ? : 0 0 0
$cls eq 'ARRAY' ? : 0 0 0
228 0 my $text_rep = $thingy->_freezedry;
229 0 my $class = ref( $thingy );
230  
231  
232 0 $self->[RECORD_STORE]->stow( "$class $text_rep", $id );
233 }
234 0 $self->[DIRTY] = {};
235  
236 } #stow_all
237  
238 0 ▶sub _fetch {
Subroutine _fetch: not called CC=14 SCAR=53.5
239 0 my( $self, $id ) = @_;
240 0 ▶ return undef unless $id && $id ne 'u';
Branch: 1 branch
BranchTrueFalseTotal
unless $id and $id ne "u" 0 0 0
Condition0%0/3
$id and $id ne "u"
!ll&&!rl&&r
000
MC/DC0%0/2
$id and $id ne "u"
$id $id ne "u"
Truth table0%0/3
A and B
A= $idB= $id ne "u"
ABresult
0X0
100
111
241  
242 0 ▶ my $ref = $self->[DIRTY]{$id} //$self->[WEAK]{$id};
Condition0%0/3
$self->[1]{$id} // $self->[2]{$id}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[1]{$id} // $self->[2]{$id}
$self->[1]{$id} $self->[2]{$id}
Truth table0%0/3
A // B
A= $self->[1]{$id}B= $self->[2]{$id}
ABresult
1X1
011
000
243 0 ▶ return $ref if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
244  
245 0 my $stowed = $self->[RECORD_STORE]->fetch( $id );
246  
247 0 ▶ return undef unless $stowed;
Branch: 1 branch
BranchTrueFalseTotal
unless $stowed 0 0 0
248  
249 0 my $pos = index( $stowed, ' ' );
250 0 ▶ die "Malformed record '$stowed'" if $pos == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == -1 0 0 0
251  
252 0 my $class = substr $stowed, 0, $pos;
253 0 my $dryfroze = substr $stowed, $pos + 1;
254  
255 0 ▶ unless( $INC{ $class } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$class}) 0 0 0
256 0 eval("use $class");
257 }
258  
259 # so foo` or foo\\` but not foo\\\`
260 # also this will never start with a `
261 0 my $pieces = [ split /\`/, $dryfroze, -1 ];
262  
263 # check to see if any of the parts were split on escapes
264 # like mypart`foo`oo (should be translated to mypart\`foo\`oo
265 0 ▶ if ( 0 < grep { /\\$/ } @$pieces ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < grep({/\\$/;} @$pieces)) 0 0 0
266 0 my $newparts = [];
267  
268 0 my $is_hanging = 0;
269 0 my $working_part = '';
270  
271 0 for my $part (@$pieces) {
272  
273 # if the part ends in a hanging escape
274 0 ▶ if ( $part =~ /(^|[^\\])((\\\\)+)?[\\]$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($part =~ /(^|[^\\])((\\\\)+)?[\\]$/) { } 0 0 0
elsif ($is_hanging) { } 0 0 0
275 0 ▶ if ( $is_hanging ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_hanging) { } 0 0 0
276 0 $working_part .= "`$part";
277 } else {
278 0 $working_part = $part;
279 }
280 0 $is_hanging = 1;
281 } elsif ( $is_hanging ) {
282 0 my $newpart = "$working_part`$part";
283 0 $newpart =~ s/\\`/`/gs;
284 0 $newpart =~ s/\\\\/\\/gs;
285 0 push @$newparts, $newpart;
286 0 $is_hanging = 0;
287 } else {
288 # normal part
289 0 push @$newparts, $part;
290 }
291 }
292 0 ▶ if ( $is_hanging ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_hanging) 0 0 0
293 0 die "Error in parsing parts\n";
294 }
295 0 $pieces = $newparts;
296 } #if there were escaped ` characters
297  
298 0 my $ret = $class->_reconstitute( $self, $id, $pieces );
299 0 $self->_store_weak( $id, $ret );
300 0 return $ret;
301 } #_fetch
302  
303 0 ▶sub _xform_in {
Subroutine _xform_in: not called CC=3 SCAR=24.8
304 0 my( $self, $val ) = @_;
305 0 ▶ if( ref( $val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) 0 0 0
306 0 return $self->_get_id( $val );
307 }
308 0 ▶ return defined $val ? "v$val" : 'u';
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
309 }
310  
311 0 ▶sub _xform_out {
Subroutine _xform_out: not called CC=4 SCAR=30.0
312 0 my( $self, $val ) = @_;
313 0 ▶ return undef unless defined( $val ) && $val ne 'u';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and $val ne "u" 0 0 0
Condition0%0/3
defined $val and $val ne "u"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val ne "u"
defined $val $val ne "u"
Truth table0%0/3
A and B
A= defined $valB= $val ne "u"
ABresult
0X0
100
111
314 0 ▶ if( index($val,'v') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($val, "v") == 0) 0 0 0
315 0 return substr( $val, 1 );
316 }
317 0 return $self->_fetch( $val );
318 }
319  
320 0 ▶sub _store_weak {
Subroutine _store_weak: not called CC=2 SCAR=17.9
321 0 my( $self, $id, $ref ) = @_;
322 0 ▶ die "Store weak called without ref" unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 0 0
323 0 $self->[WEAK]{$id} = $ref;
324  
325 0 weaken( $self->[WEAK]{$id} );
326 } #_store_weak
327  
328 0 ▶sub _dirty {
Subroutine _dirty: not called CC=2 SCAR=17.9
329 0 ▶ return unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 0 0
330 0 $_[0]->[DIRTY]->{$_[2]} = $_[1];
331 } #_dirty
332  
333  
334 0 ▶sub _new_id {
Subroutine _new_id: not called CC=1 SCAR=6.9
335 0 my( $self ) = @_;
336 0 $self->[RECORD_STORE]->next_id;
337 } #_new_id
338  
339 0 ▶sub _get_id {
Subroutine _get_id: not called CC=10 SCAR=47.0
340 0 my( $self, $ref ) = @_;
341  
342 0 my $class = ref( $ref );
343  
344 0 ▶ die "_get_id requires reference. got '$ref'" unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
345  
346 0 ▶ if( $class eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'ARRAY') { } 0 0 0
elsif ($class eq 'HASH') { } 0 0 0
347 0 my $thingy = tied @$ref;
348 0 ▶ if( ! $thingy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thingy) 0 0 0
349 0 my $id = $self->_new_id;
350 0 tie @$ref, 'Yote::Array', $self, $id, 0, $Yote::Array::MAX_BLOCKS, scalar(@$ref), 0, map { $self->_xform_in($_) } @$ref;
351 0 $self->_store_weak( $id, $ref );
352 0 $self->_dirty( $self->[WEAK]{$id}, $id );
353 0 return $id;
354 }
355 0 $ref = $thingy;
356 0 $class = ref( $ref );
357 }
358 elsif( $class eq 'HASH' ) {
359 0 my $thingy = tied %$ref;
360 0 ▶ if( ! $thingy ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thingy) 0 0 0
361 0 my $id = $self->_new_id;
362 0 my( @keys ) = keys %$ref;
363 0 tie %$ref, 'Yote::Hash', $self, $id, undef, undef, scalar(@keys), map { $_ => $self->_xform_in($ref->{$_}) } @keys;
364 0 $self->_store_weak( $id, $ref );
365 0 $self->_dirty( $self->[WEAK]{$id}, $id );
366 0 return $id;
367 }
368 0 $ref = $thingy;
369 0 $class = ref( $ref );
370 }
371 0 ▶ die "Cannot injest object that is not a hash, array or yote obj" unless ( $class eq 'Yote::Hash' || $class eq 'Yote::Array' || $ref->isa( 'Yote::Obj' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "Yote::Hash" or $class eq "Yote::Array" or $ref->isa("Yote::Obj") 0 0 0
Condition0%0/6
$class eq "Yote::Hash" or $class eq "Yote::Array" or $ref->isa("Yote::Obj")
l!l&&r!l&&!r
000
$class eq "Yote::Hash" or $class eq "Yote::Array"
l!l&&r!l&&!r
000
MC/DC0%0/3
$class eq "Yote::Hash" or $class eq "Yote::Array" or $ref->isa("Yote::Obj")
$class eq "Yote::Hash" $class eq "Yote::Array" $ref->isa("Yote::Obj")
Truth table0%0/4
A or B or C
A= $class eq "Yote::Hash"B= $class eq "Yote::Array"C= $ref->isa("Yote::Obj")
ABCresult
1XX1
01X1
0011
0000
372 0 ▶ $ref->[ID] ||= $self->_new_id;
Condition0%0/3
$ref->[0] ||= $self->_new_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$ref->[0] ||= $self->_new_id
$ref->[0] $self->_new_id
Truth table0%0/3
A ||= B
A= $ref->[0]B= $self->_new_id
ABresult
1X1
011
000
373 0 return $ref->[ID];
374  
375 } #_get_id
376  
377 # --------------------------------------------------------------------------------
378  
379 package Yote::Array;
380  
381  
382 ##################################################################################
383 # This module is used transparently by Yote to link arrays into its graph #
384 # structure. This is not meant to be called explicitly or modified. #
385 ##################################################################################
386  
387 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
388 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
389 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
390 1 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
391 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
392 #no warnings 'recursion';
393  
394 1 ▶use Tie::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
395  
396 1 $Yote::Array::MAX_BLOCKS = 1_000_000;
397  
398 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
399 1 ID => 0,
400 DATA => 1,
401 DSTORE => 2,
402 LEVEL => 3,
403 BLOCK_COUNT => 4,
404 BLOCK_SIZE => 5,
405 ITEM_COUNT => 6,
406 UNDERNEATH => 7,
407  
408 WEAK => 2,
409 1 };
410  
411 0 ▶sub _freezedry {
Subroutine _freezedry: not called CC=10 SCAR=47.0
412 0 my $self = shift;
413 0 my @items;
414 0 ▶ my $stuff_count = $self->[BLOCK_COUNT] > $self->[ITEM_COUNT] ? $self->[ITEM_COUNT] : $self->[BLOCK_COUNT];
Branch: 1 branch
BranchTrueFalseTotal
$self->[4] > $self->[6] ? : 0 0 0
415 0 ▶ if( $stuff_count > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stuff_count > 0) 0 0 0
416 0 ▶ @items = map { if( defined($_) && $_=~ /[\\\`]/ ) { $_ =~ s/[\\]/\\\\/gs; s/`/\\`/gs; } defined($_) ? $_ : 'u' } map { $self->[DATA][$_] } (0..($stuff_count-1));
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_ and $_ =~ /[\\\`]/) 0 0 0
defined $_ ? : 0 0 0
Condition0%0/3
defined $_ and $_ =~ /[\\\`]/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and $_ =~ /[\\\`]/
defined $_ $_ =~ /[\\\`]/
Truth table0%0/3
A and B
A= defined $_B= $_ =~ /[\\\`]/
ABresult
0X0
100
111
417 }
418  
419 0 ▶ join( "`",
Condition0%0/8
$self->[3] || 0
l!l
00
$self->[4] || 0
l!l
00
$self->[6] || 0
l!l
00
$self->[7] || 0
l!l
00
MC/DC0%0/1
$self->[3] || 0
$self->[3]
MC/DC0%0/1
$self->[4] || 0
$self->[4]
MC/DC0%0/1
$self->[6] || 0
$self->[6]
MC/DC0%0/1
$self->[7] || 0
$self->[7]
Truth table0%0/2
A
A= $self->[3]
Aresult
11
00
Truth table0%0/2
A
A= $self->[4]
Aresult
11
00
Truth table0%0/2
A
A= $self->[6]
Aresult
11
00
Truth table0%0/2
A
A= $self->[7]
Aresult
11
00
420 $self->[LEVEL] || 0,
421 $self->[BLOCK_COUNT] || 0,
422 $self->[ITEM_COUNT] || 0,
423 $self->[UNDERNEATH] || 0,
424 @items,
425 );
426 }
427  
428 0 ▶sub _reconstitute {
Subroutine _reconstitute: not called CC=1 SCAR=6.9
429 0 my( $cls, $store, $id, $data ) = @_;
430 0 my $arry = [];
431 0 tie @$arry, $cls, $store, $id, @$data;
432  
433 0 return $arry;
434 }
435  
436 0 ▶sub TIEARRAY {
Subroutine TIEARRAY: not called CC=6 SCAR=37.4
437 0 my( $class, $obj_store, $id, $level, $block_count, $item_count, $underneath, @list ) = @_;
438  
439 0 my $block_size = $block_count ** $level;
440  
441 0 ▶ die "DSFSOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" if $block_size == 1&&$level > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $block_size == 1 and $level > 0 0 0 0
Condition0%0/3
$block_size == 1 and $level > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$block_size == 1 and $level > 0
$block_size == 1 $level > 0
Truth table0%0/3
A and B
A= $block_size == 1B= $level > 0
ABresult
0X0
100
111
442 0 ▶ die "NOO" if $block_count < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $block_count < 1 0 0 0
443  
444 0 my $use_push = @list > $block_count;
445  
446 0 ▶ my $blocks = $use_push ? [] : [@list];
Branch: 1 branch
BranchTrueFalseTotal
$use_push ? : 0 0 0
447 0 $#$blocks = $block_count - 1;
448  
449 # once the array is tied, an additional data field will be added
450 # so obj will be [ $id, $storage, $obj_store ]
451 0 my $obj = bless [
452 $id,
453 $blocks,
454 $obj_store,
455 $level,
456 $block_count,
457 $block_size,
458 $item_count,
459 $underneath,
460 ], $class;
461  
462 0 ▶ if( $use_push ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_push) 0 0 0
463 0 $obj->[ITEM_COUNT] = 0;
464 0 $obj->PUSH( map { $obj_store->_xform_out($_) } @list );
465 }
466  
467 0 return $obj;
468 } #TIEARRAY
469  
470 0 ▶sub FETCH {
Subroutine FETCH: not called CC=4 SCAR=30.0
471 0 my( $self, $idx ) = @_;
472  
473 0 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[6]) 0 0 0
474 0 return undef;
475 }
476  
477 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) 0 0 0
478 0 return $self->[DSTORE]->_xform_out( $self->[DATA][$idx] );
479 }
480  
481 0 my $block = $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) );
482 0 ▶ if( $block ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block) 0 0 0
483 0 return $block->FETCH( $idx % $self->[BLOCK_SIZE] );
484 }
485  
486 0 return undef;
487 } #FETCH
488  
489 0 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
490 0 shift->[ITEM_COUNT];
491 }
492  
493 0 ▶sub _embiggen {
Subroutine _embiggen: not called CC=3 SCAR=24.8
494 0 my( $self, $size ) = @_;
495 0 my $store = $self->[DSTORE];
496 0 ▶ while( $size > $self->[BLOCK_SIZE] * $self->[BLOCK_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $self->[5] * $self->[4]) 0 0 0
497 0 ▶ die "UNDERNATH $size > $self->[BLOCK_SIZE] * $self->[BLOCK_COUNT]" if $self->[UNDERNEATH];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[7] 0 0 0
498 #
499 # need to tie a new block, not use _getblock
500 # becaues we do squirrely things with its tied guts
501 #
502 0 my $newblock = [];
503 0 my $newid = $store->_new_id;
504 0 tie @$newblock, 'Yote::Array', $store, $newid, $self->[LEVEL], $self->[BLOCK_COUNT], $self->[ITEM_COUNT], 1;
505 0 $store->_store_weak( $newid, $newblock );
506 0 $store->_dirty( $store->[WEAK]{$newid}, $newid );
507  
508 0 my $tied = tied @$newblock;
509 0 $tied->[DATA] = [@{$self->[DATA]}];
510  
511  
512 0 $self->[DATA] = [ $newid ];
513  
514 0 $self->[BLOCK_SIZE] *= $self->[BLOCK_COUNT];
515 0 $self->[LEVEL]++;
516 0 $store->_dirty( $store->[WEAK]{$self->[ID]}, $self->[ID] );
517 }
518 } #_embiggen
519  
520 #
521 # get a block at the given block index. Returns undef
522 # if there isn't one ther, or creates and returns
523 # one if passed do create
524 #
525 0 ▶sub _getblock {
Subroutine _getblock: not called CC=6 SCAR=37.4
526 0 my( $self, $block_idx ) = @_;
527  
528 0 my $block_id = $self->[DATA][$block_idx];
529 0 my $store = $self->[DSTORE];
530  
531 0 ▶ if( $block_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_id > 0) 0 0 0
532 0 my $block = $store->_fetch( $block_id );
533 0 ▶ return tied(@$block)||$block;
Condition0%0/3
tied @$block || $block
l!l&&r!l&&!r
000
MC/DC0%0/2
tied @$block || $block
tied @$block $block
Truth table0%0/3
A || B
A= tied @$blockB= $block
ABresult
1X1
011
000
534 0 ▶ return wantarray ? ($block, tied( @$block )) : tied( @$block );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
535 }
536  
537 0 $block_id = $store->_new_id;
538 0 my $block = [];
539 0 my $level = $self->[LEVEL] - 1;
540 0 tie @$block, 'Yote::Array', $store, $block_id, $level, $self->[BLOCK_COUNT];
541  
542 0 my $tied = tied( @$block );
543 0 $tied->[UNDERNEATH] = 1;
544 0 ▶ if( $block_idx >= ($self->[BLOCK_COUNT] - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block_idx >= $self->[4] - 1) 0 0 0
545 0 $tied->[ITEM_COUNT] = $self->[BLOCK_SIZE];
546 }
547  
548 0 $store->_store_weak( $block_id, $block );
549 0 $store->_dirty( $store->[WEAK]{$block_id}, $block_id );
550 0 $store->_dirty( $store->[WEAK]{$self->[ID]}, $self->[ID] );
551 0 $self->[DATA][$block_idx] = $block_id;
552 0 return $tied;
553 0 ▶ return wantarray ? ($block, $tied) : $tied;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
554  
555 } #_getblock
556  
557 0 ▶sub STORE {
Subroutine STORE: not called CC=4 SCAR=30.0
558 0 my( $self, $idx, $val ) = @_;
559  
560 0 ▶ if( $idx >= $self->[BLOCK_COUNT]*$self->[BLOCK_SIZE] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[4] * $self->[5]) 0 0 0
561 0 $self->_embiggen( $idx + 1 );
562 0 $self->STORE( $idx, $val );
563 0 return;
564 }
565  
566 0 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[6]) 0 0 0
567 0 $self->_storesize( $idx + 1 );
568 0 my $store = $self->[DSTORE];
569 0 $store->_dirty( $store->[WEAK]{$self->[ID]}, $self->[ID] );
570 }
571  
572 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) 0 0 0
573 0 $self->[DATA][$idx] = $self->[DSTORE]->_xform_in( $val );
574 0 my $store = $self->[DSTORE];
575 0 $store->_dirty( $store->[WEAK]{$self->[ID]}, $self->[ID] );
576 0 return;
577 }
578  
579 0 my $block = $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) );
580 0 $block->STORE( $idx % $self->[BLOCK_SIZE], $val );
581  
582 } #STORE
583  
584 0 ▶sub _storesize {
Subroutine _storesize: not called CC=2 SCAR=17.9
585 0 my( $self, $size ) = @_;
586 0 ▶ die "BADSET in ID $self->[ID] $size > $self->[BLOCK_COUNT] * $self->[BLOCK_SIZE] " if $size > $self->[BLOCK_COUNT] * $self->[BLOCK_SIZE];
Branch: 1 branch
BranchTrueFalseTotal
if $size > $self->[4] * $self->[5] 0 0 0
587 0 $self->[ITEM_COUNT] = $size;
588 }
589  
590 0 ▶sub STORESIZE {
Subroutine STORESIZE: not called CC=3 SCAR=24.8
591 0 my( $self, $size ) = @_;
592  
593 0 ▶ $size = 0 if $size < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 0 0 0 0
594  
595  
596 # fixes the size of the array if the array were to shrink
597 0 my $current_oversize = $self->[ITEM_COUNT] - $size;
598 0 ▶ if( $current_oversize > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_oversize > 0) 0 0 0
599 0 $self->SPLICE( $size, $current_oversize );
600 } #if the array shrinks
601  
602 0 $self->_storesize( $size );
603  
604 } #STORESIZE
605  
606 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=4 SCAR=30.0
607 0 my( $self, $idx ) = @_;
608 0 ▶ if( $idx >= $self->[ITEM_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= $self->[6]) 0 0 0
609 0 return 0;
610 }
611 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) 0 0 0
612 0 ▶ return exists $self->[DATA][$idx] && $self->[DATA][$idx] ne 'u';
Condition0%0/3
exists $self->[1][$idx] && $self->[1][$idx] ne 'u'
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->[1][$idx] && $self->[1][$idx] ne 'u'
exists $self->[1][$idx] $self->[1][$idx] ne 'u'
Truth table0%0/3
A && B
A= exists $self->[1][$idx]B= $self->[1][$idx] ne 'u'
ABresult
0X0
100
111
613 }
614 0 return $self->_getblock( int( $idx / $self->[BLOCK_SIZE] ) )->EXISTS( $idx % $self->[BLOCK_SIZE] );
615  
616 } #EXISTS
617  
618 0 ▶sub DELETE {
Subroutine DELETE: not called CC=5 SCAR=34.0
619 0 my( $self, $idx ) = @_;
620  
621 # if the last one was removed, shrink until there is a
622 # defined value
623 0 ▶ if( $idx < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < 0) 0 0 0
624 0 $idx = $self->[ITEM_COUNT] + $idx;
625 }
626 0 my $del = $self->FETCH( $idx );
627 0 $self->STORE( $idx, undef );
628 0 ▶ if( $idx == $self->[ITEM_COUNT] - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == $self->[6] - 1) 0 0 0
629 0 $self->[ITEM_COUNT]--;
630 0 ▶ while( $self->[ITEM_COUNT] > 0 && ! defined( $self->FETCH( $self->[ITEM_COUNT] - 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6] > 0 and not defined $self->FETCH($self->[6] - 1)) 0 0 0
Condition0%0/3
$self->[6] > 0 and not defined $self->FETCH($self->[6] - 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[6] > 0 and not defined $self->FETCH($self->[6] - 1)
$self->[6] > 0 not defined $self->FETCH($self->[6] - 1)
Truth table0%0/3
A and not(B)
A= $self->[6] > 0B= not defined $self->FETCH($self->[6] - 1)
ABresult
0X0
100
111
631 0 $self->[ITEM_COUNT]--;
632 }
633  
634 }
635 0 $self->[DSTORE]->_dirty( $self->[DSTORE]->[WEAK]{$self->[ID]}, $self->[ID] );
636  
637 0 return $del;
638  
639 } #DELETE
640  
641 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=2 SCAR=17.9
642 0 my $self = shift;
643 0 ▶ if( $self->[ITEM_COUNT] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6] > 0) 0 0 0
644 0 $self->[ITEM_COUNT] = 0;
645 0 $self->[DATA] = [];
646 0 $self->[DSTORE]->_dirty( $self->[DSTORE]->[WEAK]{$self->[ID]}, $self->[ID] );
647 }
648 }
649 0 ▶sub PUSH {
Subroutine PUSH: not called CC=2 SCAR=17.9
650 0 my( $self, @vals ) = @_;
651 0 ▶ return unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 0 0 0
652 0 $self->SPLICE( $self->[ITEM_COUNT], 0, @vals );
653 }
654 0 ▶sub POP {
Subroutine POP: not called CC=1 SCAR=6.9
655 0 my $self = shift;
656 0 my $idx = $self->[ITEM_COUNT] - 1;
657 0 my $pop = $self->FETCH( $idx );
658 0 $self->STORE( $idx, undef );
659 0 $self->[ITEM_COUNT]--;
660 0 return $pop;
661 }
662 0 ▶sub SHIFT {
Subroutine SHIFT: not called CC=2 SCAR=17.9
663 0 my( $self ) = @_;
664 0 ▶ return undef unless $self->[ITEM_COUNT];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[6] 0 0 0
665 0 my( $ret ) = $self->SPLICE( 0, 1 );
666 0 $ret;
667 }
668  
669 0 ▶sub UNSHIFT {
Subroutine UNSHIFT: not called CC=2 SCAR=17.9
670 0 my( $self, @vals ) = @_;
671 0 ▶ return unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 0 0 0
672 0 return $self->SPLICE( 0, 0, @vals );
673 }
674  
675 0 ▶sub SPLICE {
Subroutine SPLICE: not called CC=23 SCAR=63.1
676 0 my( $self, $offset, $remove_length, @vals ) = @_;
677  
678 # if negative, the offset is from the end
679 0 ▶ if( $offset < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < 0) 0 0 0
680 0 $offset = $self->[ITEM_COUNT] + $offset;
681 }
682  
683 # if negative, remove everything except the abs($remove_length) at
684 # the end of the list
685 0 ▶ if( $remove_length < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length < 0) 0 0 0
686 0 $remove_length = ($self->[ITEM_COUNT] - $offset) + $remove_length;
687 }
688  
689 0 ▶ return undef unless $remove_length || @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless $remove_length or @vals 0 0 0
Condition0%0/3
$remove_length or @vals
l!l&&r!l&&!r
000
MC/DC0%0/2
$remove_length or @vals
$remove_length @vals
Truth table0%0/3
A or B
A= $remove_lengthB= @vals
ABresult
1X1
011
000
690  
691 # check for removal past end
692 0 ▶ if( $offset > ($self->[ITEM_COUNT] - 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > $self->[6] - 1) 0 0 0
693 0 $remove_length = 0;
694 0 $offset = $self->[ITEM_COUNT];
695 }
696 0 ▶ if( $remove_length > ($self->[ITEM_COUNT] - $offset) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length > $self->[6] - $offset) 0 0 0
697 0 $remove_length = $self->[ITEM_COUNT] - $offset;
698 }
699  
700 #
701 # embiggen to delta size if this would grow. Also use the
702 # calculated size as a check for correctness.
703 #
704 0 my $new_size = $self->[ITEM_COUNT];
705 0 $new_size -= $remove_length;
706 0 ▶ if( $new_size < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_size < 0) 0 0 0
707 0 $new_size = 0;
708 }
709 0 $new_size += @vals;
710  
711 0 ▶ if( $new_size > $self->[BLOCK_SIZE] * $self->[BLOCK_COUNT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_size > $self->[5] * $self->[4]) 0 0 0
712 0 $self->_embiggen( $new_size );
713 }
714  
715 0 my $BLOCK_COUNT = $self->[BLOCK_COUNT];
716 0 my $store = $self->[DSTORE];
717 0 my $BLOCK_SIZE = $self->[BLOCK_SIZE]; # embiggen may have changed this, so dont set this before the embiggen call
718  
719 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) 0 0 0
720 # lowest level, must fit in the size. The end recursion and easy case.
721 0 my $blocks = $self->[DATA];
722 0 my @raw_return = splice @$blocks, $offset, $remove_length, map { $store->_xform_in($_) } @vals;
723 0 my @ret = map { $store->_xform_out($_) } @raw_return;
724 0 $self->_storesize( $new_size );
725 0 $store->_dirty( $store->[WEAK]{$self->[ID]}, $self->[ID] );
726 0 return @ret;
727 }
728  
729 0 my( @removed );
730 0 ▶ while( @vals && $remove_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals and $remove_length) 0 0 0
Condition0%0/3
@vals and $remove_length
!ll&&!rl&&r
000
MC/DC0%0/2
@vals and $remove_length
@vals $remove_length
Truth table0%0/3
A and B
A= @valsB= $remove_length
ABresult
0X0
100
111
731 #
732 # harmony case. doesn't change the size. eats up vals and remove length
733 # until one is zero
734 #
735 0 push @removed, $self->FETCH( $offset );
736 0 $self->STORE( $offset++, shift @vals );
737 0 $remove_length--;
738 }
739  
740 0 ▶ if( $remove_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_length) 0 0 0
741 0 my $last_idx = $self->[ITEM_COUNT] - 1;
742  
743 0 ▶ for( my $idx=$offset; $idx<($offset+$remove_length); $idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < $offset + $remove_length) 0 0 0
744 0 push @removed, $self->FETCH( $idx );
745 }
746  
747 0 my $things_to_move = $self->[ITEM_COUNT] - ($offset+$remove_length);
748 0 my $to_idx = $offset;
749 0 my $from_idx = $to_idx + $remove_length;
750 0 for( 1..$things_to_move ) {
751 0 $self->STORE( $to_idx, $self->FETCH( $from_idx ) );
752 0 $to_idx++;
753 0 $from_idx++;
754 }
755 } # has things to remove
756  
757 0 ▶ if( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 0 0 0
758 #
759 # while there are any in the insert list, grab all the items in the next block if any
760 # and append to the insert list, then splice in the insert list to the beginning of
761 # the block. There still may be items in the insert list, so repeat until it is done
762 #
763  
764 0 my $block_idx = int( $offset / $BLOCK_SIZE );
765 0 my $block_off = $offset % $BLOCK_SIZE;
766  
767 0 ▶ while( @vals && ($self->[ITEM_COUNT] > $block_idx*$BLOCK_SIZE+$block_off) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals and $self->[6] > $block_idx * $BLOCK_SIZE + $block_off) 0 0 0
Condition0%0/3
@vals and $self->[6] > $block_idx * $BLOCK_SIZE + $block_off
!ll&&!rl&&r
000
MC/DC0%0/2
@vals and $self->[6] > $block_idx * $BLOCK_SIZE + $block_off
@vals $self->[6] > $block_idx * $BLOCK_SIZE + $block_off
Truth table0%0/3
A and B
A= @valsB= $self->[6] > $block_idx * $BLOCK_SIZE + $block_off
ABresult
0X0
100
111
768 0 my $block = $self->_getblock( $block_idx );
769 0 my $bubble_size = $block->FETCHSIZE - $block_off;
770 0 ▶ if( $bubble_size > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bubble_size > 0) 0 0 0
771 0 my @bubble = $block->SPLICE( $block_off, $bubble_size );
772 0 push @vals, @bubble;
773 }
774 0 ▶ my $can_insert = @vals > ($BLOCK_SIZE-$block_off) ? ($BLOCK_SIZE-$block_off) : @vals;
Branch: 1 branch
BranchTrueFalseTotal
@vals > $BLOCK_SIZE - $block_off ? : 0 0 0
775 0 ▶ if( $can_insert > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_insert > 0) 0 0 0
776 0 $block->SPLICE( $block_off, 0, splice( @vals, 0, $can_insert ) );
777 }
778 0 $block_idx++;
779 0 $block_off = 0;
780 }
781 0 ▶ while( @vals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals) 0 0 0
782 0 my $block = $self->_getblock( $block_idx );
783 0 my $remmy = $BLOCK_SIZE - $block_off;
784 0 ▶ if( $remmy > @vals ) { $remmy = @vals; }
Branch: 1 branch
BranchTrueFalseTotal
if ($remmy > @vals) 0 0 0
785  
786 0 $block->SPLICE( $block_off, $block->[ITEM_COUNT], splice( @vals, 0, $remmy) );
787 0 $block_idx++;
788 0 $block_off = 0;
789 }
790  
791 } # has vals
792  
793 0 $self->_storesize( $new_size );
794  
795 0 return @removed;
796  
797 } #SPLICE
798  
799 0 ▶sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=0.0
800 }
801  
802 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
803 0 my $self = shift;
804 0 delete $self->[DSTORE]->[WEAK]{$self->[ID]};
805 }
806  
807 # --------------------------------------------------------------------------------
808  
809 package Yote::Hash;
810  
811 ##################################################################################
812 # This module is used transparently by Yote to link hashes into its #
813 # graph structure. This is not meant to be called explicitly or modified. #
814 ##################################################################################
815  
816 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
817 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
818  
819 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
820 1 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
821  
822 1 ▶use Tie::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
823  
824 1 $Yote::Hash::SIZE = 977;
825  
826 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
827 1 ID => 0,
828 DATA => 1,
829 DSTORE => 2,
830 LEVEL => 3,
831 BUCKETS => 4,
832 SIZE => 5,
833 NEXT => 6,
834 1 };
835 0 ▶sub _freezedry {
Subroutine _freezedry: not called CC=4 SCAR=30.0
836 0 my $self = shift;
837 0 my $r = $self->[DATA];
838 join( "`",
839 $self->[LEVEL],
840 $self->[BUCKETS],
841 $self->[SIZE],
842 0 ▶ map { if( defined($_) ) { s/[\\]/\\\\/gs; s/`/\\`/gs; } defined($_) ? $_ : 'u' } $self->[LEVEL] ? @$r : %$r
Branch: 3 branches
BranchTrueFalseTotal
if (defined $_) 0 0 0
defined $_ ? : 0 0 0
$self->[3] ? : 0 0 0
843 );
844 }
845  
846 0 ▶sub _reconstitute {
Subroutine _reconstitute: not called CC=1 SCAR=6.9
847 0 my( $cls, $store, $id, $data ) = @_;
848 0 my $hash = {};
849 0 tie %$hash, $cls, $store, $id, @$data;
850 0 return $hash;
851 }
852  
853 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=8 SCAR=42.8
854 0 my( $class, $obj_store, $id, $level, $buckets, $size, @fetch_buckets ) = @_;
855 0 ▶ $level ||= 0;
Condition0%0/2
$level ||= 0
l!l
00
MC/DC0%0/1
$level ||= 0
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
856 0 ▶ $size ||= 0;
Condition0%0/2
$size ||= 0
l!l
00
MC/DC0%0/1
$size ||= 0
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
857 0 ▶ $buckets ||= $Yote::Hash::SIZE;
Condition0%0/3
$buckets ||= $Yote::Hash::SIZE
l!l&&r!l&&!r
000
MC/DC0%0/2
$buckets ||= $Yote::Hash::SIZE
$buckets $Yote::Hash::SIZE
Truth table0%0/3
A ||= B
A= $bucketsB= $Yote::Hash::SIZE
ABresult
1X1
011
000
858 0 my $hash;
859 0 ▶ if( $level == 0 && $size > $buckets ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0 and $size > $buckets) { } 0 0 0
Condition0%0/3
$level == 0 and $size > $buckets
!ll&&!rl&&r
000
MC/DC0%0/2
$level == 0 and $size > $buckets
$level == 0 $size > $buckets
Truth table0%0/3
A and B
A= $level == 0B= $size > $buckets
ABresult
0X0
100
111
860 # this case is where a hash is initialized the first time with more items than buckets.
861 0 $hash = bless [ $id, {}, $obj_store, 0, $buckets, 0, [undef,undef] ], $class;
862 0 ▶ while( @fetch_buckets ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fetch_buckets) 0 0 0
863 0 my $k = shift @fetch_buckets;
864 0 my $v = shift @fetch_buckets;
865 0 $hash->STORE( $k, $obj_store->_xform_out($v) );
866 }
867 }
868 else {
869 0 ▶ $hash = bless [ $id, $level ? [@fetch_buckets] : {@fetch_buckets}, $obj_store, $level, $buckets, $size, [undef,undef] ], $class;
Branch: 1 branch
BranchTrueFalseTotal
$level ? : 0 0 0
870 }
871  
872 0 $hash;
873 }
874  
875 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=2 SCAR=17.9
876 0 my $self = shift;
877 0 ▶ if( $self->[SIZE] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[5] > 0) 0 0 0
878 0 $self->[SIZE] = 0;
879 0 my $store = $self->[DSTORE];
880 0 $store->_dirty( $store->[Yote::ObjStore::WEAK]{$self->[ID]}, $self->[ID] );
881 0 %{$self->[DATA]} = ();
882 }
883 }
884  
885 0 ▶sub DELETE {
Subroutine DELETE: not called CC=4 SCAR=30.0
886 0 my( $self, $key ) = @_;
887  
888 0 ▶ return undef unless $self->EXISTS( $key );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->EXISTS($key) 0 0 0
889  
890 0 $self->[SIZE]--;
891  
892 0 my $data = $self->[DATA];
893 0 my $store = $self->[DSTORE];
894  
895 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) { } 0 0 0
896 0 $store->_dirty( $store->[Yote::ObjStore::WEAK]{$self->[ID]}, $self->[ID] );
897 0 return $store->_xform_out( delete $data->{$key} );
898 } else {
899 0 my $hval = 0;
900 0 foreach (split //,$key) {
901 0 $hval = $hval*33 - ord($_);
902 }
903 0 $hval = $hval % $self->[BUCKETS];
904 0 return $self->[DSTORE]->_fetch( $data->[$hval] )->DELETE( $key );
905 }
906 0 return undef;
907 } #DELETE
908  
909  
910 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=5 SCAR=34.0
911 0 my( $self, $key ) = @_;
912  
913 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) { } 0 0 0
914 0 ▶ return exists $self->[DATA]{$key} && $self->[DATA]{$key} ne 'u';
Condition0%0/3
exists $self->[1]{$key} && $self->[1]{$key} ne 'u'
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->[1]{$key} && $self->[1]{$key} ne 'u'
exists $self->[1]{$key} $self->[1]{$key} ne 'u'
Truth table0%0/3
A && B
A= exists $self->[1]{$key}B= $self->[1]{$key} ne 'u'
ABresult
0X0
100
111
915 } else {
916 0 my $data = $self->[DATA];
917 0 my $hval = 0;
918 0 foreach (split //,$key) {
919 0 $hval = $hval*33 - ord($_);
920 }
921 0 $hval = $hval % $self->[BUCKETS];
922 0 my $hash_id = $data->[$hval];
923 0 ▶ if( $hash_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_id > 0) 0 0 0
924 0 my $hash = $self->[DSTORE]->_fetch( $hash_id );
925 0 my $tied = tied %$hash;
926 0 return $tied->EXISTS( $key );
927 }
928  
929 }
930 0 return 0;
931 } #EXISTS
932  
933 0 ▶sub FETCH {
Subroutine FETCH: not called CC=4 SCAR=30.0
934 0 my( $self, $key ) = @_;
935 0 my $data = $self->[DATA];
936  
937 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) { } 0 0 0
938 0 return $self->[DSTORE]->_xform_out( $data->{$key} );
939 } else {
940 0 my $hval = 0;
941 0 foreach (split //,$key) {
942 0 $hval = $hval*33 - ord($_);
943 }
944 0 $hval = $hval % $self->[BUCKETS];
945 0 my $hash_id = $data->[$hval];
946 0 ▶ if( $hash_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_id > 0) 0 0 0
947 0 my $hash = $self->[DSTORE]->_fetch( $hash_id );
948 0 my $tied = tied %$hash;
949 0 return $tied->FETCH( $key );
950 }
951 }
952 0 return undef;
953 } #FETCH
954  
955 0 ▶sub _SHOW {
Subroutine _SHOW: not called CC=3 SCAR=24.8
956 0 my( $self, $lvl ) = @_;
957 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) { } 0 0 0
958 0 print STDERR (" " x $lvl ) . "($self->[ID]) : BASE SHOW : " . join( ',', keys %{$self->[DATA]} ) . "\n";
959 } else {
960 0 my( @ids ) = @{$self->[DATA]};
961 0 print STDERR (" " x $lvl ) . "($self->[ID]) : subhashes : " . join( ',', map { "($_)" } @ids ) . "\n";
962 0 for my $id (grep { $_ ne 'u' } @ids) {
963 0 my $h = $self->[DSTORE]->_fetch( $id );
964 0 tied( %$h )->SHOW( $lvl + 1 );;
965 }
966 }
967 }
968  
969 0 ▶sub STORE {
Subroutine STORE: not called CC=9 SCAR=45.0
970 0 my( $self, $key, $val ) = @_;
971  
972 0 my $data = $self->[DATA];
973  
974 #
975 # EMBIGGEN TEST
976 #
977 0 my $newkey = ! $self->EXISTS( $key );
978 0 ▶ if( $newkey ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newkey) 0 0 0
979 0 $self->[SIZE]++;
980 }
981  
982 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) { } 0 0 0
983 0 $data->{$key} = $self->[DSTORE]->_xform_in( $val );
984  
985 0 ▶ if( $self->[SIZE] > $self->[BUCKETS] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[5] > $self->[4]) 0 0 0
986  
987 # do the thing converting this to a deeper level
988 0 $self->[LEVEL] = 1;
989 0 my $store = $self->[DSTORE];
990 0 my( @newhash, @newids );
991  
992 0 for my $key (keys %$data) {
993 0 my $hval = 0;
994 0 foreach (split //,$key) {
995 0 $hval = $hval*33 - ord($_);
996 }
997 0 $hval = $hval % $self->[BUCKETS];
998  
999 0 my $hash = $newhash[$hval];
1000 0 ▶ if( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) { } 0 0 0
1001 0 my $tied = tied %$hash;
1002 0 $tied->STORE( $key, $store->_xform_out($data->{$key}) );
1003 } else {
1004 0 $hash = {};
1005 0 my $hash_id = $store->_new_id;
1006 0 tie %$hash, 'Yote::Hash', $store, $hash_id, 0, $self->[BUCKETS]+1, 1, $key, $data->{$key};
1007 0 $store->_store_weak( $hash_id, $hash );
1008 0 $store->_dirty( $store->[Yote::ObjStore::WEAK]{$hash_id}, $hash_id );
1009  
1010 0 $newhash[$hval] = $hash;
1011 0 $newids[$hval] = $hash_id;
1012 }
1013  
1014 }
1015 0 $self->[DATA] = \@newids;
1016 0 $data = $self->[DATA];
1017 # here is the problem. this isnt in weak yet!
1018 # this is a weak reference problem and the problem is at NEXTKEY with
1019 # LEVEL 0 hashes that are loaded from LEVEL 1 hashes that are loaded from
1020 # LEVEL 2 hashes. The level 1 hash is loaded and dumped as needed, not keeping
1021 # the ephermal info (or is that sort of chained..hmm)
1022 0 $store->_dirty( $store->[Yote::ObjStore::WEAK]{$self->[ID]}, $self->[ID] );
1023  
1024 } # EMBIGGEN CHECK
1025  
1026 } else {
1027 0 my $store = $self->[DSTORE];
1028 0 my $hval = 0;
1029 0 foreach (split //,$key) {
1030 0 $hval = $hval*33 - ord($_);
1031 }
1032 0 $hval = $hval % $self->[BUCKETS];
1033 0 my $hash_id = $data->[$hval];
1034 0 my $hash;
1035 0 ▶ if( $hash_id > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash_id > 0) { } 0 0 0
1036 0 $hash = $store->_fetch( $hash_id );
1037 0 my $tied = tied %$hash;
1038 0 $tied->STORE( $key, $val );
1039 } else {
1040 0 $hash = {};
1041 0 $hash_id = $store->_new_id;
1042 0 tie %$hash, 'Yote::Hash', $store, $hash_id, 0, $self->[BUCKETS]+1, 1, $key, $store->_xform_in( $val );
1043 0 $store->_store_weak( $hash_id, $hash );
1044 0 $store->_dirty( $store->[Yote::ObjStore::WEAK]{$hash_id}, $hash_id );
1045 0 $data->[$hval] = $hash_id;
1046 }
1047 }
1048  
1049 } #STORE
1050  
1051 0 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: not called CC=3 SCAR=24.8
1052 0 my $self = shift;
1053  
1054 0 my $data = $self->[DATA];
1055 0 ▶ if( $self->[LEVEL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[3] == 0) 0 0 0
1056 0 my $a = scalar keys %$data; #reset
1057 0 my( $k, $val ) = each %$data;
1058 0 ▶ return wantarray ? ( $k => $self->[DSTORE]->_xform_out( $val ) ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1059 }
1060 0 $self->[NEXT] = [undef,undef];
1061 0 return $self->NEXTKEY;
1062 }
1063  
1064 0 ▶sub NEXTKEY {
Subroutine NEXTKEY: not called CC=12 SCAR=50.5
1065 0 my $self = shift;
1066 0 my $data = $self->[DATA];
1067 0 my $lvl = $self->[LEVEL];
1068 0 ▶ if( $lvl == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl == 0) { } 0 0 0
1069 0 my( $k, $val ) = each %$data;
1070 0 ▶ return wantarray ? ( $k => $self->[DSTORE]->_xform_out($val) ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1071 }
1072 else {
1073 0 my $store = $self->[DSTORE];
1074  
1075 0 my $at_start = ! defined( $self->[NEXT][0] );
1076  
1077 0 ▶ if( $at_start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at_start) 0 0 0
1078 0 $self->[NEXT][0] = 0;
1079 0 $self->[NEXT][1] = undef;
1080 }
1081  
1082 0 my $hash = $self->[NEXT][1];
1083 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
1084 0 ▶ unless( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash) 0 0 0
1085 0 my $hash_id = $data->[$self->[NEXT][0]];
1086 0 ▶ $hash = $store->_fetch( $hash_id ) if $hash_id > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_id > 1 0 0 0
1087 }
1088  
1089 0 ▶ if( $hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) 0 0 0
1090 0 my $tied = tied( %$hash );
1091 0 ▶ my( $k, $v ) = $at_start ? $tied->FIRSTKEY : $tied->NEXTKEY;
Branch: 1 branch
BranchTrueFalseTotal
$at_start ? : 0 0 0
1092 0 ▶ if( defined( $k ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 0 0 0
1093 0 $self->[NEXT][1] = $hash; #to keep the weak reference
1094 0 ▶ return wantarray ? ( $k => $v ) : $k;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1095 }
1096 }
1097  
1098 0 $self->[NEXT][1] = undef;
1099 0 $self->[NEXT][0]++;
1100  
1101 0 ▶ if( $self->[NEXT][0] > $#$data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6][0] > $data->$#*) 0 0 0
1102 0 $self->[NEXT][0] = undef;
1103 0 return undef;
1104 }
1105 # recursion case, the next bucket has been incremented
1106 0 return $self->NEXTKEY;
1107 }
1108  
1109 # really should be impossible to reach this case.
1110 0 die "Impossible case";
1111 0 $self->[NEXT] = [undef,undef];
1112 0 return undef;
1113  
1114 } #NEXTKEY
1115  
1116 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
1117 0 my $self = shift;
1118  
1119 #remove all WEAK_REFS to the buckets
1120 0 undef $self->[DATA];
1121  
1122 0 delete $self->[DSTORE]->[Yote::ObjStore::WEAK]{$self->[ID]};
1123 }
1124  
1125 # --------------------------------------------------------------------------------
1126  
1127 package Yote::Obj;
1128  
1129 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1130 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1131 1 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1132 1 ▶no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1133  
1134 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
1135 1 ID => 0,
1136 DATA => 1,
1137 DSTORE => 2,
1138 1 };
1139  
1140 #
1141 # The string version of the yote object is simply its id. This allows
1142 # object ids to easily be stored as hash keys.
1143 #
1144 use overload
1145 0 ▶ '""' => sub { shift->[ID] }, # for hash keys
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine __ANON__: not called CC=1 SCAR=6.9
1146 0 ▶ eq => sub { ref($_[1]) && $_[1]->[ID] == $_[0]->[ID] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][0] == $_[0][0] 0 0 0
1147 0 ▶ ne => sub { ! ref($_[1]) || $_[1]->[ID] != $_[0]->[ID] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] or $_[1][0] != $_[0][0] 0 0 0
1148 0 ▶ '==' => sub { ref($_[1]) && $_[1]->[ID] == $_[0]->[ID] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and $_[1][0] == $_[0][0] 0 0 0
1149 0 ▶ '!=' => sub { ! ref($_[1]) || $_[1]->[ID] != $_[0]->[ID] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] or $_[1][0] != $_[0][0] 0 0 0
1150 1 fallback => 1;
1151  
1152 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
1153 0 shift->[ID];
1154 }
1155  
1156 0 ▶sub set {
Subroutine set: not called CC=3 SCAR=24.8
1157 0 my( $self, $fld, $val ) = @_;
1158  
1159 0 my $inval = $self->[DSTORE]->_xform_in( $val );
1160 0 ▶ if( $self->[DATA]{$fld} ne $inval ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1]{$fld} ne $inval) 0 0 0
1161 0 $self->[DSTORE]->_dirty( $self, $self->[ID] );
1162 }
1163  
1164 0 ▶ unless( defined $inval ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inval) 0 0 0
1165 0 delete $self->[DATA]{$fld};
1166 0 return;
1167 }
1168 0 $self->[DATA]{$fld} = $inval;
1169 0 return $self->[DSTORE]->_xform_out( $self->[DATA]{$fld} );
1170 } #set
1171  
1172  
1173 0 ▶sub get {
Subroutine get: not called CC=5 SCAR=34.0
1174 0 my( $self, $fld, $default ) = @_;
1175  
1176 0 my $cur = $self->[DATA]{$fld};
1177 0 my $store = $self->[DSTORE];
1178 0 ▶ if( ( ! defined( $cur ) || $cur eq 'u' ) && defined( $default ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($cur) || $cur eq "u" and defined $default) 0 0 0
Condition0%0/6
!defined($cur) || $cur eq "u" and defined $default
!ll&&!rl&&r
000
not defined $cur or $cur eq "u"
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($cur) || $cur eq "u" and defined $default
not defined $cur $cur eq "u" defined $default
Truth table0%0/5
not(A) or B and C
A= not defined $curB= $cur eq "u"C= defined $default
ABCresult
00X0
1X00
0100
1X11
0111
1179 0 ▶ if( ref( $default ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $default) 0 0 0
1180 # this must be done to make sure the reference is saved
1181 # for cases where the reference has not yet made it to the store of things to save
1182 0 $store->_dirty( $store->_get_id( $default ) );
1183 }
1184 0 $store->_dirty( $self, $self->[ID] );
1185 0 $self->[DATA]{$fld} = $store->_xform_in( $default );
1186 }
1187 0 return $store->_xform_out( $self->[DATA]{$fld} );
1188 } #get
1189  
1190  
1191 0 ▶sub store {
Subroutine store: not called CC=1 SCAR=6.9
1192 0 return shift->[DSTORE];
1193 }
1194  
1195 # -----------------------
1196 #
1197 # Public Methods
1198 # -----------------------
1199 #
1200 # Defines get_foo, set_foo, add_to_foolist, remove_from_foolist
1201 #
1202 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=7 SCAR=33.2
1203 0 my( $s, $arg ) = @_;
1204 0 my $func = our $AUTOLOAD;
1205 0 ▶ if( $func =~/:add_to_(.*)/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($func =~ /:add_to_(.*)/) { } 0 0 0
elsif ($func =~ /:add_once_to_(.*)/) { } 0 0 0
elsif ($func =~ /:remove_from_(.*)/) { } 0 0 0
elsif ($func =~ /:remove_all_from_(.*)/) { } 0 0 0
elsif ($func =~ /:set_(.*)/) { } 0 0 0
elsif ($func =~ /:get_(.*)/) { } 0 0 0
1206 0 my( $fld ) = $1;
1207 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1208 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1209 0 my( $self, @vals ) = @_;
1210 0 my $get = "get_$fld";
1211 0 my $arry = $self->$get([]); # init array if need be
1212 0 push( @$arry, @vals );
1213 0 };
1214 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1215 0 goto &$AUTOLOAD;
1216 } #add_to
1217 elsif( $func =~/:add_once_to_(.*)/ ) {
1218 0 my( $fld ) = $1;
1219 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1220 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1221 0 my( $self, @vals ) = @_;
1222 0 my $get = "get_$fld";
1223 0 my $arry = $self->$get([]); # init array if need be
1224 0 for my $val ( @vals ) {
1225 0 ▶ unless( grep { $val eq $_ } @$arry ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$val eq $_;} @$arry) 0 0 0
1226 0 push @$arry, $val;
1227 }
1228 }
1229 0 };
1230 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1231 0 goto &$AUTOLOAD;
1232 } #add_once_to
1233 elsif( $func =~ /:remove_from_(.*)/ ) { #removes the first instance of the target thing from the list
1234 0 my $fld = $1;
1235 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1236 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1237 0 my( $self, @vals ) = @_;
1238 0 my $get = "get_$fld";
1239 0 my $arry = $self->$get([]); # init array if need be
1240 0 for my $val (@vals ) {
1241 0 for my $i (0..$#$arry) {
1242 0 ▶ if( $arry->[$i] eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arry->[$i] eq $val) 0 0 0
1243 0 splice @$arry, $i, 1;
1244 0 last;
1245 }
1246 }
1247 }
1248 0 };
1249 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1250 0 goto &$AUTOLOAD;
1251 }
1252 elsif( $func =~ /:remove_all_from_(.*)/ ) { #removes the first instance of the target thing from the list
1253 0 my $fld = $1;
1254 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1255 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
1256 0 my( $self, @vals ) = @_;
1257 0 my $get = "get_$fld";
1258 0 my $arry = $self->$get([]); # init array if need be
1259 0 for my $val (@vals) {
1260 0 my $count = grep { $_ eq $val } @$arry;
1261 0 ▶ while( $count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 0 0 0
1262 0 for my $i (0..$#$arry) {
1263 0 ▶ if( $arry->[$i] eq $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arry->[$i] eq $val) 0 0 0
1264 0 --$count;
1265 0 splice @$arry, $i, 1;
1266 0 ▶ last unless $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
1267 }
1268 }
1269 }
1270 }
1271 0 };
1272 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1273 0 goto &$AUTOLOAD;
1274 }
1275 elsif ( $func =~ /:set_(.*)/ ) {
1276 0 my $fld = $1;
1277 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1278 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1279 0 my( $self, $val ) = @_;
1280 0 my $store = $self->[DSTORE];
1281 0 my $inval = $store->_xform_in( $val );
1282 0 ▶ $store->_dirty( $self, $self->[ID] ) if $self->[DATA]{$fld} ne $inval;
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1]{$fld} ne $inval 0 0 0
1283 0 ▶ unless( defined $inval ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inval) 0 0 0
1284 0 delete $self->[DATA]{$fld};
1285 0 return;
1286 }
1287 0 $self->[DATA]{$fld} = $inval;
1288 0 return $store->_xform_out( $self->[DATA]{$fld} );
1289 0 };
1290 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1291 0 goto &$AUTOLOAD;
1292 }
1293 elsif( $func =~ /:get_(.*)/ ) {
1294 0 my $fld = $1;
1295 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1296 0 ▶ *$AUTOLOAD = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
1297 0 my( $self, $init_val ) = @_;
1298 0 my $store = $self->[DSTORE];
1299 0 ▶ if( ( ! defined( $self->[DATA]{$fld} ) || $self->[DATA]{$fld} eq 'u' ) && defined($init_val) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($self->[1]{$fld}) || $self->[1]{$fld} eq "u" and defined $init_val) 0 0 0
Condition0%0/6
!defined($self->[1]{$fld}) || $self->[1]{$fld} eq "u" and defined $init_val
!ll&&!rl&&r
000
not defined $self->[1]{$fld} or $self->[1]{$fld} eq "u"
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($self->[1]{$fld}) || $self->[1]{$fld} eq "u" and defined $init_val
not defined $self->[1]{$fld} $self->[1]{$fld} eq "u" defined $init_val
Truth table0%0/5
not(A) or B and C
A= not defined $self->[1]{$fld}B= $self->[1]{$fld} eq "u"C= defined $init_val
ABCresult
00X0
1X00
0100
1X11
0111
1300 0 ▶ if( ref( $init_val ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $init_val) 0 0 0
1301 # this must be done to make sure the reference is saved for cases where the reference has not yet made it to the store of things to save
1302 0 my $ref_id = $store->_get_id( $init_val );
1303 0 $store->_dirty( $init_val, $ref_id );
1304 }
1305 0 $store->_dirty( $self, $self->[ID] );
1306 0 $self->[DATA]{$fld} = $store->_xform_in( $init_val );
1307 }
1308 0 return $store->_xform_out( $self->[DATA]{$fld} );
1309 0 };
1310 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1311 0 goto &$AUTOLOAD;
1312 }
1313 else {
1314 0 die "Unknown Yote::Obj function '$func'";
1315 }
1316  
1317 } #AUTOLOAD
1318  
1319 # -----------------------
1320 #
1321 # Overridable Methods
1322 # -----------------------
1323  
1324 =head2 _init
1325  
1326 This is called the first time an object is created. It is not
1327 called when the object is loaded from storage. This can be used
1328 to set up defaults. This is meant to be overridden.
1329  
1330 =cut
1331 0 ▶sub _init {}
Subroutine _init: not called CC=1 SCAR=0.0
1332  
1333 =head2 _init
1334  
1335 This is called each time the object is loaded from the data store.
1336 This is meant to be overridden.
1337  
1338 =cut
1339 0 ▶sub _load {}
Subroutine _load: not called CC=1 SCAR=0.0
1340  
1341  
1342  
1343 # -----------------------
1344 #
1345 # Private Methods
1346 #
1347 # -----------------------
1348 0 ▶sub _freezedry {
Subroutine _freezedry: not called CC=3 SCAR=24.8
1349 0 my $self = shift;
1350 0 ▶ join( "`", map { if( defined($_) ) { s/[\\]/\\\\/gs; s/`/\\`/gs; } defined($_) ? $_ : 'u' } %{$self->[DATA]} );
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_) 0 0 0
defined $_ ? : 0 0 0
1351 }
1352  
1353 0 ▶sub _reconstitute {
Subroutine _reconstitute: not called CC=1 SCAR=6.9
1354 0 my( $cls, $store, $id, $data ) = @_;
1355 0 my $obj = [$id,{@$data},$store];
1356 0 bless $obj, $cls;
1357 0 $obj->_load;
1358 0 $obj;
1359 }
1360  
1361 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
1362 0 my $self = shift;
1363  
1364 0 delete $self->[DSTORE][Yote::ObjStore::WEAK]{$self->[ID]};
1365 }
1366  
1367 1 1;
1368  
1369 __END__
↑ Summary