blib/lib/Data/Shared/Composite.pm

filter: Statementstmt 94.8% 681 / 718 Branchbran 80.3% 461 / 574 Conditioncond 68.9% 253 / 367 MC/DCmcdc 48.8% 102 / 209 Subroutinesub 98.7% 77 / 78 Podpod 0.0% 0 / 15 totaltotal 80.2% 1574 / 1961 CC 424 SCAR 28.6
CC
424
Cov
84%
parse_node
59.2
__ANON__
48.4
_verb_at_child
31.2
CRAP 17.5
« blib/lib/Data/Shared/Manifest.pm ↑ Summary blib/lib/Data/Shared/Registry.pm »
1 package Data::Shared::Composite;
2 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use Fcntl qw(:flock O_RDWR O_APPEND O_CREAT);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 39 our $VERSION = '0.02';
10  
11 39 our @CARP_NOT = qw(Data::Shared Data::Shared::Manifest Data::Shared::Storage
12 Data::Shared::Composite);
13  
14 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
15  
16 39 my %PARENT_OK = map { $_ => 1 } qw(hashmap sortedset kdtree graph);
17  
18 157 ▶sub _refuse_unknown_keys {
Subroutine _refuse_unknown_keys: called CC=3 SCAR=11.0
19 157 my ($hash, $what, @allowed) = @_;
20 157 my %ok = map { $_ => 1 } @allowed;
21 157 my @bad = sort grep { !$ok{$_} } keys %$hash;
22 157 ▶ return unless @bad;
Branch: 1 branch
BranchTrueFalseTotal
unless @bad 154 3 157
23 3 ▶ Carp::croak("Data::Shared: unknown composite $what"
Branch: 1 branch
BranchTrueFalseTotal
@bad == 1 ? : 3 0 3
24 . (@bad == 1 ? " '$bad[0]'" : "s '" . join("', '", @bad) . "'")
25 . '; expected ' . join(', ', @allowed));
26 }
27  
28 4857 ▶sub parse_node {
Subroutine parse_node: called CC=35 SCAR=40.8
Pod undocumented
29 4857 my ($node) = @_;
30 4857 ▶ if (!ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 0 4857 4857
31 0 ▶ Carp::croak("Data::Shared: composite spec must be a string, arrayref, or hashref") unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
32 0 my $resolved = Data::Shared::Registry::resolve_spec($node);
33 0 ▶ Carp::croak("Data::Shared: unknown mount spec '$node'") unless $resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolved 0 0 0
34 0 return { spec => $node, resolved => $resolved, args => [], child => undef,
35 max_children => 10_000, cache_size => 32 };
36 }
37 4857 ▶ if (ref $node eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "HASH") 92 4765 4857
38 92 ▶ my $spec = $node->{spec} // $node->{type} // $node->{class} // $node->{key};
Condition33%3/9
(($node->{"spec"} // $node->{"type"}) // $node->{"class"}) // $node->{"key"}
l!l&&r!l&&!r
9200
($node->{"spec"} // $node->{"type"}) // $node->{"class"}
l!l&&r!l&&!r
9200
$node->{"spec"} // $node->{"type"}
l!l&&r!l&&!r
9200
MC/DC0%0/4
(($node->{"spec"} // $node->{"type"}) // $node->{"class"}) // $node->{"key"}
$node->{"spec"} $node->{"type"} $node->{"class"} $node->{"key"}
Truth table20%1/5
A // B // C // D
A= $node->{"spec"}B= $node->{"type"}C= $node->{"class"}D= $node->{"key"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
39 92 ▶ Carp::croak("Data::Shared: composite hashref spec needs spec/type/class/key") unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 0 92 92
40 92 _refuse_unknown_keys($node, 'spec key',
41 qw(spec type class key args ctor child max_children cache_size));
42 91 my $resolved = Data::Shared::Registry::resolve_spec($spec);
43 91 ▶ Carp::croak("Data::Shared: unknown mount spec '$spec'") unless $resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolved 0 91 91
44 Carp::croak('Data::Shared: constructor args must be an ARRAY reference')
45 91 ▶ if exists $node->{args} && ref $node->{args} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $node->{"args"} and ref $node->{"args"} ne "ARRAY" 0 91 91
Condition33%1/3
exists $node->{"args"} and ref $node->{"args"} ne "ARRAY"
!ll&&!rl&&r
0910
MC/DC0%0/2
exists $node->{"args"} and ref $node->{"args"} ne "ARRAY"
exists $node->{"args"} ref $node->{"args"} ne "ARRAY"
Truth table33%1/3
A and B
A= exists $node->{"args"}B= ref $node->{"args"} ne "ARRAY"
ABresult
0X0
100
111
46 Carp::croak('Data::Shared: invalid constructor name')
47 91 ▶ if exists $node->{ctor} && (!defined $node->{ctor} || ref $node->{ctor} || $node->{ctor} !~ /\A[A-Za-z_]\w*\z/);
Branch: 1 branch
BranchTrueFalseTotal
if exists $node->{"ctor"} and !defined($node->{"ctor"}) || ref $node->{"ctor"} || !($node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/) 0 91 91
Condition44%4/9
exists $node->{"ctor"} and !defined($node->{"ctor"}) || ref $node->{"ctor"} || !($node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/)
!ll&&!rl&&r
9010
not defined $node->{"ctor"} or ref $node->{"ctor"} or not $node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
l!l&&r!l&&!r
001
not defined $node->{"ctor"} or ref $node->{"ctor"}
l!l&&r!l&&!r
001
MC/DC0%0/4
exists $node->{"ctor"} and !defined($node->{"ctor"}) || ref $node->{"ctor"} || !($node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/)
exists $node->{"ctor"} not defined $node->{"ctor"} ref $node->{"ctor"} not $node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
Truth table40%2/5
A and not(B) or C or not(D)
A= exists $node->{"ctor"}B= not defined $node->{"ctor"}C= ref $node->{"ctor"}D= not $node->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
48 # ctor_named marks a caller override; the registry sets its own ctor for some families.
49 $resolved = { %$resolved, ctor => $node->{ctor}, ctor_named => 1 }
50 91 ▶ if defined $node->{ctor};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"ctor"} 1 90 91
51 my $out = { spec => $spec, resolved => $resolved,
52 91 ▶ args => $node->{args} ? [ @{ $node->{args} } ] : [],
Condition100%4/4
$node->{"max_children"} // 10000
l!l
3259
$node->{"cache_size"} // 32
l!l
3952
MC/DC100%1/1
$node->{"max_children"} // 10000
$node->{"max_children"}
MC/DC100%1/1
$node->{"cache_size"} // 32
$node->{"cache_size"}
Truth table100%2/2
A
A= $node->{"max_children"}
Aresult
11
00
Truth table100%2/2
A
A= $node->{"cache_size"}
Aresult
11
00
53 child => undef,
54 max_children => $node->{max_children} // 10_000,
55 91 ▶ cache_size => $node->{cache_size} // 32 };
Branch: 1 branch
BranchTrueFalseTotal
$node->{'args'} ? : 91 0 91
56 91 ▶ $out->{child} = parse_node($node->{child}) if defined $node->{child};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"child"} 48 43 91
57 91 _validate_node($out);
58 91 return $out;
59 }
60 4765 ▶ if (ref $node eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "ARRAY") 4765 0 4765
61 4765 my @elems = @$node;
62 4765 ▶ Carp::croak("Data::Shared: composite arrayref spec is empty") unless @elems;
Branch: 1 branch
BranchTrueFalseTotal
unless @elems 0 4765 4765
63 4765 my $spec = shift @elems;
64 4765 ▶ Carp::croak("Data::Shared: composite arrayref spec must start with a spec string") if ref $spec;
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec 0 4765 4765
65 4765 my %opts;
66 4765 ▶ if (@elems >= 2 && ref $elems[-1] eq 'HASH' && ref $elems[-2] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@elems >= 2 and ref $elems[-1] eq "HASH" and ref $elems[-2] eq "ARRAY") 65 4700 4765
Condition100%6/6
@elems >= 2 and ref $elems[-1] eq "HASH" and ref $elems[-2] eq "ARRAY"
!ll&&!rl&&r
4692865
@elems >= 2 and ref $elems[-1] eq "HASH"
!ll&&!rl&&r
2340235273
MC/DC100%3/3
@elems >= 2 and ref $elems[-1] eq "HASH" and ref $elems[-2] eq "ARRAY"
@elems >= 2 ref $elems[-1] eq "HASH" ref $elems[-2] eq "ARRAY"
Truth table100%4/4
A and B and C
A= @elems >= 2B= ref $elems[-1] eq "HASH"C= ref $elems[-2] eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
67 # A trailing child array and options hash must not fall through to constructor args.
68 65 _refuse_unknown_keys($elems[-1], 'option', qw(max_children cache_size));
69 63 %opts = %{ pop @elems };
70 }
71 4763 ▶ if (@elems && ref $elems[-1] eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (@elems and ref $elems[-1] eq "HASH" and grep {exists $elems[-1]{$_};} "spec", "type", "class", "key", "child") 1 4762 4763
Condition83%5/6
@elems and ref $elems[-1] eq "HASH" and grep {exists $elems[-1]{$_};} "spec", "type", "class", "key", "child"
!ll&&!rl&&r
4745171
@elems and ref $elems[-1] eq "HASH"
!ll&&!rl&&r
0474518
MC/DC66%2/3
@elems and ref $elems[-1] eq "HASH" and grep {exists $elems[-1]{$_};} "spec", "type", "class", "key", "child"
@elems ref $elems[-1] eq "HASH" grep {exists $elems[-1]{$_};} "spec", "type", "class", "key", "child"
Truth table75%3/4
A and B and C
A= @elemsB= ref $elems[-1] eq "HASH"C= grep {exists $elems[-1]{$_};} "spec", "type", "class", "key", "child"
ABCresult
0XX0
10X0
1100
1111
72 90 && grep { exists $elems[-1]{$_} } qw(spec type class key child)) {
73 1 Carp::croak('Data::Shared: a child spec in an arrayref composite spec must be'
74 . ' an arrayref; a trailing hashref is read as a constructor argument');
75 }
76 4762 my $child;
77 4762 ▶ if (@elems && ref $elems[-1] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@elems and ref $elems[-1] eq "ARRAY") 2388 2374 4762
Condition66%2/3
@elems and ref $elems[-1] eq "ARRAY"
!ll&&!rl&&r
023742388
MC/DC50%1/2
@elems and ref $elems[-1] eq "ARRAY"
@elems ref $elems[-1] eq "ARRAY"
Truth table66%2/3
A and B
A= @elemsB= ref $elems[-1] eq "ARRAY"
ABresult
0X0
100
111
78 2388 $child = parse_node(pop @elems);
79 }
80 4758 my $resolved = Data::Shared::Registry::resolve_spec($spec);
81 4758 ▶ Carp::croak("Data::Shared: unknown mount spec '$spec'") unless $resolved;
Branch: 1 branch
BranchTrueFalseTotal
unless $resolved 2 4756 4758
82 my $out = { spec => $spec, resolved => $resolved, args => \@elems, child => $child,
83 max_children => $opts{max_children} // 10_000,
84 4756 ▶ cache_size => $opts{cache_size} // 32 };
Condition100%4/4
$opts{"max_children"} // 10000
l!l
574699
$opts{"cache_size"} // 32
l!l
74749
MC/DC100%1/1
$opts{"max_children"} // 10000
$opts{"max_children"}
MC/DC100%1/1
$opts{"cache_size"} // 32
$opts{"cache_size"}
Truth table100%2/2
A
A= $opts{"max_children"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"cache_size"}
Aresult
11
00
85 4756 _validate_node($out);
86 4736 return $out;
87 }
88 0 Carp::croak("Data::Shared: composite spec must be a string, arrayref, or hashref");
89 }
90  
91 # A leading undef or ':file' is the file placeholder, not an argument; every reader of args must strip it.
92 15191 ▶sub _strip_placeholder {
Subroutine _strip_placeholder: called CC=3 SCAR=11.0
93 15191 my ($args) = @_;
94 15191 my @a = @$args;
95 15191 ▶ my $placeholder = sub { @a && (!defined $a[0] || (!ref $a[0] && $a[0] eq ':file'))};
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
@a and !defined($a[0]) || !ref($a[0]) && $a[0] eq ":file" 30380 2 30382
Condition100%9/9
@a && (!defined($a[0]) || !ref($a[0]) && $a[0] eq ':file')
!ll&&!rl&&r
23034436
not defined $a[0] or not ref $a[0] and $a[0] eq ":file"
l!l&&r!l&&!r
31530344
not ref $a[0] and $a[0] eq ":file"
!ll&&!rl&&r
89302555
MC/DC100%4/4
@a && (!defined($a[0]) || !ref($a[0]) && $a[0] eq ':file')
@a not defined $a[0] not ref $a[0] $a[0] eq ":file"
Truth table100%5/5
A && not(B) or not(C) and D
A= @aB= not defined $a[0]C= not ref $a[0]D= $a[0] eq ":file"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
96 15191 ▶ shift @a if $placeholder->();
Branch: 1 branch
BranchTrueFalseTotal
if &$placeholder() 33 15158 15191
97 15191 ▶ Carp::croak("Data::Shared: a spec names the backing-path placeholder"
Branch: 1 branch
BranchTrueFalseTotal
if &$placeholder() 3 15188 15191
98 . " (undef or ':file') more than once; the facade supplies one file")
99 if $placeholder->();
100 15188 return \@a;
101 }
102  
103 12766 ▶sub _constructor_args {
Subroutine _constructor_args: called CC=2 SCAR=6.9
104 12766 my ($resolved, $args) = @_;
105 12766 my $a = _strip_placeholder($args);
106 12766 ▶ return $a if $resolved->{convention} ne 'leading';
Branch: 1 branch
BranchTrueFalseTotal
if $resolved->{"convention"} ne "leading" 32 12734 12766
107 12734 return [undef, @$a];
108 }
109  
110 5542 ▶sub construct_node {
Subroutine construct_node: called CC=2 SCAR=7.2
Pod undocumented
111 5542 my ($dir, $readonly, $resolved, $name, $args, $mode) = @_;
112 5542 ▶ return Data::Shared::_construct_with($dir, $readonly, $resolved, $name,
Condition50%1/2
$mode || {}
l!l
55420
MC/DC0%0/1
$mode || {}
$mode
Truth table50%1/2
A
A= $mode
Aresult
11
00
113 _constructor_args($resolved, $args), $mode || {});
114 }
115  
116 4803 ▶sub _preflight {
Subroutine _preflight: called CC=13 SCAR=25.9
117 4803 my ($root, $node, $dir, $opening, $name) = @_;
118 # Reopening loads only this level, so an untouched child's backend cannot block the store.
119 4803 ▶ for (my $current = $node; $current; $current = $current->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) 9405 4571 13976
120 9405 Data::Shared::Storage::_load($current->{resolved});
121 9403 ▶ last if $opening;
Branch: 1 branch
BranchTrueFalseTotal
if $opening 230 9173 9403
122 }
123 # plan touches no filesystem: a malformed child spec is refused before anything is published.
124 4801 ▶ unless ($opening) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opening) 4571 230 4801
125 4571 ▶ my $as_child = bless { dir => defined $dir ? "$dir/child-0" : undef }, 'Data::Shared';
Branch: 1 branch
BranchTrueFalseTotal
defined $dir ? : 395 4176 4571
126 4571 ▶ for (my $c = $node->{child}; $c; $c = $c->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 4600 4566 9166
127 Data::Shared::Storage::plan($as_child, $c->{resolved}, 'child',
128 4600 _constructor_args($c->{resolved}, $c->{args}));
129 }
130 }
131 4796 ▶ if ($root->{strict_readonly}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->{"strict_readonly"}) 11 4785 4796
132 11 ▶ for (my $current = $node; $current; $current = $current->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) 22 10 32
133 22 Data::Shared::Storage::check_readonly($current->{resolved}, $name);
134 }
135 }
136 4795 ▶ return unless $opening;
Branch: 1 branch
BranchTrueFalseTotal
unless $opening 4566 229 4795
137 229 ▶ Carp::croak("Data::Shared: missing composite directory '" . ($dir // '') . "'") unless defined $dir && -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and -d $dir 0 229 229
Condition20%1/5
defined $dir and -d $dir
!ll&&!rl&&r
00229
$dir // ""
l!l
00
MC/DC0%0/2
defined $dir and -d $dir
defined $dir -d $dir
MC/DC0%0/1
$dir // ""
$dir
Truth table33%1/3
A and B
A= defined $dirB= -d $dir
ABresult
0X0
100
111
Truth table0%0/2
A
A= $dir
Aresult
11
00
138 229 my $context = bless { dir => $dir }, 'Data::Shared';
139 my $parent = Data::Shared::Storage::plan($context, $node->{resolved}, 'parent',
140 229 _constructor_args($node->{resolved}, $node->{args}));
141 229 my $index = Data::Shared::Storage::plan($context,
142 _index_spec(), 'index', _index_args($node));
143 229 Data::Shared::Storage::require_files($_) for ($parent, $index);
144 }
145  
146 4847 ▶sub _validate_node {
Subroutine _validate_node: called CC=10 SCAR=24.1
147 4847 my ($node) = @_;
148 4847 ▶ return unless $node->{child};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"child"} 2415 2432 4847
149 2432 my $entry = $node->{resolved}{entry};
150 2432 ▶ my $key = $entry ? $entry->{key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$entry ? : 2432 0 2432
151 Carp::croak("Data::Shared: '" . (defined $key ? $key : $node->{spec})
152 . "' cannot be a composite parent (only hashmap, sortedset, kdtree, and graph can); use it as a leaf or a sidecar")
153 2432 ▶ unless defined $key && $PARENT_OK{$key};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $key and $PARENT_OK{$key} 4 2428 2432
defined $key ? : 4 0 4
Condition66%2/3
defined $key and $PARENT_OK{$key}
!ll&&!rl&&r
042428
MC/DC50%1/2
defined $key and $PARENT_OK{$key}
defined $key $PARENT_OK{$key}
Truth table66%2/3
A and B
A= defined $keyB= $PARENT_OK{$key}
ABresult
0X0
100
111
154 2428 for my $option (qw(max_children cache_size)) {
155 Carp::croak("Data::Shared: composite $option must be an integer >= 1")
156 unless defined $node->{$option} && !ref $node->{$option}
157 4853 ▶ && $node->{$option} =~ /\A[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node->{$option} and not ref $node->{$option} and $node->{$option} =~ /\A[1-9][0-9]*\z/ 3 4850 4853
Condition50%3/6
defined $node->{$option} and not ref $node->{$option} and $node->{$option} =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
034850
defined $node->{$option} and not ref $node->{$option}
!ll&&!rl&&r
004853
MC/DC33%1/3
defined $node->{$option} and not ref $node->{$option} and $node->{$option} =~ /\A[1-9][0-9]*\z/
defined $node->{$option} not ref $node->{$option} $node->{$option} =~ /\A[1-9][0-9]*\z/
Truth table50%2/4
A and not(B) and C
A= defined $node->{$option}B= not ref $node->{$option}C= $node->{$option} =~ /\A[1-9][0-9]*\z/
ABCresult
0XX0
10X0
1100
1111
158 }
159 2425 _refuse_shared_child_path($node->{child});
160 }
161  
162 2425 ▶sub _refuse_shared_child_path {
Subroutine _refuse_shared_child_path: called CC=14 SCAR=26.4
163 2425 my ($child) = @_;
164 2425 ▶ my $args = _strip_placeholder($child->{args} || []);
Condition50%1/2
$child->{'args'} || []
l!l
24250
MC/DC0%0/1
$child->{'args'} || []
$child->{'args'}
Truth table50%1/2
A
A= $child->{'args'}
Aresult
11
00
165 2422 my $resolved = $child->{resolved};
166 2422 my @named;
167 2422 my $convention = $resolved->{convention};
168 2422 ▶ if ($convention eq 'options') {
Branch: 2 branches
BranchTrueFalseTotal
if ($convention eq 'options') { } 18 2404 2422
elsif ($convention eq 'handle') { } 4 2400 2404
169 18 ▶ my %opt = @$args == 1 && ref $args->[0] eq 'HASH' ? %{ $args->[0] }
Branch: 2 branches
BranchTrueFalseTotal
@$args == 1 && ref $args->[0] eq 'HASH' ? : 15 3 18
@$args % 2 ? : 1 2 3
Condition66%2/3
@$args == 1 and ref $args->[0] eq "HASH"
!ll&&!rl&&r
3015
MC/DC50%1/2
@$args == 1 and ref $args->[0] eq "HASH"
@$args == 1 ref $args->[0] eq "HASH"
Truth table66%2/3
A and B
A= @$args == 1B= ref $args->[0] eq "HASH"
ABresult
0X0
100
111
170 : @$args % 2 ? ()
171 : @$args;
172 18 @named = grep { defined $opt{$_} } qw(set keys);
173 }
174 elsif ($convention eq 'handle') {
175 @named = 'path' if @$args == 1 && ref $args->[0] eq 'HASH'
176 4 ▶ && defined $args->[0]{path};
Branch: 1 branch
BranchTrueFalseTotal
if @$args == 1 and ref $args->[0] eq "HASH" and defined $args->[0]{"path"} 1 3 4
Condition100%6/6
@$args == 1 and ref $args->[0] eq "HASH" and defined $args->[0]{"path"}
!ll&&!rl&&r
211
@$args == 1 and ref $args->[0] eq "HASH"
!ll&&!rl&&r
112
MC/DC100%3/3
@$args == 1 and ref $args->[0] eq "HASH" and defined $args->[0]{"path"}
@$args == 1 ref $args->[0] eq "HASH" defined $args->[0]{"path"}
Truth table100%4/4
A and B and C
A= @$args == 1B= ref $args->[0] eq "HASH"C= defined $args->[0]{"path"}
ABCresult
0XX0
10X0
1100
1111
177 4 ▶ @named = 'path' if @$args && defined $args->[0] && !ref $args->[0];
Branch: 1 branch
BranchTrueFalseTotal
if @$args and defined $args->[0] and not ref $args->[0] 1 3 4
Condition83%5/6
@$args and defined $args->[0] and not ref $args->[0]
!ll&&!rl&&r
121
@$args and defined $args->[0]
!ll&&!rl&&r
103
MC/DC66%2/3
@$args and defined $args->[0] and not ref $args->[0]
@$args defined $args->[0] not ref $args->[0]
Truth table75%3/4
A and B and not(C)
A= @$argsB= defined $args->[0]C= not ref $args->[0]
ABCresult
0XX0
10X0
1100
1111
178 }
179 2422 ▶ Carp::croak("Data::Shared: a composite child cannot name its own backing path ("
Branch: 1 branch
BranchTrueFalseTotal
if @named 10 2412 2422
180 . join(', ', @named) . "): one spec serves every child, so they would"
181 . " share one file. Leave it out and the facade derives one per child")
182 if @named;
183 2412 return;
184 }
185  
186 2408 ▶sub new {
Subroutine new: called CC=11 SCAR=24.2
Pod undocumented
187 2408 my ($class, %o) = @_;
188 2408 ▶ my $node = $o{node} or Carp::croak('Data::Shared: Composite requires a node');
Branch: 1 branch
BranchTrueFalseTotal
my $node = $o{"node"} or Carp::croak("Data::Shared: Composite requires a node") 2408 0 2408
189 2408 ▶ my $self = bless { node => $node, dir => $o{dir}, path => [ @{ $o{path} || [] } ],
Branch: 4 branches
BranchTrueFalseTotal
$o{'readonly'} ? : 84 2324 2408
$o{'cleanup'} ? : 3 2405 2408
$o{'frozen_ok'} ? : 4 2404 2408
$o{'strict_readonly'} ? : 5 2403 2408
Condition50%1/2
$o{'path'} || []
l!l
24080
MC/DC0%0/1
$o{'path'} || []
$o{'path'}
Truth table50%1/2
A
A= $o{'path'}
Aresult
11
00
190 name => $o{name}, readonly => $o{readonly} ? 1 : 0,
191 _cleanup => $o{cleanup} ? 1 : 0, _frozen_ok => $o{frozen_ok} ? 1 : 0,
192 2408 strict_readonly => $o{strict_readonly} ? 1 : 0,
193 cache => {}, lru_prev => {}, lru_next => {} }, $class;
194 2408 $self->{root_weak} = $o{root};
195 2408 ▶ weaken($self->{root_weak}) if $self->{root_weak};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"root_weak"} 2408 0 2408
196 2408 _preflight($self, $node, $self->{dir}, $o{opening}, $self->{name});
197 2408 ▶ if (defined $self->{dir} && !$o{opening}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dir"} and not $o{"opening"}) 199 2209 2408
Condition100%3/3
defined $self->{"dir"} and not $o{"opening"}
!ll&&!rl&&r
2090119199
MC/DC100%2/2
defined $self->{"dir"} and not $o{"opening"}
defined $self->{"dir"} not $o{"opening"}
Truth table100%3/3
A and not(B)
A= defined $self->{"dir"}B= not $o{"opening"}
ABresult
0X0
100
111
198 199 require File::Path;
199 199 File::Path::make_path($self->{dir}, { mode => 0700 });
200 }
201 2408 ▶ $self->_with_lock(sub {
Subroutine __ANON__: called CC=25 SCAR=32.9
202 # sealed_ok permits nested children to reopen after sealing; top-level mounts refuse it.
203 my %mode = (opening => $o{opening}, strict_readonly => $self->{strict_readonly},
204 pending_paths => $o{pending_paths}, cleanup => $self->{_cleanup},
205 2408 ▶ frozen_ok => ($self->{_frozen_ok} || $o{sealed_ok}) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_frozen_ok'} || $o{'sealed_ok'} ? : 9 2399 2408
Condition100%3/3
$self->{"_frozen_ok"} or $o{"sealed_ok"}
l!l&&r!l&&!r
452399
MC/DC100%2/2
$self->{"_frozen_ok"} or $o{"sealed_ok"}
$self->{"_frozen_ok"} $o{"sealed_ok"}
Truth table100%3/3
A or B
A= $self->{"_frozen_ok"}B= $o{"sealed_ok"}
ABresult
1X1
011
000
206 2408 my ($parent) = construct_node($self->{dir}, $self->{readonly}, $node->{resolved}, 'parent', $node->{args}, \%mode);
207 2407 $self->{parent_handle} = $parent;
208 2407 $self->{parent_record} = { handle => $parent, entry => $node->{resolved}{entry}, dt => {} };
209 my ($index) = Data::Shared::_construct_with($self->{dir}, $self->{readonly},
210 2407 _index_spec(), 'index', _index_args($node), \%mode);
211 2407 $self->{index} = $index;
212 317 @{$self}{qw(_index_dev _index_ino)} = (stat _index_file($self))[0, 1]
213 2407 ▶ if defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"dir"} 317 2090 2407
214 2407 ▶ Carp::croak('Data::Shared: composite instance was deleted') if $index->get('x:') && !$self->{_cleanup};
Branch: 1 branch
BranchTrueFalseTotal
if $index->get("x:") and not $self->{"_cleanup"} 0 2407 2407
Condition66%2/3
$index->get("x:") and not $self->{"_cleanup"}
!ll&&!rl&&r
240610
MC/DC0%0/2
$index->get("x:") and not $self->{"_cleanup"}
$index->get("x:") not $self->{"_cleanup"}
Truth table66%2/3
A and not(B)
A= $index->get("x:")B= not $self->{"_cleanup"}
ABresult
0X0
100
111
215 # 's:' is the child count; 'p:' marks an interrupted mutation that requires a recount.
216 # _index_frozen, not frozen: only the index's own writability matters here.
217 2407 ▶ if (!$self->{readonly} && !$self->{_cleanup} && !$self->_index_frozen
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"readonly"} || $self->{"_cleanup"} || $self->_index_frozen and $index->get("p:") || !defined($index->get("s:"))) 2292 115 2407
Condition100%12/12
not $self->{"readonly"} || $self->{"_cleanup"} || $self->_index_frozen and $index->get("p:") || !defined($index->get("s:"))
!ll&&!rl&&r
91242292
$self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen
l!l&&r!l&&!r
8742316
$self->{"readonly"} or $self->{"_cleanup"}
l!l&&r!l&&!r
8432320
$index->get("p:") or not defined $index->get("s:")
l!l&&r!l&&!r
2229024
MC/DC100%5/5
not $self->{"readonly"} || $self->{"_cleanup"} || $self->_index_frozen and $index->get("p:") || !defined($index->get("s:"))
$self->{"readonly"} $self->{"_cleanup"} $self->_index_frozen $index->get("p:") not defined $index->get("s:")
Truth table100%6/6
not(A or B || C) and D or not(E)
A= $self->{"readonly"}B= $self->{"_cleanup"}C= $self->_index_frozenD= $index->get("p:")E= not defined $index->get("s:")
ABCDEresult
1XXXX0
01XXX0
001XX0
000000
0001X1
000011
218 && ($index->get('p:') || !defined $index->get('s:'))) {
219 2292 $self->_index_put('s:', $self->_count_addresses);
220 2292 $self->_index_remove('p:');
221 }
222 2407 my $chain = _chain_signature($node);
223 2407 my $recorded = $index->get('k:');
224 2407 ▶ if (defined $recorded && length $recorded) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $recorded and length $recorded) { } 118 2289 2407
elsif (not $self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen) { } 2289 0 2289
Condition66%2/3
defined $recorded and length $recorded
!ll&&!rl&&r
22890118
MC/DC50%1/2
defined $recorded and length $recorded
defined $recorded length $recorded
Truth table66%2/3
A and B
A= defined $recordedB= length $recorded
ABresult
0X0
100
111
225 118 ▶ Carp::croak("Data::Shared: composite '$self->{name}' storage was created for"
Branch: 1 branch
BranchTrueFalseTotal
if $recorded ne $chain 1 117 118
226 . " [$recorded], not [$chain]")
227 if $recorded ne $chain;
228 }
229 ▶ elsif (!$self->{readonly} && !$self->{_cleanup} && !$self->_index_frozen) {
Condition33%2/6
$self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen
l!l&&r!l&&!r
002289
$self->{"readonly"} or $self->{"_cleanup"}
l!l&&r!l&&!r
002289
MC/DC0%0/3
$self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen
$self->{"readonly"} $self->{"_cleanup"} $self->_index_frozen
Truth table25%1/4
A or B || C
A= $self->{"readonly"}B= $self->{"_cleanup"}C= $self->_index_frozen
ABCresult
1XX1
01X1
0011
0000
230 2289 $self->_index_put('k:', $chain);
231 }
232 # 'b:' records the creation budget; the index's growing slot table cannot reveal it.
233 2406 my $budget = $index->get('b:');
234 2406 ▶ if (defined $budget && $budget =~ /\A[0-9]+\z/ && $budget < $node->{max_children}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $budget and $budget =~ /\A[0-9]+\z/ and $budget < $node->{'max_children'}) { } 2 2404 2406
elsif (not defined $budget || $self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen) { } 2289 115 2404
Condition83%5/6
defined $budget and $budget =~ /\A[0-9]+\z/ and $budget < $node->{"max_children"}
!ll&&!rl&&r
22891152
defined $budget and $budget =~ /\A[0-9]+\z/
!ll&&!rl&&r
22890117
MC/DC66%2/3
defined $budget and $budget =~ /\A[0-9]+\z/ and $budget < $node->{"max_children"}
defined $budget $budget =~ /\A[0-9]+\z/ $budget < $node->{"max_children"}
Truth table75%3/4
A and B and C
A= defined $budgetB= $budget =~ /\A[0-9]+\z/C= $budget < $node->{"max_children"}
ABCresult
0XX0
10X0
1100
1111
235 # A replayed manifest may ask for more; it gets the stored budget instead.
236 Carp::croak("Data::Shared: composite '$self->{name}' storage was created"
237 . " for max_children=$budget and cannot serve"
238 . " $node->{max_children}; the index is sized when it is created,"
239 . " so raising the budget needs unmount(unlink => 1) first")
240 2 ▶ unless $o{replaying};
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"replaying"} 1 1 2
241 1 $self->{_budget} = $budget;
242 }
243 ▶ elsif (!defined $budget && !$self->{readonly} && !$self->{_cleanup}
Condition66%6/9
defined $budget || $self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen
l!l&&r!l&&!r
11502289
defined $budget or $self->{"readonly"} or $self->{"_cleanup"}
l!l&&r!l&&!r
11502289
defined $budget or $self->{"readonly"}
l!l&&r!l&&!r
11502289
MC/DC25%1/4
defined $budget || $self->{'readonly'} || $self->{'_cleanup'} || $self->_index_frozen
defined $budget $self->{"readonly"} $self->{"_cleanup"} $self->_index_frozen
Truth table40%2/5
A or B or C || D
A= defined $budgetB= $self->{"readonly"}C= $self->{"_cleanup"}D= $self->_index_frozen
ABCDresult
1XXX1
01XX1
001X1
00011
00000
244 && !$self->_index_frozen) {
245 2289 $self->_index_put('b:', $node->{max_children});
246 }
247 2408 ▶ }, undef, $o{opening} ? 1 : 0); # reopening tolerates an unwritable lock; creating does not
Branch: 1 branch
BranchTrueFalseTotal
$o{'opening'} ? : 119 2289 2408
248 2405 return $self;
249 }
250  
251 2662 ▶sub _index_file { my ($self) = @_; return "$self->{dir}/index.shm" }
Subroutine _index_file: called CC=1 SCAR=0.0
252  
253 # Best-effort: a missing or unreadable lock file must not block a shipped store.
254 164 ▶sub _with_shared_lock {
Subroutine _with_shared_lock: called CC=8 SCAR=24.9
255 164 my ($self, $code) = @_;
256 164 ▶ my $lockfile = defined $self->{dir} ? "$self->{dir}/.lock" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'dir'} ? : 164 0 164
257 164 my $fh;
258 164 ▶ if (defined $lockfile && -e $lockfile && CORE::open($fh, '<', $lockfile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lockfile and -e $lockfile and open $fh, "<", $lockfile) 164 0 164
Condition33%2/6
defined $lockfile and -e $lockfile and open $fh, "<", $lockfile
!ll&&!rl&&r
00164
defined $lockfile and -e $lockfile
!ll&&!rl&&r
00164
MC/DC0%0/3
defined $lockfile and -e $lockfile and open $fh, "<", $lockfile
defined $lockfile -e $lockfile open $fh, "<", $lockfile
Truth table25%1/4
A and B and C
A= defined $lockfileB= -e $lockfileC= open $fh, "<", $lockfile
ABCresult
0XX0
10X0
1100
1111
259 164 ▶ until (flock $fh, LOCK_SH) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 1) 0 164 164
260 0 ▶ last unless $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"EINTR"} 0 0 0
261 }
262 # Recheck identity after waiting; teardown may have replaced the instance.
263 164 ▶ $self->_assert_live_instance if $self->{index};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} 80 84 164
264 }
265 163 local $self->{_locked} = 1;
266 163 return $code->();
267 }
268  
269 # Index identity distinguishes incarnations even when frozen mappings cannot record deletion.
270 # Teardown may meet its own absent index, but must never remove a replacement.
271 39 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
272 39 _INDEX_SAME => 0,
273 _INDEX_ABSENT => 1, # our own teardown, finished or interrupted
274 _INDEX_REPLACED => 2, # a different incarnation of the store
275 39 };
276  
277 6627 ▶sub _index_replaced {
Subroutine _index_replaced: called CC=6 SCAR=18.0
278 6627 my ($self) = @_;
279 6627 ▶ return _INDEX_SAME unless defined $self->{dir} && defined $self->{_index_ino};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} and defined $self->{"_index_ino"} 4282 2345 6627
Condition66%2/3
defined $self->{"dir"} and defined $self->{"_index_ino"}
!ll&&!rl&&r
428202345
MC/DC50%1/2
defined $self->{"dir"} and defined $self->{"_index_ino"}
defined $self->{"dir"} defined $self->{"_index_ino"}
Truth table66%2/3
A and B
A= defined $self->{"dir"}B= defined $self->{"_index_ino"}
ABresult
0X0
100
111
280 2345 my ($dev, $ino) = (stat _index_file($self))[0, 1];
281 2345 ▶ return _INDEX_ABSENT unless defined $ino;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ino 1 2344 2345
282 return ($dev == $self->{_index_dev} && $ino == $self->{_index_ino})
283 2344 ▶ ? _INDEX_SAME : _INDEX_REPLACED;
Branch: 1 branch
BranchTrueFalseTotal
$dev == $self->{'_index_dev'} && $ino == $self->{'_index_ino'} ? : 2339 5 2344
Condition66%2/3
$dev == $self->{"_index_dev"} and $ino == $self->{"_index_ino"}
!ll&&!rl&&r
052339
MC/DC50%1/2
$dev == $self->{"_index_dev"} and $ino == $self->{"_index_ino"}
$dev == $self->{"_index_dev"} $ino == $self->{"_index_ino"}
Truth table66%2/3
A and B
A= $dev == $self->{"_index_dev"}B= $ino == $self->{"_index_ino"}
ABresult
0X0
100
111
284 }
285  
286 6627 ▶sub _assert_live_instance {
Subroutine _assert_live_instance: called CC=5 SCAR=16.1
287 6627 my ($self) = @_;
288 6627 my $state = $self->_index_replaced;
289 6627 ▶ Carp::croak('Data::Shared: composite storage belongs to a newer instance')
Branch: 1 branch
BranchTrueFalseTotal
if $state == 2 5 6622 6627
290 if $state == _INDEX_REPLACED;
291 6622 ▶ return if $self->{_cleanup};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cleanup"} 40 6582 6622
292 Carp::croak('Data::Shared: composite instance was deleted')
293 6582 ▶ if $self->{index}->get('x:') || $state == _INDEX_ABSENT;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"}->get("x:") or $state == 1 1 6581 6582
Condition66%2/3
$self->{"index"}->get("x:") or $state == 1
l!l&&r!l&&!r
016581
MC/DC50%1/2
$self->{"index"}->get("x:") or $state == 1
$self->{"index"}->get("x:") $state == 1
Truth table66%2/3
A or B
A= $self->{"index"}->get("x:")B= $state == 1
ABresult
1X1
011
000
294 6581 return;
295 }
296  
297 2407 ▶sub _chain_signature {
Subroutine _chain_signature: called CC=3 SCAR=11.0
298 2407 my ($node) = @_;
299 2407 my @levels;
300 2407 ▶ for (my $level = $node; $level; $level = $level->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 4831 2407 7238
301 4831 ▶ push @levels, $level->{resolved}{class} . '->' . ($level->{resolved}{ctor} || 'new');
Condition50%1/2
$level->{'resolved'}{'ctor'} || 'new'
l!l
48310
MC/DC0%0/1
$level->{'resolved'}{'ctor'} || 'new'
$level->{'resolved'}{'ctor'}
Truth table50%1/2
A
A= $level->{'resolved'}{'ctor'}
Aresult
11
00
302 }
303 2407 return join ' ', @levels;
304 }
305  
306 5676 ▶sub _root {
Subroutine _root: called CC=3 SCAR=17.3
307 5676 my ($self, $root) = @_;
308 5676 ▶ return $root if $root;
Branch: 1 branch
BranchTrueFalseTotal
if $root 5676 0 5676
309 0 my $r = $self->{root_weak};
310 0 ▶ Carp::croak("Data::Shared: root has gone away") unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 0 0
311 0 return $r;
312 }
313  
314 # The resolved spec is fixed for this instance's lifetime.
315 11607 ▶sub _key_is_int {
Subroutine _key_is_int: called CC=2 SCAR=7.1
316 11607 my ($self) = @_;
317 11607 ▶ return $self->{_key_is_int} //= _key_is_int_for($self);
Condition66%2/3
$self->{"_key_is_int"} //= _key_is_int_for($self)
l!l&&r!l&&!r
922723800
MC/DC0%0/2
$self->{"_key_is_int"} //= _key_is_int_for($self)
$self->{"_key_is_int"} _key_is_int_for($self)
Truth table66%2/3
A //= B
A= $self->{"_key_is_int"}B= _key_is_int_for($self)
ABresult
1X1
011
000
318 }
319  
320 198 ▶sub _key_int_bits {
Subroutine _key_int_bits: called CC=2 SCAR=7.1
321 198 my ($self) = @_;
322 198 ▶ return $self->{_key_int_bits} //= _key_int_bits_for($self);
Condition66%2/3
$self->{"_key_int_bits"} //= _key_int_bits_for($self)
l!l&&r!l&&!r
175230
MC/DC0%0/2
$self->{"_key_int_bits"} //= _key_int_bits_for($self)
$self->{"_key_int_bits"} _key_int_bits_for($self)
Truth table66%2/3
A //= B
A= $self->{"_key_int_bits"}B= _key_int_bits_for($self)
ABresult
1X1
011
000
323 }
324  
325 2377 ▶sub _key_probe {
Subroutine _key_probe: called CC=3 SCAR=11.1
326 2377 my ($resolved) = @_;
327 2377 ▶ return lc $resolved->{variant} if defined $resolved->{variant};
Branch: 1 branch
BranchTrueFalseTotal
if defined $resolved->{"variant"} 2372 5 2377
328 5 ▶ return $resolved->{class} =~ /::(\w+)\z/ ? lc $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$resolved->{'class'} =~ /::(\w+)\z/ ? : 5 0 5
329 }
330  
331 2380 ▶sub _key_is_int_for {
Subroutine _key_is_int_for: called CC=7 SCAR=19.5
332 2380 my ($self) = @_;
333 2380 my $resolved = $self->{node}{resolved};
334 # kdtree and graph address children by integer id without an int variant.
335 2380 ▶ return 1 if $self->_is_index_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_index_parent 8 2372 2380
336 2372 ▶ return 0 if $resolved->{class} eq 'Data::SortedSet::Shared::Strings';
Branch: 1 branch
BranchTrueFalseTotal
if $resolved->{"class"} eq "Data::SortedSet::Shared::Strings" 5 2367 2372
337 2367 ▶ return 1 if $resolved->{entry} && ($resolved->{entry}{key} || '') eq 'sortedset';
Branch: 1 branch
BranchTrueFalseTotal
if $resolved->{"entry"} and ($resolved->{"entry"}{"key"} || "") eq "sortedset" 5 2362 2367
Condition60%3/5
$resolved->{"entry"} and ($resolved->{"entry"}{"key"} || "") eq "sortedset"
!ll&&!rl&&r
023625
$resolved->{'entry'}{'key'} || ''
l!l
23670
MC/DC0%0/2
$resolved->{"entry"} and ($resolved->{"entry"}{"key"} || "") eq "sortedset"
$resolved->{"entry"} $resolved->{'entry'}{'key'}
Truth table33%1/3
A and B
A= $resolved->{"entry"}B= $resolved->{'entry'}{'key'}
ABresult
0X0
100
111
338 2362 ▶ return _key_probe($resolved) =~ /\A(?:i16|i32|ii|is)/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_key_probe($resolved) =~ /\A(?:i16|i32|ii|is)/ ? : 10 2352 2362
339 }
340  
341 11404 ▶sub _valid_address {
Subroutine _valid_address: called CC=13 SCAR=25.7
342 11404 my ($self, $addr) = @_;
343 11404 ▶ return 0 unless defined $addr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr 0 11404 11404
344 11404 ▶ return 1 unless $self->_key_is_int;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_key_is_int 11187 217 11404
345 # One canonical spelling per key, and \z not $: the index keys on the string and the
346 # parent on its numeric value, so "7\n" would register a second child over one slot.
347 217 my ($neg, $mag) = $addr =~ /\A(-?)(0|[1-9][0-9]*)\z/;
348 217 ▶ return 0 if !defined $mag || ($neg && $mag eq '0');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $mag or $neg and $mag eq 0 19 198 217
Condition100%6/6
not defined $mag or $neg and $mag eq 0
l!l&&r!l&&!r
163198
$neg and $mag eq 0
!ll&&!rl&&r
182163
MC/DC100%3/3
not defined $mag or $neg and $mag eq 0
not defined $mag $neg $mag eq 0
Truth table100%4/4
not(A) or B and C
A= not defined $magB= $negC= $mag eq 0
ABCresult
1XX1
0111
00X0
0100
349 # Overflow is refused for composite parents only; plain leaves keep backend wrapping.
350 198 ▶ if (my $bits = $self->_key_int_bits) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bits = $self->_key_int_bits) 128 70 198
351 128 ▶ my $limit = $bits == 64
Branch: 3 branches
BranchTrueFalseTotal
$bits == 64 ? : 98 30 128
$neg ? : 8 90 98
$neg ? : 8 22 30
352 ? ($neg ? '9223372036854775808' : '9223372036854775807')
353 : (1 << ($bits - 1)) - ($neg ? 0 : 1);
354 # Compare decimal strings to avoid rounding 64-bit bounds through a double.
355 128 ▶ return 0 if length($mag) > length($limit)
Branch: 1 branch
BranchTrueFalseTotal
if length $mag > length $limit or length $mag == length $limit and $mag gt $limit 14 114 128
Condition100%6/6
length $mag > length $limit or length $mag == length $limit and $mag gt $limit
l!l&&r!l&&!r
212114
length $mag == length $limit and $mag gt $limit
!ll&&!rl&&r
783612
MC/DC100%3/3
length $mag > length $limit or length $mag == length $limit and $mag gt $limit
length $mag > length $limit length $mag == length $limit $mag gt $limit
Truth table100%4/4
A or B and C
A= length $mag > length $limitB= length $mag == length $limitC= $mag gt $limit
ABCresult
1XX1
0111
00X0
0100
356 || (length($mag) == length($limit) && $mag gt $limit);
357 }
358 184 return 1;
359 }
360  
361 23 ▶sub _key_int_bits_for {
Subroutine _key_int_bits_for: called CC=5 SCAR=16.1
362 23 my ($self) = @_;
363 # Id parents have no mirror slot whose fixed-width key could collide.
364 23 ▶ return 0 if $self->_is_index_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_index_parent 8 15 23
365 15 my $probe = _key_probe($self->{node}{resolved});
366 15 ▶ return 16 if $probe =~ /\Ai16/;
Branch: 1 branch
BranchTrueFalseTotal
if $probe =~ /\Ai16/ 2 13 15
367 13 ▶ return 32 if $probe =~ /\Ai32/;
Branch: 1 branch
BranchTrueFalseTotal
if $probe =~ /\Ai32/ 2 11 13
368 # Other integer-keyed parents wrap at IV width.
369 11 ▶ return $self->_key_is_int ? 64 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_key_is_int ? : 11 0 11
370 }
371  
372 5736 ▶sub _with_lock {
Subroutine _with_lock: called CC=24 SCAR=32.5
373 5736 my ($self, $code, $mutating, $read_only) = @_;
374 # Check identity before every shortcut, including re-entry and read-only access.
375 5736 ▶ $self->_assert_live_instance if $self->{index};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} 3328 2408 5736
376 5731 ▶ return $code->() if $self->{_locked};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_locked"} 24 5707 5731
377 # Hold a shared lock through child opens so teardown cannot replace their storage.
378 5707 ▶ return $self->_with_shared_lock($code) if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 164 5543 5707
379 5543 my $fh;
380 5543 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'dir'}) { } 1312 4231 5543
381 1312 my $lockfile = "$self->{dir}/.lock";
382 1312 ▶ Carp::croak("Data::Shared: missing composite directory '$self->{dir}'") unless -d $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{"dir"} 0 1312 1312
383 # $read_only, not !$mutating: freeze and destroy are destructive yet pass no $mutating.
384 1312 ▶ unless (sysopen $fh, $lockfile, O_RDWR | O_APPEND | O_CREAT, 0600) {
Branch: 1 branch
BranchTrueFalseTotal
unless (sysopen $fh, $lockfile, 1090, 384) 2 1310 1312
385 2 my $err = $!;
386 2 ▶ unless ($read_only && -e $lockfile && CORE::open $fh, '<', $lockfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($read_only and -e $lockfile and open $fh, "<", $lockfile) 0 2 2
Condition33%2/6
$read_only and -e $lockfile and open $fh, "<", $lockfile
!ll&&!rl&&r
002
$read_only and -e $lockfile
!ll&&!rl&&r
002
MC/DC0%0/3
$read_only and -e $lockfile and open $fh, "<", $lockfile
$read_only -e $lockfile open $fh, "<", $lockfile
Truth table25%1/4
A and B and C
A= $read_onlyB= -e $lockfileC= open $fh, "<", $lockfile
ABCresult
0XX0
10X0
1100
1111
387 0 $! = $err;
388 0 Carp::croak("Data::Shared: cannot open composite lock '$lockfile': $!");
389 }
390 }
391 1312 ▶ until (flock $fh, LOCK_EX) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 2) 0 1312 1312
392 0 ▶ Carp::croak("Data::Shared: cannot lock composite: $!") unless $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"EINTR"} 0 0 0
393 }
394 } else {
395 4231 ▶ unless ($self->{lock_handle}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"lock_handle"}) 2090 2141 4231
396 # RWLock recovers a lock whose owner died.
397 2090 Data::Shared::_require_class('Data::Sync::Shared::RWLock', 'Data-Sync-Shared');
398 2090 $self->{lock_handle} = Data::Sync::Shared::RWLock->new(undef);
399 }
400 4231 $self->{lock_handle}->wrlock;
401 }
402 5543 local $self->{_locked} = 1;
403 5543 my $want = wantarray;
404 5543 my (@ret, $ret);
405 5543 my $ok = eval {
406 5543 ▶ if ($self->{index}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"}) 3219 2324 5543
407 3219 $self->_assert_live_instance;
408 # A sealed index cannot be repaired.
409 3219 ▶ if ($self->{index}->get('p:') && !$self->_index_frozen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"}->get("p:") and not $self->_index_frozen) 5 3214 3219
Condition100%3/3
$self->{"index"}->get("p:") and not $self->_index_frozen
!ll&&!rl&&r
321225
MC/DC100%2/2
$self->{"index"}->get("p:") and not $self->_index_frozen
$self->{"index"}->get("p:") not $self->_index_frozen
Truth table100%3/3
A and not(B)
A= $self->{"index"}->get("p:")B= not $self->_index_frozen
ABresult
0X0
100
111
410 5 $self->_index_put('s:', $self->_count_addresses);
411 5 $self->_index_remove('p:');
412 }
413 3219 ▶ $self->_index_put('p:', 1) if $mutating;
Branch: 1 branch
BranchTrueFalseTotal
if $mutating 2793 426 3219
414 }
415 5543 ▶ if ($want) { @ret = $code->() } elsif (defined $want) { $ret = $code->() } else { $code->() }
Branch: 2 branches
BranchTrueFalseTotal
if ($want) { } 1 5542 5543
elsif (defined $want) { } 3168 2374 5542
416 5525 ▶ $self->_index_remove('p:') if $mutating && $self->{index};
Branch: 1 branch
BranchTrueFalseTotal
if $mutating and $self->{"index"} 2782 2743 5525
Condition66%2/3
$mutating and $self->{"index"}
!ll&&!rl&&r
274302782
MC/DC50%1/2
$mutating and $self->{"index"}
$mutating $self->{"index"}
Truth table66%2/3
A and B
A= $mutatingB= $self->{"index"}
ABresult
0X0
100
111
417 5525 1;
418 };
419 5543 my $err = $@;
420 5543 ▶ if ($fh) { close $fh }
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 1312 4231 5543
421 4231 else { $self->{lock_handle}->wrunlock }
422 5543 ▶ die $err unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 18 5525 5543
423 5525 ▶ return $want ? @ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 1 5524 5525
424 }
425  
426 # Each index key needs next_pow2(2 + address length) bytes: the backend's 128-byte
427 # default covers 126-byte addresses, 272 covers 254. The mapping is sparse.
428 39 my $INDEX_ARENA_PER_ENTRY = 272;
429 39 my $INDEX_ARENA_MAX = 0xFFFFFFFF; # the backend's 32-bit size limit
430  
431 # No freeze: sealing a composite index would prevent retiring it (freeze_all seals subtrees).
432 39 my %LIFECYCLE_METHOD = map { $_ => 1 } qw(stats sync unlink destroy frozen);
433  
434 # Backends may reject a second freeze.
435 344 ▶sub _freeze_once {
Subroutine _freeze_once: called CC=5 SCAR=17.0
436 344 my ($handle) = @_;
437 344 ▶ return 0 unless $handle && $handle->can('freeze');
Branch: 1 branch
BranchTrueFalseTotal
unless $handle and $handle->can("freeze") 0 344 344
Condition33%1/3
$handle and $handle->can("freeze")
!ll&&!rl&&r
00344
MC/DC0%0/2
$handle and $handle->can("freeze")
$handle $handle->can("freeze")
Truth table33%1/3
A and B
A= $handleB= $handle->can("freeze")
ABresult
0X0
100
111
438 344 ▶ return 0 if $handle->can('frozen') && $handle->frozen;
Branch: 1 branch
BranchTrueFalseTotal
if $handle->can("frozen") and $handle->frozen 2 342 344
Condition66%2/3
$handle->can("frozen") and $handle->frozen
!ll&&!rl&&r
03422
MC/DC50%1/2
$handle->can("frozen") and $handle->frozen
$handle->can("frozen") $handle->frozen
Truth table66%2/3
A and B
A= $handle->can("frozen")B= $handle->frozen
ABresult
0X0
100
111
439 342 $handle->freeze;
440 342 return 1;
441 }
442  
443 # Shared by every composite: nothing may write to it.
444 39 my $INDEX_SPEC;
445 2642 ▶sub _index_spec { return $INDEX_SPEC ||= Data::Shared::Registry::resolve_spec('hashmap:ss') }
Subroutine _index_spec: called CC=2 SCAR=7.2
Condition66%2/3
$INDEX_SPEC ||= Data::Shared::Registry::resolve_spec("hashmap:ss")
l!l&&r!l&&!r
2621210
MC/DC0%0/2
$INDEX_SPEC ||= Data::Shared::Registry::resolve_spec("hashmap:ss")
$INDEX_SPEC Data::Shared::Registry::resolve_spec("hashmap:ss")
Truth table66%2/3
A ||= B
A= $INDEX_SPECB= Data::Shared::Registry::resolve_spec("hashmap:ss")
ABresult
1X1
011
000
446  
447 2636 ▶sub _index_args {
Subroutine _index_args: called CC=2 SCAR=7.0
448 2636 my ($node) = @_;
449 2636 my $entries = 2 * $node->{max_children} + 16;
450 2636 my $arena = $entries * $INDEX_ARENA_PER_ENTRY;
451 2636 ▶ $arena = $INDEX_ARENA_MAX if $arena > $INDEX_ARENA_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if $arena > $INDEX_ARENA_MAX 0 2636 2636
452 2636 return [undef, $entries, 0, 0, 0, $arena];
453 }
454  
455 20709 ▶sub _index_put {
Subroutine _index_put: called CC=7 SCAR=21.5
456 20709 my ($self, $key, $value) = @_;
457 20709 ▶ return 1 if $self->{index}->put($key, $value);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"}->put($key, $value) 20708 1 20709
458 1 ▶ my $s = ($self->{index}->can('stats') ? $self->{index}->stats : undef) || {};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'index'}->can('stats') ? : 1 0 1
Condition50%1/2
($self->{'index'}->can('stats') ? $self->{'index'}->stats : undef) || {}
l!l
10
MC/DC0%0/1
($self->{'index'}->can('stats') ? $self->{'index'}->stats : undef) || {}
($self->{'index'}->can('stats') ? $self->{'index'}->stats : undef)
Truth table50%1/2
A
A= ($self->{'index'}->can('stats') ? $self->{'index'}->stats : undef)
Aresult
11
00
459 # HashMap put exhausts capacity, not the smaller max_entries load-factor limit.
460 1 ▶ my $shown = length($key) > 72 ? substr($key, 0, 69) . '...' : $key;
Branch: 1 branch
BranchTrueFalseTotal
length $key > 72 ? : 0 1 1
461 Carp::croak(sprintf
462 "Data::Shared: composite registry is full, cannot write '%s'"
463 . " (entries %s/%s, string arena %s/%s bytes, max_children=%s)",
464 5 ▶ $shown, map { defined $_ ? $_ : '?' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 5 0 5
Condition33%1/3
$s->{"capacity"} // $s->{"max_entries"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$s->{"capacity"} // $s->{"max_entries"}
$s->{"capacity"} $s->{"max_entries"}
Truth table33%1/3
A // B
A= $s->{"capacity"}B= $s->{"max_entries"}
ABresult
1X1
011
000
465 $s->{size}, $s->{capacity} // $s->{max_entries},
466 $s->{arena_used}, $s->{arena_cap},
467 1 $self->{node}{max_children});
468 }
469  
470 5150 ▶sub _index_remove {
Subroutine _index_remove: called CC=2 SCAR=7.1
471 5150 my ($self, $key) = @_;
472 5150 $self->{index}->remove($key);
473 5150 ▶ Carp::croak("Data::Shared: cannot remove composite registry '$key'") if $self->{index}->exists($key);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"}->exists($key) 0 5150 5150
474 }
475  
476 11710 ▶sub _reg_id {
Subroutine _reg_id: called CC=1 SCAR=0.0
477 11710 my ($self, $addr) = @_;
478 11710 return $self->{index}->get('a:' . $addr);
479 }
480  
481 3344 ▶sub _reg_constructed {
Subroutine _reg_constructed: called CC=7 SCAR=19.7
482 3344 my ($self, $addr, $id) = @_;
483 3344 my $value = $self->{index}->get('c:' . $addr);
484 3344 ▶ return 0 unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 12 3332 3344
Condition66%2/3
defined $value and length $value
!ll&&!rl&&r
1203332
MC/DC50%1/2
defined $value and length $value
defined $value length $value
Truth table66%2/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
485 # Legacy marker spelling, still read; t/17 covers it.
486 3332 ▶ return 1 if $value eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq 1 2 3330 3332
487 3330 ▶ $id = $self->_reg_id($addr) unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 3330 3330
488 3330 ▶ return defined $id && $value eq "id:$id" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $id && $value eq "id:$id" ? : 3327 3 3330
Condition66%2/3
defined $id and $value eq "id:$id"
!ll&&!rl&&r
033327
MC/DC50%1/2
defined $id and $value eq "id:$id"
defined $id $value eq "id:$id"
Truth table66%2/3
A and B
A= defined $idB= $value eq "id:$id"
ABresult
0X0
100
111
489 }
490  
491 2297 ▶sub _count_addresses {
Subroutine _count_addresses: called CC=1 SCAR=0.0
492 2297 my ($self) = @_;
493 2297 my @keys = $self->{index}->keys;
494 2297 return scalar grep { substr($_, 0, 2) eq 'a:' } @keys;
495 }
496  
497 5574 ▶sub _child_count {
Subroutine _child_count: called CC=5 SCAR=16.2
498 5574 my ($self) = @_;
499 5574 ▶ if (!$self->{_locked} && $self->{index}->get('p:')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_locked"} and $self->{"index"}->get("p:")) 5 5569 5574
Condition100%3/3
not $self->{"_locked"} and $self->{"index"}->get("p:")
!ll&&!rl&&r
5545245
MC/DC100%2/2
not $self->{"_locked"} and $self->{"index"}->get("p:")
not $self->{"_locked"} $self->{"index"}->get("p:")
Truth table100%3/3
not(A) and B
A= not $self->{"_locked"}B= $self->{"index"}->get("p:")
ABresult
0X0
100
111
500 5 ▶ return $self->_count_addresses if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 5 5
501 5 ▶ return $self->_with_lock(sub { $self->{index}->get('s:') }, undef, 1);
Subroutine __ANON__: called CC=1 SCAR=0.0
502 }
503 5569 my $count = $self->{index}->get('s:');
504 5569 ▶ return defined $count ? $count : $self->_count_addresses;
Branch: 1 branch
BranchTrueFalseTotal
defined $count ? : 5569 0 5569
505 }
506  
507 2757 ▶sub _allocate_id {
Subroutine _allocate_id: called CC=5 SCAR=16.2
508 2757 my ($self) = @_;
509 2757 ▶ my $limit = $self->{_budget} // $self->{node}{max_children};
Condition66%2/3
$self->{"_budget"} // $self->{"node"}{"max_children"}
l!l&&r!l&&!r
327540
MC/DC0%0/2
$self->{"_budget"} // $self->{"node"}{"max_children"}
$self->{"_budget"} $self->{"node"}{"max_children"}
Truth table66%2/3
A // B
A= $self->{"_budget"}B= $self->{"node"}{"max_children"}
ABresult
1X1
011
000
510 2757 ▶ Carp::croak("Data::Shared: composite child limit exceeded (max_children=$limit) at $self->{name}")
Branch: 1 branch
BranchTrueFalseTotal
if $self->_child_count >= $limit 6 2751 2757
511 if $self->_child_count >= $limit;
512 2751 ▶ my $id = $self->{index}->get('n:') // 0;
Condition100%2/2
$self->{"index"}->get("n:") // 0
l!l
4802271
MC/DC100%1/1
$self->{"index"}->get("n:") // 0
$self->{"index"}->get("n:")
Truth table100%2/2
A
A= $self->{"index"}->get("n:")
Aresult
11
00
513 2751 ▶ Carp::croak('Data::Shared: invalid composite child sequence') unless $id =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /\A[0-9]+\z/ 0 2751 2751
514 2751 $self->_index_put('n:', $id + 1); # Child ids are never rolled back or reused.
515 2751 return $id;
516 }
517  
518 10815 ▶sub _is_index_parent {
Subroutine _is_index_parent: called CC=4 SCAR=13.9
519 10815 my ($self) = @_;
520 10815 ▶ my $key = $self->{node}{resolved}{entry}{key} || '';
Condition50%1/2
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
l!l
108150
MC/DC0%0/1
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
$self->{'node'}{'resolved'}{'entry'}{'key'}
Truth table50%1/2
A
A= $self->{'node'}{'resolved'}{'entry'}{'key'}
Aresult
11
00
521 10815 ▶ return ($key eq 'kdtree' || $key eq 'graph') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'kdtree' || $key eq 'graph' ? : 60 10755 10815
Condition100%3/3
$key eq "kdtree" or $key eq "graph"
l!l&&r!l&&!r
243610755
MC/DC100%2/2
$key eq "kdtree" or $key eq "graph"
$key eq "kdtree" $key eq "graph"
Truth table100%3/3
A or B
A= $key eq "kdtree"B= $key eq "graph"
ABresult
1X1
011
000
522 }
523  
524 5612 ▶sub _parent_exists {
Subroutine _parent_exists: called CC=4 SCAR=13.9
525 5612 my ($self, $addr) = @_;
526 5612 ▶ return defined $self->_reg_id($addr) ? 1 : 0 if $self->_is_index_parent;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_is_index_parent 22 5590 5612
defined $self->_reg_id($addr) ? : 0 22 22
527 5590 my $r = Data::Shared::_dispatch_record('exists', $self->{parent_record}, [$addr]);
528 5590 ▶ return $r ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 2799 2791 5590
529 }
530  
531 2753 ▶sub _parent_register {
Subroutine _parent_register: called CC=15 SCAR=31.5
532 2753 my ($self, $addr, $id) = @_;
533 2753 ▶ return if $self->_is_index_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_index_parent 22 2731 2753
534 2731 ▶ my $key = $self->{node}{resolved}{entry}{key} || '';
Condition50%1/2
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
l!l
27310
MC/DC0%0/1
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
$self->{'node'}{'resolved'}{'entry'}{'key'}
Truth table50%1/2
A
A= $self->{'node'}{'resolved'}{'entry'}{'key'}
Aresult
11
00
535 2731 ▶ if ($key eq 'sortedset') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'sortedset') { } 22 2709 2731
536 22 ▶ if (!$self->_parent_exists($addr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_parent_exists($addr)) 18 4 22
537 18 Data::Shared::_dispatch_record('set', $self->{parent_record}, [$addr], 0);
538 }
539 } else {
540 2709 Data::Shared::_dispatch_record('set', $self->{parent_record}, [$addr], $id);
541 }
542 2731 ▶ return if $self->_parent_exists($addr);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_parent_exists($addr) 2730 1 2731
543 1 ▶ my $s = ($self->{parent_handle}->can('stats') ? $self->{parent_handle}->stats : undef) || {};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parent_handle'}->can('stats') ? : 1 0 1
Condition50%1/2
($self->{'parent_handle'}->can('stats') ? $self->{'parent_handle'}->stats : undef) || {}
l!l
10
MC/DC0%0/1
($self->{'parent_handle'}->can('stats') ? $self->{'parent_handle'}->stats : undef) || {}
($self->{'parent_handle'}->can('stats') ? $self->{'parent_handle'}->stats : undef)
Truth table50%1/2
A
A= ($self->{'parent_handle'}->can('stats') ? $self->{'parent_handle'}->stats : undef)
Aresult
11
00
544 # SortedSet::Strings reports member capacity under "set".
545 1 ▶ $s = $s->{set} if ref $s->{set} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $s->{"set"} eq "HASH" 0 1 1
546 1 ▶ my $size = $s->{size} // $s->{count};
Condition33%1/3
$s->{"size"} // $s->{"count"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$s->{"size"} // $s->{"count"}
$s->{"size"} $s->{"count"}
Truth table33%1/3
A // B
A= $s->{"size"}B= $s->{"count"}
ABresult
1X1
011
000
547 1 ▶ my $cap = $s->{capacity} // $s->{max_entries} // $s->{max};
Condition33%2/6
($s->{"capacity"} // $s->{"max_entries"}) // $s->{"max"}
l!l&&r!l&&!r
100
$s->{"capacity"} // $s->{"max_entries"}
l!l&&r!l&&!r
010
MC/DC0%0/3
($s->{"capacity"} // $s->{"max_entries"}) // $s->{"max"}
$s->{"capacity"} $s->{"max_entries"} $s->{"max"}
Truth table25%1/4
A // B // C
A= $s->{"capacity"}B= $s->{"max_entries"}C= $s->{"max"}
ABCresult
1XX1
01X1
0011
0000
548 Carp::croak(sprintf
549 "Data::Shared: cannot register child '%s' in the %s parent of '%s'"
550 . " (parent holds %s of %s; every child is an entry in it, so its own"
551 . " capacity bounds max_children=%s)",
552 $addr, $key || ref $self->{parent_handle}, $self->{name},
553 3 ▶ map { defined $_ ? $_ : '?' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 3 0 3
Condition33%1/3
$self->{"_budget"} // $self->{"node"}{"max_children"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"_budget"} // $self->{"node"}{"max_children"}
$self->{"_budget"} $self->{"node"}{"max_children"}
Truth table33%1/3
A // B
A= $self->{"_budget"}B= $self->{"node"}{"max_children"}
ABresult
1X1
011
000
554 1 ▶ $size, $cap, $self->{_budget} // $self->{node}{max_children});
Condition33%1/3
$key || ref $self->{'parent_handle'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$key || ref $self->{'parent_handle'}
$key ref $self->{'parent_handle'}
Truth table33%1/3
A || B
A= $keyB= ref $self->{'parent_handle'}
ABresult
1X1
011
000
555 0 return;
556 }
557  
558 21 ▶sub _parent_unregister {
Subroutine _parent_unregister: called CC=4 SCAR=14.0
559 21 my ($self, $addr) = @_;
560 21 ▶ return if $self->_is_index_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_index_parent 0 21 21
561 21 ▶ if ($self->_parent_exists($addr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_parent_exists($addr)) 18 3 21
562 18 Data::Shared::_dispatch_record('delete', $self->{parent_record}, [$addr]);
563 18 ▶ Carp::croak('Data::Shared: cannot unregister child in parent backend') if $self->_parent_exists($addr);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_parent_exists($addr) 0 18 18
564 }
565 21 return;
566 }
567  
568 1533 ▶sub _untouch {
Subroutine _untouch: called CC=4 SCAR=13.9
569 1533 my ($self, $id) = @_;
570 1533 ▶ return unless exists $self->{lru_prev}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"lru_prev"}{$id} 1021 512 1533
571 512 my $prev = delete $self->{lru_prev}{$id};
572 512 my $next = delete $self->{lru_next}{$id};
573 512 ▶ if (defined $prev) { $self->{lru_next}{$prev} = $next } else { $self->{lru_head} = $next }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev) { } 1 511 512
574 512 ▶ if (defined $next) { $self->{lru_prev}{$next} = $prev } else { $self->{lru_tail} = $prev }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next) { } 504 8 512
575 }
576  
577 5435 ▶sub _touch {
Subroutine _touch: called CC=5 SCAR=16.1
578 5435 my ($self, $id) = @_;
579 5435 ▶ return unless defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 4376 1059 5435
580 1059 ▶ return if defined $self->{lru_tail} && $self->{lru_tail} == $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"lru_tail"} and $self->{"lru_tail"} == $id 59 1000 1059
Condition100%3/3
defined $self->{"lru_tail"} and $self->{"lru_tail"} == $id
!ll&&!rl&&r
28371759
MC/DC100%2/2
defined $self->{"lru_tail"} and $self->{"lru_tail"} == $id
defined $self->{"lru_tail"} $self->{"lru_tail"} == $id
Truth table100%3/3
A and B
A= defined $self->{"lru_tail"}B= $self->{"lru_tail"} == $id
ABresult
0X0
100
111
581 1000 $self->_untouch($id);
582 1000 my $tail = $self->{lru_tail};
583 1000 $self->{lru_prev}{$id} = $tail;
584 1000 $self->{lru_next}{$id} = undef;
585 1000 ▶ if (defined $tail) { $self->{lru_next}{$tail} = $id } else { $self->{lru_head} = $id }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tail) { } 717 283 1000
586 1000 $self->{lru_tail} = $id;
587 }
588  
589 533 ▶sub _forget {
Subroutine _forget: called CC=1 SCAR=0.0
590 533 my ($self, $id) = @_;
591 533 $self->_untouch($id);
592 533 return delete $self->{cache}{$id};
593 }
594  
595 3112 ▶sub _evict {
Subroutine _evict: called CC=3 SCAR=11.0
596 3112 my ($self) = @_;
597 3112 ▶ return unless defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 2117 995 3112
598 995 ▶ while (keys(%{ $self->{cache} }) > $self->{node}{cache_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"cache"};} > $self->{"node"}{"cache_size"}) 496 995 1491
599 496 $self->_forget($self->{lru_head});
600 }
601 }
602  
603 3163 ▶sub _open_child {
Subroutine _open_child: called CC=19 SCAR=29.4
604 3163 my ($self, $root, $addr, $id, $opening, $pending, $cleanup) = @_;
605 3163 ▶ if (my $rt = $self->{cache}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rt = $self->{"cache"}{$id}) 2 3161 3163
606 2 $self->_touch($id);
607 2 return $rt;
608 }
609 3161 my $node = $self->{node}{child};
610 3161 ▶ my $dir = defined $self->{dir} ? "$self->{dir}/child-$id" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'dir'} ? : 1043 2118 3161
611 3161 ▶ Carp::croak("Data::Shared: child '" . join('/', '', @{ $self->{path} }, $addr)
Branch: 1 branch
BranchTrueFalseTotal
if $opening and not defined $dir 1 3160 3161
Condition100%3/3
$opening and not defined $dir
!ll&&!rl&&r
27494111
MC/DC100%2/2
$opening and not defined $dir
$opening not defined $dir
Truth table100%3/3
A and not(B)
A= $openingB= not defined $dir
ABresult
0X0
100
111
612 . "' exists in the shared index but belongs to another process; an anonymous"
613 . " root has no backing file to reopen it (mount a file-backed root)")
614 if $opening && !defined $dir;
615 3160 ▶ if (defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 1043 2117 3160
616 1043 ▶ Carp::croak("Data::Shared: missing composite child directory '$dir'") if $opening && !-d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $opening and not -d $dir 1 1042 1043
Condition100%3/3
$opening and not -d $dir
!ll&&!rl&&r
6324101
MC/DC100%2/2
$opening and not -d $dir
$opening not -d $dir
Truth table100%3/3
A and not(B)
A= $openingB= not -d $dir
ABresult
0X0
100
111
617 1042 ▶ Carp::croak("Data::Shared: unpublished child storage exists at '$dir'; inspect it before retrying") if !$opening && -e $dir;
Branch: 1 branch
BranchTrueFalseTotal
if not $opening and -e $dir 1 1041 1042
Condition100%3/3
not $opening and -e $dir
!ll&&!rl&&r
4106311
MC/DC100%2/2
not $opening and -e $dir
not $opening -e $dir
Truth table100%3/3
not(A) and B
A= not $openingB= -e $dir
ABresult
0X0
100
111
618 1041 ▶ if (!$opening) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opening) 631 410 1041
619 631 ▶ push @$pending, $dir if $pending;
Branch: 1 branch
BranchTrueFalseTotal
if $pending 631 0 631
620 631 require File::Path;
621 631 File::Path::make_path($dir, { mode => 0700 });
622 }
623 }
624 # Existing children may be sealed even on a writable root.
625 my %mode = (opening => $opening, strict_readonly => $self->{strict_readonly},
626 pending_paths => $pending, cleanup => $cleanup, frozen_ok => $self->{_frozen_ok},
627 3158 ▶ replaying => $opening ? 1 : 0,
Branch: 2 branches
BranchTrueFalseTotal
$opening ? : 410 2748 3158
$opening ? : 410 2748 3158
628 sealed_ok => $opening ? 1 : 0);
629 3158 my $rt;
630 3158 ▶ if ($node->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'child'}) { } 24 3134 3158
631 my $comp = Data::Shared::Composite->new(root => $root, name => $addr, node => $node, dir => $dir,
632 24 path => [ @{ $self->{path} }, $addr ], readonly => $self->{readonly}, %mode);
633 24 $rt = { kind => 'composite', comp => $comp, addr => $addr };
634 } else {
635 my ($handle) = construct_node($dir, $self->{readonly}, $node->{resolved}, 'child', $node->{args},
636 3134 ▶ { %mode, frozen_ok => $mode{frozen_ok} || $mode{sealed_ok} });
Condition100%3/3
$mode{'frozen_ok'} || $mode{'sealed_ok'}
l!l&&r!l&&!r
24032729
MC/DC100%2/2
$mode{'frozen_ok'} || $mode{'sealed_ok'}
$mode{'frozen_ok'} $mode{'sealed_ok'}
Truth table100%3/3
A || B
A= $mode{'frozen_ok'}B= $mode{'sealed_ok'}
ABresult
1X1
011
000
637 my $record = { name => $addr, handle => $handle, entry => $node->{resolved}{entry}
638 3131 ▶ || { key => $node->{resolved}{class}, dist => 'unknown', path_class => 'map' }, dt => {} };
Condition50%1/2
$node->{'resolved'}{'entry'} || {'key', $node->{'resolved'}{'class'}, 'dist', 'unknown', 'path_class', 'map'}
l!l
31310
MC/DC0%0/1
$node->{'resolved'}{'entry'} || {'key', $node->{'resolved'}{'class'}, 'dist', 'unknown', 'path_class', 'map'}
$node->{'resolved'}{'entry'}
Truth table50%1/2
A
A= $node->{'resolved'}{'entry'}
Aresult
11
00
639 3131 $rt = { kind => 'leaf', record => $record, handle => $handle, addr => $addr };
640 }
641 # Walks and removal opens must not evict the caller's cached handles.
642 3155 ▶ return $rt if $cleanup || $self->{_walking};
Branch: 1 branch
BranchTrueFalseTotal
if $cleanup or $self->{"_walking"} 43 3112 3155
Condition100%3/3
$cleanup or $self->{"_walking"}
l!l&&r!l&&!r
3403112
MC/DC100%2/2
$cleanup or $self->{"_walking"}
$cleanup $self->{"_walking"}
Truth table100%3/3
A or B
A= $cleanupB= $self->{"_walking"}
ABresult
1X1
011
000
643 3112 $self->{cache}{$id} = $rt;
644 3112 $self->_touch($id);
645 3112 $self->_evict;
646 3112 return $rt;
647 }
648  
649 8452 ▶sub _existing_child {
Subroutine _existing_child: called CC=6 SCAR=18.0
650 8452 my ($self, $root, $addr) = @_;
651 8452 ▶ return undef unless $self->_valid_address($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_address($addr) 2 8450 8452
652 8450 my $id = $self->_reg_id($addr);
653 8450 ▶ return undef unless defined $id && $self->_reg_constructed($addr, $id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and $self->_reg_constructed($addr, $id) 5535 2915 8450
Condition100%3/3
defined $id and $self->_reg_constructed($addr, $id)
!ll&&!rl&&r
5522132915
MC/DC100%2/2
defined $id and $self->_reg_constructed($addr, $id)
defined $id $self->_reg_constructed($addr, $id)
Truth table100%3/3
A and B
A= defined $idB= $self->_reg_constructed($addr, $id)
ABresult
0X0
100
111
654 2915 ▶ if (my $rt = $self->{cache}{$id}) { $self->_touch($id) unless $self->{_walking}; return $rt }
Branch: 2 branches
BranchTrueFalseTotal
if (my $rt = $self->{"cache"}{$id}) 2500 415 2915
unless $self->{"_walking"} 2321 179 2500
655 409 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
656 409 my $current = $self->_reg_id($addr);
657 409 ▶ return undef unless defined $current && $self->_reg_constructed($addr, $current);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current and $self->_reg_constructed($addr, $current) 0 409 409
Condition33%1/3
defined $current and $self->_reg_constructed($addr, $current)
!ll&&!rl&&r
00409
MC/DC0%0/2
defined $current and $self->_reg_constructed($addr, $current)
defined $current $self->_reg_constructed($addr, $current)
Truth table33%1/3
A and B
A= defined $currentB= $self->_reg_constructed($addr, $current)
ABresult
0X0
100
111
658 409 return $self->_open_child($root, $addr, $current, 1);
659 415 }, undef, 1); # opens an existing child, writes nothing
660 }
661  
662 2875 ▶sub _ensure_child {
Subroutine _ensure_child: called CC=5 SCAR=16.1
663 2875 my ($self, $root, $addr) = @_;
664 2875 ▶ Carp::croak('Data::Shared: composite is read-only, cannot create a child') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 2875 2875
665 2875 ▶ Carp::croak("Data::Shared: invalid composite address '" . (defined $addr ? $addr : 'undef') . "' for $self->{node}{spec}")
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_valid_address($addr) 29 2846 2875
defined $addr ? : 29 0 29
666 unless $self->_valid_address($addr);
667 2846 my $existing = $self->_existing_child($root, $addr);
668 2845 ▶ return $existing if $existing;
Branch: 1 branch
BranchTrueFalseTotal
if $existing 90 2755 2845
669 2755 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=15 SCAR=27.2
670 2755 my $current = $self->_existing_child($root, $addr);
671 2755 ▶ return $current if $current;
Branch: 1 branch
BranchTrueFalseTotal
if $current 0 2755 2755
672 2755 my $old_id = $self->_reg_id($addr);
673 2755 my $old_marker = $self->{index}->get('c:' . $addr);
674 2755 my $was_parent = $self->_parent_exists($addr);
675 my $old_value = $was_parent && !$self->_is_index_parent
676 2755 ▶ ? Data::Shared::_dispatch_record('get', $self->{parent_record}, [$addr]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$was_parent && !$self->_is_index_parent ? : 6 2749 2755
Condition66%2/3
$was_parent and not $self->_is_index_parent
!ll&&!rl&&r
274906
MC/DC50%1/2
$was_parent and not $self->_is_index_parent
$was_parent not $self->_is_index_parent
Truth table66%2/3
A and not(B)
A= $was_parentB= not $self->_is_index_parent
ABresult
0X0
100
111
677 2755 my $count = $self->_child_count;
678 2755 ▶ my $id = defined $old_id ? $old_id : $self->_allocate_id;
Branch: 1 branch
BranchTrueFalseTotal
defined $old_id ? : 6 2749 2755
679 2749 my @pending;
680 my $rt;
681 2749 my $ok = eval {
682 2749 $rt = $self->_open_child($root, $addr, $id, 0, \@pending);
683 2746 $self->_index_put('c:' . $addr, "id:$id");
684 2745 $self->_parent_register($addr, $id);
685 2744 ▶ $self->_index_put('s:', $count + 1) unless defined $old_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_id 2740 4 2744
686 2744 ▶ $self->_index_put('a:' . $addr, $id) unless defined $old_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_id 2740 4 2744
687 2744 1;
688 };
689 2749 my $err = $@;
690 2749 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 5 2744 2749
691 5 $self->_forget($id);
692 5 undef $rt;
693 5 my $clean = eval {
694 5 ▶ defined $old_marker ? $self->_index_put('c:' . $addr, $old_marker) : $self->_index_remove('c:' . $addr);
Branch: 1 branch
BranchTrueFalseTotal
defined $old_marker ? : 1 4 5
695 5 ▶ $self->_index_remove('a:' . $addr) unless defined $old_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_id 3 2 5
696 5 ▶ $self->_parent_unregister($addr) unless $was_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $was_parent 3 2 5
697 5 ▶ Data::Shared::_dispatch_record('set', $self->{parent_record}, [$addr], $old_value)
Branch: 1 branch
BranchTrueFalseTotal
if $was_parent and not $self->_is_index_parent 2 3 5
Condition66%2/3
$was_parent and not $self->_is_index_parent
!ll&&!rl&&r
302
MC/DC50%1/2
$was_parent and not $self->_is_index_parent
$was_parent not $self->_is_index_parent
Truth table66%2/3
A and not(B)
A= $was_parentB= not $self->_is_index_parent
ABresult
0X0
100
111
698 if $was_parent && !$self->_is_index_parent;
699 5 $self->_index_put('s:', $count);
700 5 1;
701 };
702 5 ▶ my $rollback = $clean ? '' : $@;
Branch: 1 branch
BranchTrueFalseTotal
$clean ? : 5 0 5
703 5 my $files = Data::Shared::_cleanup_paths(\@pending);
704 5 ▶ _rethrow($err, length($rollback . $files) ? "$rollback $files" : '');
Branch: 1 branch
BranchTrueFalseTotal
length $rollback . $files ? : 0 5 5
705 }
706 2744 return $rt;
707 2755 }, 1);
708 }
709  
710 5537 ▶sub dispatch_verb {
Subroutine dispatch_verb: called CC=11 SCAR=24.0
Pod undocumented
711 5537 my ($self, $root, $verb, $rest, @args) = @_;
712 5537 $root = $self->_root($root);
713 5537 ▶ if (!@$rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rest) 11 5526 5537
714 11 ▶ return Data::Shared::Node->new($root, [ @{ $self->{path} } ]) if $verb eq 'get';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "get" 4 7 11
715 7 ▶ return 1 if $verb eq 'exists';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "exists" 3 4 7
716 4 Carp::croak("Data::Shared: cannot $verb a composite mount itself; address a child");
717 }
718 5526 my ($addr, @child_rest) = @$rest;
719 5526 ▶ if (!@child_rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@child_rest) 75 5451 5526
720 75 return $self->_verb_at_child($root, $verb, $addr, @args);
721 }
722 5451 my $rt;
723 5451 ▶ if ($verb eq 'exists' || $verb eq 'get' || $verb eq 'delete') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq 'exists' or $verb eq 'get' or $verb eq 'delete') { } 2604 2847 5451
Condition100%6/6
$verb eq "exists" or $verb eq "get" or $verb eq "delete"
l!l&&r!l&&!r
2578262847
$verb eq "exists" or $verb eq "get"
l!l&&r!l&&!r
5925192873
MC/DC100%3/3
$verb eq "exists" or $verb eq "get" or $verb eq "delete"
$verb eq "exists" $verb eq "get" $verb eq "delete"
Truth table100%4/4
A or B or C
A= $verb eq "exists"B= $verb eq "get"C= $verb eq "delete"
ABCresult
1XX1
01X1
0011
0000
724 2604 $rt = $self->_existing_child($root, $addr);
725 2596 ▶ return $verb eq 'exists' ? 0 : undef unless $rt;
Branch: 2 branches
BranchTrueFalseTotal
unless $rt 16 2580 2596
$verb eq 'exists' ? : 5 11 16
726 } else {
727 2847 $rt = $self->_ensure_child($root, $addr);
728 }
729 5386 ▶ if ($rt->{kind} eq 'composite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->{"kind"} eq "composite") 38 5348 5386
730 38 return $rt->{comp}->dispatch_verb($root, $verb, \@child_rest, @args);
731 }
732 5348 return Data::Shared::_dispatch_record($verb, $rt->{record}, \@child_rest, @args);
733 }
734  
735 75 ▶sub _verb_at_child {
Subroutine _verb_at_child: called CC=22 SCAR=34.4
736 75 my ($self, $root, $verb, $addr, @args) = @_;
737 75 ▶ my $key = $self->{node}{resolved}{entry}{key} || '';
Condition50%1/2
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
l!l
750
MC/DC0%0/1
$self->{'node'}{'resolved'}{'entry'}{'key'} || ''
$self->{'node'}{'resolved'}{'entry'}{'key'}
Truth table50%1/2
A
A= $self->{'node'}{'resolved'}{'entry'}{'key'}
Aresult
11
00
738 75 ▶ if ($verb eq 'exists') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "exists") 17 58 75
739 17 ▶ return 0 unless $self->_valid_address($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_address($addr) 2 15 17
740 15 ▶ return (defined $self->_reg_id($addr) || $self->_parent_exists($addr)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_reg_id($addr) || $self->_parent_exists($addr) ? : 6 9 15
Condition66%2/3
defined $self->_reg_id($addr) or $self->_parent_exists($addr)
l!l&&r!l&&!r
609
MC/DC50%1/2
defined $self->_reg_id($addr) or $self->_parent_exists($addr)
defined $self->_reg_id($addr) $self->_parent_exists($addr)
Truth table66%2/3
A or B
A= defined $self->_reg_id($addr)B= $self->_parent_exists($addr)
ABresult
1X1
011
000
741 }
742 58 ▶ if ($verb eq 'get') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "get") 22 36 58
743 22 ▶ if ($key eq 'sortedset' && $self->{parent_handle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "sortedset" and $self->{"parent_handle"}) 18 4 22
Condition66%2/3
$key eq "sortedset" and $self->{"parent_handle"}
!ll&&!rl&&r
4018
MC/DC50%1/2
$key eq "sortedset" and $self->{"parent_handle"}
$key eq "sortedset" $self->{"parent_handle"}
Truth table66%2/3
A and B
A= $key eq "sortedset"B= $self->{"parent_handle"}
ABresult
0X0
100
111
744 18 ▶ return undef unless $self->_valid_address($addr) && $self->_parent_exists($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_address($addr) and $self->_parent_exists($addr) 2 16 18
Condition66%2/3
$self->_valid_address($addr) and $self->_parent_exists($addr)
!ll&&!rl&&r
0216
MC/DC50%1/2
$self->_valid_address($addr) and $self->_parent_exists($addr)
$self->_valid_address($addr) $self->_parent_exists($addr)
Truth table66%2/3
A and B
A= $self->_valid_address($addr)B= $self->_parent_exists($addr)
ABresult
0X0
100
111
745 16 return Data::Shared::_dispatch_record('get', $self->{parent_record}, [$addr]);
746 }
747 4 ▶ return undef unless $self->_valid_address($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_address($addr) 0 4 4
748 4 ▶ return undef unless defined $self->_reg_id($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_reg_id($addr) 2 2 4
749 2 return Data::Shared::Node->new($root, [ @{ $self->{path} }, $addr ]);
750 }
751 36 ▶ if ($verb eq 'set' || $verb eq 'incr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "set" or $verb eq "incr") 18 18 36
Condition66%2/3
$verb eq "set" or $verb eq "incr"
l!l&&r!l&&!r
18018
MC/DC50%1/2
$verb eq "set" or $verb eq "incr"
$verb eq "set" $verb eq "incr"
Truth table66%2/3
A or B
A= $verb eq "set"B= $verb eq "incr"
ABresult
1X1
011
000
752 18 ▶ Carp::croak("Data::Shared: cannot $verb a composite child of $self->{node}{spec}; $verb a path inside it")
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "sortedset" 2 16 18
753 unless $key eq 'sortedset';
754 # Validate before setting the interrupted-mutation marker.
755 16 ▶ Carp::croak("Data::Shared: sortedset $verb needs a " . ($verb eq 'set' ? 'score' : 'delta'))
Branch: 2 branches
BranchTrueFalseTotal
unless @args 1 15 16
$verb eq 'set' ? : 1 0 1
756 unless @args;
757 15 ▶ Carp::croak('Data::Shared: composite is read-only') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 15 15
758 15 ▶ Carp::croak("Data::Shared: invalid composite address '" . (defined $addr ? $addr : 'undef') . "' for $self->{node}{spec}")
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_valid_address($addr) 0 15 15
defined $addr ? : 0 0 0
759 unless $self->_valid_address($addr);
760 15 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=11 SCAR=28.6
761 15 my $old_id = $self->_reg_id($addr);
762 15 my $was_parent = $self->_parent_exists($addr);
763 15 ▶ my $score = $was_parent ? Data::Shared::_dispatch_record('get', $self->{parent_record}, [$addr]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$was_parent ? : 7 8 15
764 15 my $count = $self->_child_count;
765 15 my $result;
766 15 my $ok = eval {
767 15 ▶ unless (defined $old_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $old_id) 8 7 15
768 8 my $id = $self->_allocate_id;
769 8 $self->_parent_register($addr, $id);
770 8 $self->_index_put('s:', $count + 1);
771 8 $self->_index_put('a:' . $addr, $id);
772 }
773 15 $result = Data::Shared::_dispatch_record($verb, $self->{parent_record}, [$addr], @args);
774 15 ▶ Carp::croak('Data::Shared: parent score operation failed') unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 15 15
775 15 1;
776 };
777 15 my $err = $@;
778 15 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 15 15
779 0 my $clean = eval {
780 0 ▶ $self->_index_remove('a:' . $addr) unless defined $old_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_id 0 0 0
781 0 $self->_index_put('s:', $count);
782 0 ▶ if ($was_parent) { Data::Shared::_dispatch_record('set', $self->{parent_record}, [$addr], $score) }
Branch: 1 branch
BranchTrueFalseTotal
if ($was_parent) { } 0 0 0
783 0 else { $self->_parent_unregister($addr) }
784 0 1;
785 };
786 0 ▶ _rethrow($err, $clean ? '' : $@);
Branch: 1 branch
BranchTrueFalseTotal
$clean ? : 0 0 0
787 }
788 # Registration pre-inserts score 0; report whether the address existed before this call.
789 15 ▶ return 1 if $verb eq 'set' && !$was_parent && !$result;
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "set" and not $was_parent and not $result 8 7 15
Condition66%4/6
$verb eq "set" and not $was_parent and not $result
!ll&&!rl&&r
708
$verb eq "set" and not $was_parent
!ll&&!rl&&r
078
MC/DC33%1/3
$verb eq "set" and not $was_parent and not $result
$verb eq "set" not $was_parent not $result
Truth table50%2/4
A and not(B) and not(C)
A= $verb eq "set"B= not $was_parentC= not $result
ABCresult
0XX0
10X0
1100
1111
790 7 return $result;
791 15 }, 1);
792 }
793 18 ▶ if ($verb eq 'delete') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "delete") 18 0 18
794 18 return $self->delete_subtree($root, $addr);
795 }
796 0 Carp::croak("Data::Shared: operation '$verb' is not supported at a composite child of $self->{node}{spec}");
797 }
798  
799 18 ▶sub dispatch_pushpop {
Subroutine dispatch_pushpop: called CC=5 SCAR=16.2
Pod undocumented
800 18 my ($self, $root, $which, $rest, @args) = @_;
801 18 $root = $self->_root($root);
802 18 ▶ Carp::croak("Data::Shared: cannot $which a composite mount itself; address a child") unless @$rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rest 2 16 18
803 16 my ($addr, @child_rest) = @$rest;
804 # A missing child is an empty one to pop, not one to create.
805 16 ▶ my $rt = $which eq 'pop' ? $self->_existing_child($root, $addr) : $self->_ensure_child($root, $addr);
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'pop' ? : 9 7 16
806 16 ▶ return undef unless $rt;
Branch: 1 branch
BranchTrueFalseTotal
unless $rt 5 11 16
807 11 ▶ if ($rt->{kind} eq 'composite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->{"kind"} eq "composite") 0 11 11
808 0 return $rt->{comp}->dispatch_pushpop($root, $which, \@child_rest, @args);
809 }
810 11 return Data::Shared::_dispatch_record_pushpop($which, $rt->{record}, \@child_rest, @args);
811 }
812  
813 86 ▶sub dispatch_call {
Subroutine dispatch_call: called CC=20 SCAR=30.0
Pod undocumented
814 86 my ($self, $root, $rest, $method, @args) = @_;
815 86 $root = $self->_root($root);
816 86 ▶ if (!@$rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rest) 51 35 86
817 return $self->$method(@args)
818 51 ▶ if $LIFECYCLE_METHOD{$method} && $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if $LIFECYCLE_METHOD{$method} and $self->can($method) 4 47 51
Condition66%2/3
$LIFECYCLE_METHOD{$method} and $self->can($method)
!ll&&!rl&&r
4704
MC/DC50%1/2
$LIFECYCLE_METHOD{$method} and $self->can($method)
$LIFECYCLE_METHOD{$method} $self->can($method)
Truth table66%2/3
A and B
A= $LIFECYCLE_METHOD{$method}B= $self->can($method)
ABresult
0X0
100
111
819 47 ▶ Carp::croak("Data::Shared: cannot freeze composite mount '$self->{name}' through call();"
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "freeze" 1 46 47
820 . " sealing the subtree would seal its child index too. Use \$root->freeze_all")
821 if $method eq 'freeze';
822 46 ▶ if ($self->{parent_handle} && $self->{parent_handle}->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"parent_handle"} and $self->{"parent_handle"}->can($method)) 30 16 46
Condition66%2/3
$self->{"parent_handle"} and $self->{"parent_handle"}->can($method)
!ll&&!rl&&r
01630
MC/DC50%1/2
$self->{"parent_handle"} and $self->{"parent_handle"}->can($method)
$self->{"parent_handle"} $self->{"parent_handle"}->can($method)
Truth table66%2/3
A and B
A= $self->{"parent_handle"}B= $self->{"parent_handle"}->can($method)
ABresult
0X0
100
111
823 30 return $self->{parent_handle}->$method(@args);
824 }
825 16 ▶ if ($method eq 'children') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "children") 2 14 16
826 2 my @c = $self->children_at($root, []);
827 2 ▶ return wantarray ? @c : \@c;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
828 }
829 14 ▶ if ($method eq 'child_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "child_count") 14 0 14
830 14 return $self->_child_count;
831 }
832 0 Carp::croak("Data::Shared: composite mount '" . $self->{name} . "' has no method '$method'");
833 }
834 35 my ($addr, @child_rest) = @$rest;
835 # Retiring must not construct a missing child.
836 35 ▶ my $retire = $method eq 'unlink' || $method eq 'destroy';
Condition100%3/3
$method eq 'unlink' || $method eq 'destroy'
l!l&&r!l&&!r
6524
MC/DC100%2/2
$method eq 'unlink' || $method eq 'destroy'
$method eq 'unlink' $method eq 'destroy'
Truth table100%3/3
A || B
A= $method eq 'unlink'B= $method eq 'destroy'
ABresult
1X1
011
000
837 35 ▶ return $self->delete_subtree($root, $addr) if $retire && !@child_rest;
Branch: 1 branch
BranchTrueFalseTotal
if $retire and not @child_rest 5 30 35
Condition100%3/3
$retire and not @child_rest
!ll&&!rl&&r
2465
MC/DC100%2/2
$retire and not @child_rest
$retire not @child_rest
Truth table100%3/3
A and not(B)
A= $retireB= not @child_rest
ABresult
0X0
100
111
838 30 ▶ my $rt = $self->{readonly} || $retire
Branch: 1 branch
BranchTrueFalseTotal
$self->{'readonly'} || $retire ? : 9 21 30
Condition100%3/3
$self->{"readonly"} or $retire
l!l&&r!l&&!r
3621
MC/DC100%2/2
$self->{"readonly"} or $retire
$self->{"readonly"} $retire
Truth table100%3/3
A or B
A= $self->{"readonly"}B= $retire
ABresult
1X1
011
000
839 ? $self->_existing_child($root, $addr) : $self->_ensure_child($root, $addr);
840 30 ▶ return undef if $retire && !$rt;
Branch: 1 branch
BranchTrueFalseTotal
if $retire and not $rt 4 26 30
Condition100%3/3
$retire and not $rt
!ll&&!rl&&r
2424
MC/DC100%2/2
$retire and not $rt
$retire not $rt
Truth table100%3/3
A and not(B)
A= $retireB= not $rt
ABresult
0X0
100
111
841 26 ▶ Carp::croak('Data::Shared: read-only composite has no constructed child at this path') unless $rt;
Branch: 1 branch
BranchTrueFalseTotal
unless $rt 2 24 26
842 24 ▶ if ($rt->{kind} eq 'composite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->{"kind"} eq "composite") 4 20 24
843 4 return $rt->{comp}->dispatch_call($root, \@child_rest, $method, @args);
844 }
845 # Native leaf unlink/destroy ignore record suffixes and remove the whole file.
846 20 ▶ Carp::croak("Data::Shared: '$method' retires a composite child, not the record"
Branch: 1 branch
BranchTrueFalseTotal
if $retire 2 18 20
847 . " at '$addr/" . join('/', @child_rest) . "' below it;"
848 . " use shared_delete to remove a record")
849 if $retire;
850 18 return Data::Shared::_dispatch_record_call($rt->{record}, \@child_rest, $method, @args);
851 }
852  
853 194 ▶sub children_at {
Subroutine children_at: called CC=5 SCAR=16.2
Pod undocumented
854 194 my ($self, $root, $rest) = @_;
855 # Must not require a live root: teardown lists children after its root may be gone.
856 194 ▶ if (!@$rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rest) 192 2 194
857 192 my @addrs = map { substr($_, 2) } grep { substr($_, 0, 2) eq 'a:' } $self->{index}->keys;
858 192 ▶ my @sorted = $self->_key_is_int ? (sort { $a <=> $b } @addrs) : (sort @addrs);
Branch: 1 branch
BranchTrueFalseTotal
$self->_key_is_int ? : 22 170 192
859 192 return @sorted;
860 }
861 2 $root = $self->_root($root);
862 2 my ($addr, @more) = @$rest;
863 2 my $rt = $self->_existing_child($root, $addr);
864 0 ▶ Carp::croak("Data::Shared: no composite child at '" . join('/', @{ $self->{path} }, $addr) . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $rt 0 2 2
865 unless $rt;
866 2 ▶ Carp::croak("Data::Shared: child '$addr' is not composite") unless $rt->{kind} eq 'composite';
Branch: 1 branch
BranchTrueFalseTotal
unless $rt->{"kind"} eq "composite" 0 2 2
867 2 return $rt->{comp}->children_at($root, \@more);
868 }
869  
870 10 ▶sub handle_at {
Subroutine handle_at: called CC=5 SCAR=16.7
Pod undocumented
871 10 my ($self, $root, $rest) = @_;
872 10 $root = $self->_root($root);
873 10 ▶ if (!@$rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rest) 2 8 10
874 2 return Data::Shared::Node->new($root, [ @{ $self->{path} } ]);
875 }
876 8 my ($addr, @more) = @$rest;
877 8 my $rt = $self->_existing_child($root, $addr);
878 0 ▶ Carp::croak("Data::Shared: no child at '" . join('/', @{ $self->{path} }, $addr) . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $rt 0 8 8
879 unless $rt;
880 8 ▶ if ($rt->{kind} eq 'composite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->{"kind"} eq "composite") 0 8 8
881 0 return $rt->{comp}->handle_at($root, \@more);
882 }
883 8 ▶ Carp::croak("Data::Shared: handle() path must name a leaf exactly (got extra components)") if @more;
Branch: 1 branch
BranchTrueFalseTotal
if @more 0 8 8
884 8 return $rt->{handle};
885 }
886  
887 # The caller owns registry, cache, and directory cleanup.
888 28 ▶sub _remove_child_storage {
Subroutine _remove_child_storage: called CC=3 SCAR=11.0
889 28 my ($rt) = @_;
890 28 ▶ if ($rt->{kind} eq 'composite') { $rt->{comp}->destroy }
Branch: 2 branches
BranchTrueFalseTotal
if ($rt->{'kind'} eq 'composite') { } 7 21 28
elsif ($rt->{'handle'}->can('unlink')) { } 21 0 21
891 21 elsif ($rt->{handle}->can('unlink')) { $rt->{handle}->unlink }
892 28 return;
893 }
894  
895 23 ▶sub delete_subtree {
Subroutine delete_subtree: called CC=3 SCAR=12.3
Pod undocumented
896 23 my ($self, $root, $addr) = @_;
897 23 $root = $self->_root($root);
898 23 ▶ Carp::croak('Data::Shared: composite is read-only, cannot delete') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 23 23
899 23 ▶ return undef unless $self->_valid_address($addr);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_address($addr) 0 23 23
900 23 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=22 SCAR=38.8
901 23 my $id = $self->_reg_id($addr);
902 23 my $was_parent = $self->_parent_exists($addr);
903 23 ▶ return undef unless defined $id || $was_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id or $was_parent 5 18 23
Condition66%2/3
defined $id or $was_parent
l!l&&r!l&&!r
1805
MC/DC50%1/2
defined $id or $was_parent
defined $id $was_parent
Truth table66%2/3
A or B
A= defined $idB= $was_parent
ABresult
1X1
011
000
904 18 my $cleanup_rt;
905 18 ▶ if (defined $id && $self->{node}{child}{child} && $self->_reg_constructed($addr, $id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)) 4 14 18
Condition83%5/6
defined $id and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)
!ll&&!rl&&r
1314
defined $id and $self->{"node"}{"child"}{"child"}
!ll&&!rl&&r
0135
MC/DC66%2/3
defined $id and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)
defined $id $self->{"node"}{"child"}{"child"} $self->_reg_constructed($addr, $id)
Truth table75%3/4
A and B and C
A= defined $idB= $self->{"node"}{"child"}{"child"}C= $self->_reg_constructed($addr, $id)
ABCresult
0XX0
10X0
1100
1111
906 4 $cleanup_rt = $self->_open_child($root, $addr, $id, 1, undef, 1);
907 }
908 18 my $marker = $self->{index}->get('c:' . $addr);
909 18 my $count = $self->_child_count;
910 my $score = $was_parent && !$self->_is_index_parent
911 18 ▶ ? Data::Shared::_dispatch_record('get', $self->{parent_record}, [$addr]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$was_parent && !$self->_is_index_parent ? : 18 0 18
Condition33%1/3
$was_parent and not $self->_is_index_parent
!ll&&!rl&&r
0018
MC/DC0%0/2
$was_parent and not $self->_is_index_parent
$was_parent not $self->_is_index_parent
Truth table33%1/3
A and not(B)
A= $was_parentB= not $self->_is_index_parent
ABresult
0X0
100
111
912 18 my $ok = eval {
913 18 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 18 0 18
914 # Remove readiness before registration; interruption then leaves a recoverable score-only child.
915 18 $self->_index_remove('c:' . $addr);
916 18 $self->_index_remove('a:' . $addr);
917 18 $self->_index_put('s:', $count - 1);
918 }
919 18 $self->_parent_unregister($addr);
920 18 1;
921 };
922 18 my $err = $@;
923 18 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 18 18
924 0 my $clean = eval {
925 0 ▶ $self->_index_put('c:' . $addr, $marker) if defined $marker;
Branch: 1 branch
BranchTrueFalseTotal
if defined $marker 0 0 0
926 0 ▶ $self->_index_put('a:' . $addr, $id) if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 0 0 0
927 0 $self->_index_put('s:', $count);
928 # Restoring an untouched record would fail on a frozen parent.
929 0 ▶ Data::Shared::_dispatch_record('set', $self->{parent_record}, [$addr], $score)
Branch: 1 branch
BranchTrueFalseTotal
if $was_parent and not $self->_is_index_parent and not $self->_parent_exists($addr) 0 0 0
Condition0%0/6
$was_parent and not $self->_is_index_parent and not $self->_parent_exists($addr)
!ll&&!rl&&r
000
$was_parent and not $self->_is_index_parent
!ll&&!rl&&r
000
MC/DC0%0/3
$was_parent and not $self->_is_index_parent and not $self->_parent_exists($addr)
$was_parent not $self->_is_index_parent not $self->_parent_exists($addr)
Truth table0%0/4
A and not(B) and not(C)
A= $was_parentB= not $self->_is_index_parentC= not $self->_parent_exists($addr)
ABCresult
0XX0
10X0
1100
1111
930 if $was_parent && !$self->_is_index_parent && !$self->_parent_exists($addr);
931 0 1;
932 };
933 0 ▶ _rethrow($err, $clean ? '' : $@);
Branch: 1 branch
BranchTrueFalseTotal
$clean ? : 0 0 0
934 }
935 18 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 18 0 18
936 18 ▶ my $rt = $self->_forget($id) || $cleanup_rt;
Condition100%3/3
$self->_forget($id) || $cleanup_rt
l!l&&r!l&&!r
1323
MC/DC100%2/2
$self->_forget($id) || $cleanup_rt
$self->_forget($id) $cleanup_rt
Truth table100%3/3
A || B
A= $self->_forget($id)B= $cleanup_rt
ABresult
1X1
011
000
937 18 ▶ if ($rt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt) 15 3 18
938 15 my $ok = eval {
939 15 _remove_child_storage($rt);
940 15 1;
941 };
942 15 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 15 15
943 0 my $why = Data::Shared::_strip_location($@);
944 0 Carp::croak("Data::Shared: subtree detached but retiring its storage"
945 . " failed: $why");
946 }
947 }
948 18 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dir"}) 9 9 18
949 9 my $cleanup = Data::Shared::_cleanup_paths(["$self->{dir}/child-$id"]);
950 9 ▶ Carp::croak("Data::Shared: subtree detached but cleanup failed: $cleanup") if length $cleanup;
Branch: 1 branch
BranchTrueFalseTotal
if length $cleanup 0 9 9
951 }
952 }
953 18 return 1;
954 23 }, 1);
955 }
956  
957 20 ▶sub destroy {
Subroutine destroy: called CC=4 SCAR=13.9
Pod undocumented
958 20 my ($self) = @_;
959 20 ▶ Carp::croak('Data::Shared: composite is read-only, cannot destroy') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 20 20
960 20 ▶ return 0 if defined $self->{dir} && !-d $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"dir"} and not -d $self->{"dir"} 0 20 20
Condition66%2/3
defined $self->{"dir"} and not -d $self->{"dir"}
!ll&&!rl&&r
2180
MC/DC0%0/2
defined $self->{"dir"} and not -d $self->{"dir"}
defined $self->{"dir"} not -d $self->{"dir"}
Truth table66%2/3
A and not(B)
A= defined $self->{"dir"}B= not -d $self->{"dir"}
ABresult
0X0
100
111
961 # Teardown may retry after removing its own index.
962 20 local $self->{_cleanup} = 1;
963 20 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=16 SCAR=27.9
964 20 my $frozen = $self->_index_frozen;
965 20 ▶ if (!$frozen) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $frozen) { } 12 8 20
966 # Set 'x:' first: waiters keep the old mapped index and could rebuild the subtree.
967 12 $self->_index_put('x:', 1);
968 12 for my $addr ($self->children_at(undef, [])) {
969 14 my $id = $self->_reg_id($addr);
970 14 my $rt = $self->{cache}{$id};
971 14 ▶ if (!$rt && $self->{node}{child}{child} && $self->_reg_constructed($addr, $id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $rt and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)) 1 13 14
Condition100%6/6
not $rt and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)
!ll&&!rl&&r
1211
not $rt and $self->{"node"}{"child"}{"child"}
!ll&&!rl&&r
752
MC/DC100%3/3
not $rt and $self->{"node"}{"child"}{"child"} and $self->_reg_constructed($addr, $id)
not $rt $self->{"node"}{"child"}{"child"} $self->_reg_constructed($addr, $id)
Truth table100%4/4
not(A) and B and C
A= not $rtB= $self->{"node"}{"child"}{"child"}C= $self->_reg_constructed($addr, $id)
ABCresult
0XX0
10X0
1100
1111
972 1 $rt = $self->_open_child($self->{root_weak}, $addr, $id, 1, undef, 1);
973 }
974 14 $self->_index_remove('a:' . $addr);
975 14 $self->_index_remove('c:' . $addr);
976 14 $self->_forget($id);
977 14 ▶ _remove_child_storage($rt) if $rt;
Branch: 1 branch
BranchTrueFalseTotal
if $rt 8 6 14
978 }
979 12 $self->_index_put('s:', 0);
980 } else {
981 # Frozen indexes already reject the mutation marker before any creation.
982 8 for my $rt (values %{ $self->{cache} }) {
983 5 _remove_child_storage($rt);
984 }
985 }
986 20 ▶ $self->{parent_handle}->unlink if $self->{parent_handle} && $self->{parent_handle}->can('unlink');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parent_handle"} and $self->{"parent_handle"}->can("unlink") 20 0 20
Condition33%1/3
$self->{"parent_handle"} and $self->{"parent_handle"}->can("unlink")
!ll&&!rl&&r
0020
MC/DC0%0/2
$self->{"parent_handle"} and $self->{"parent_handle"}->can("unlink")
$self->{"parent_handle"} $self->{"parent_handle"}->can("unlink")
Truth table33%1/3
A and B
A= $self->{"parent_handle"}B= $self->{"parent_handle"}->can("unlink")
ABresult
0X0
100
111
987 20 ▶ $self->{index}->unlink if $self->{index} && $self->{index}->can('unlink');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} and $self->{"index"}->can("unlink") 20 0 20
Condition33%1/3
$self->{"index"} and $self->{"index"}->can("unlink")
!ll&&!rl&&r
0020
MC/DC0%0/2
$self->{"index"} and $self->{"index"}->can("unlink")
$self->{"index"} $self->{"index"}->can("unlink")
Truth table33%1/3
A and B
A= $self->{"index"}B= $self->{"index"}->can("unlink")
ABresult
0X0
100
111
988 20 $self->{cache} = {};
989 20 $self->{lru_prev} = {};
990 20 $self->{lru_next} = {};
991 20 delete @{$self}{qw(lru_head lru_tail)};
992 20 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dir"}) 18 2 20
993 # Lock only the nested dirs: flock via a second descriptor of our held lock would block.
994 18 my @under;
995 18 ▶ if (opendir my $dh, $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $self->{"dir"}) 18 0 18
996 45 @under = map { "$self->{dir}/$_" }
997 18 ▶ grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition100%3/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
181845
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
998 18 closedir $dh;
999 }
1000 18 my $held = Data::Shared::_lock_composite_dirs(\@under);
1001 18 my $cleanup = Data::Shared::_cleanup_paths([$self->{dir}]);
1002 18 undef $held;
1003 18 ▶ Carp::croak("Data::Shared: cannot remove retired composite: $cleanup") if length $cleanup;
Branch: 1 branch
BranchTrueFalseTotal
if length $cleanup 1 17 18
1004 }
1005 19 return 1;
1006 20 });
1007 }
1008  
1009 5 ▶sub _rethrow {
Subroutine _rethrow: called CC=4 SCAR=16.1
1010 5 my ($err, $rollback) = @_;
1011 5 ▶ die $err if ref $err;
Branch: 1 branch
BranchTrueFalseTotal
if ref $err 0 5 5
1012 # Croak here, not in a shared helper, so Carp blames the composite's caller.
1013 5 ▶ Carp::croak(Data::Shared::_strip_location($err)
Branch: 1 branch
BranchTrueFalseTotal
defined $rollback && length $rollback ? : 0 5 5
Condition33%1/3
defined $rollback and length $rollback
!ll&&!rl&&r
050
MC/DC0%0/2
defined $rollback and length $rollback
defined $rollback length $rollback
Truth table33%1/3
A and B
A= defined $rollbackB= length $rollback
ABresult
0X0
100
111
1014 . (defined $rollback && length $rollback ? " (rollback: $rollback)" : ''));
1015 }
1016  
1017 64 ▶sub _sync_once {
Subroutine _sync_once: called CC=3 SCAR=11.0
1018 64 my ($rt) = @_;
1019 64 ▶ return $rt->{comp}->sync if $rt->{kind} eq 'composite';
Branch: 1 branch
BranchTrueFalseTotal
if $rt->{"kind"} eq "composite" 2 62 64
1020 62 ▶ return 0 unless $rt->{handle}->can('sync');
Branch: 1 branch
BranchTrueFalseTotal
unless $rt->{"handle"}->can("sync") 0 62 62
1021 62 $rt->{handle}->sync;
1022 62 return 1;
1023 }
1024  
1025 12 ▶sub sync {
Subroutine sync: called CC=8 SCAR=21.2
Pod undocumented
1026 12 my ($self) = @_;
1027 12 my $n = 0;
1028 # Sealed children need no _frozen_ok: _existing_child opens with opening=1,
1029 # which already permits them.
1030 12 local $self->{_walking} = 1;
1031 12 my $root = $self->{root_weak};
1032 12 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'dir'}) { } 11 1 12
1033 # One child open at a time, or a large composite runs out of descriptors.
1034 11 for my $addr ($self->children_at(undef, [])) {
1035 63 ▶ my $rt = $self->_existing_child($root, $addr) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rt = $self->_existing_child($root, $addr) or next 63 0 63
1036 63 $n += _sync_once($rt);
1037 }
1038 } else {
1039 # Anonymous roots can flush only children mapped in this process.
1040 1 $n += _sync_once($_) for values %{ $self->{cache} };
1041 }
1042 # Native sync returns nothing; count the call regardless of its result.
1043 12 for my $h ($self->{parent_handle}, $self->{index}) {
1044 24 ▶ next unless $h && $h->can('sync');
Branch: 1 branch
BranchTrueFalseTotal
unless $h and $h->can("sync") 0 24 24
Condition33%1/3
$h and $h->can("sync")
!ll&&!rl&&r
0024
MC/DC0%0/2
$h and $h->can("sync")
$h $h->can("sync")
Truth table33%1/3
A and B
A= $hB= $h->can("sync")
ABresult
0X0
100
111
1045 24 $h->sync;
1046 24 $n++;
1047 }
1048 12 return $n;
1049 }
1050  
1051 7029 ▶sub _index_frozen {
Subroutine _index_frozen: called CC=4 SCAR=14.9
1052 7029 my ($self) = @_;
1053 7029 ▶ return $self->{index} && $self->{index}->can('frozen') && $self->{index}->frozen ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'index'} && $self->{'index'}->can('frozen') && $self->{'index'}->frozen ? : 24 7005 7029
Condition50%3/6
$self->{"index"} and $self->{"index"}->can("frozen") and $self->{"index"}->frozen
!ll&&!rl&&r
0700524
$self->{"index"} and $self->{"index"}->can("frozen")
!ll&&!rl&&r
007029
MC/DC33%1/3
$self->{"index"} and $self->{"index"}->can("frozen") and $self->{"index"}->frozen
$self->{"index"} $self->{"index"}->can("frozen") $self->{"index"}->frozen
Truth table50%2/4
A and B and C
A= $self->{"index"}B= $self->{"index"}->can("frozen")C= $self->{"index"}->frozen
ABCresult
0XX0
10X0
1100
1111
1054 }
1055  
1056 # The class of the first level that cannot reopen read-only, or undef.
1057 107 ▶sub _unsealable {
Subroutine _unsealable: called CC=3 SCAR=11.0
1058 107 my ($self) = @_;
1059 107 ▶ for (my $node = $self->{node}; $node; $node = $node->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 217 105 322
1060 217 ▶ return $node->{resolved}{class} unless Data::Shared::Storage::readonly_capable($node->{resolved});
Branch: 1 branch
BranchTrueFalseTotal
unless Data::Shared::Storage::readonly_capable($node->{"resolved"}) 2 215 217
1061 }
1062 105 return;
1063 }
1064  
1065 # The index is frozen last, so a frozen index means the subtree is sealed.
1066 103 ▶sub frozen {
Subroutine frozen: called CC=3 SCAR=11.0
Pod undocumented
1067 103 my ($self) = @_;
1068 103 ▶ return $self->_index_frozen && !defined $self->_unsealable ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_index_frozen && !defined($self->_unsealable) ? : 9 94 103
Condition100%3/3
$self->_index_frozen and not defined $self->_unsealable
!ll&&!rl&&r
9319
MC/DC100%2/2
$self->_index_frozen and not defined $self->_unsealable
$self->_index_frozen not defined $self->_unsealable
Truth table100%3/3
A and not(B)
A= $self->_index_frozenB= not defined $self->_unsealable
ABresult
0X0
100
111
1069 }
1070  
1071 95 ▶sub freeze {
Subroutine freeze: called CC=2 SCAR=7.0
Pod undocumented
1072 95 my ($self) = @_;
1073 95 ▶ Carp::croak("Data::Shared: cannot freeze a read-only composite") if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 95 95
1074 95 ▶ return $self->_with_lock(sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1075 95 my $root = $self->{root_weak};
1076 95 my $n = 0;
1077 # Earlier freezes may have sealed uncached children; see sync.
1078 95 local $self->{_walking} = 1;
1079 95 for my $addr ($self->children_at(undef, [])) {
1080 156 ▶ my $rt = $self->_existing_child($root, $addr) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rt = $self->_existing_child($root, $addr) or next 156 0 156
1081 156 ▶ if ($rt->{kind} eq 'composite') { $n += $rt->{comp}->freeze }
Branch: 1 branch
BranchTrueFalseTotal
if ($rt->{'kind'} eq 'composite') { } 2 154 156
1082 154 else { $n += _freeze_once($rt->{handle}) }
1083 }
1084 95 $n += _freeze_once($self->{parent_handle});
1085 95 $n += _freeze_once($self->{index});
1086 95 return $n;
1087 95 });
1088 }
1089  
1090 13 ▶sub unlink {
Subroutine unlink: called CC=1 SCAR=0.0
Pod undocumented
1091 13 my ($self) = @_;
1092 13 return $self->destroy;
1093 }
1094  
1095 15 ▶sub stats {
Subroutine stats: called CC=4 SCAR=13.9
Pod undocumented
1096 15 my ($self) = @_;
1097 15 my %children;
1098 15 for my $id (sort { $a <=> $b } keys %{ $self->{cache} }) {
1099 47 my $rt = $self->{cache}{$id};
1100 $children{ $rt->{addr} } = $rt->{kind} eq 'composite' ? $rt->{comp}->stats
1101 47 ▶ : ($rt->{handle}->can('stats') ? $rt->{handle}->stats : { class => ref $rt->{handle} });
Branch: 2 branches
BranchTrueFalseTotal
$rt->{'kind'} eq 'composite' ? : 3 44 47
$rt->{'handle'}->can('stats') ? : 44 0 44
1102 }
1103 return {
1104 class => 'Data::Shared::Composite',
1105 spec => $self->{node}{spec},
1106 children => $self->_child_count,
1107 15 open => scalar keys %{ $self->{cache} },
1108 child_stats => \%children,
1109 };
1110 }
1111  
1112 39 1;
1113  
1114 __END__
« blib/lib/Data/Shared/Manifest.pm ↑ Summary blib/lib/Data/Shared/Registry.pm »