blib/lib/Data/Shared.pm

filter: Statementstmt 98.7% 998 / 1011 Branchbran 87.6% 496 / 566 Conditioncond 74.6% 224 / 300 MC/DCmcdc 55.8% 96 / 172 Subroutinesub 100% 146 / 146 Podpod 63.3% 19 / 30 totaltotal 88.9% 1979 / 2225 CC 407 SCAR 23.2
CC
407
Cov
92%
_recipe
40.1
__ANON__
31.5
_compiled_code
20.0
CRAP 10.1
« blib/lib/Data/Shared/Registry.pm ↑ Summary blib/lib/Data/Shared/Adapter/Keyed.pm »
1 package Data::Shared;
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  
5 39 our $VERSION = '0.02';
6  
7 # Report mount-time errors at the caller across the manifest lock.
8 39 our @CARP_NOT = qw(Data::Shared Data::Shared::Manifest Data::Shared::Storage
9 Data::Shared::Composite);
10  
11 39 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use Scalar::Util qw(blessed refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 our @EXPORT_OK = qw(
16 shared_get shared_set shared_delete shared_exists shared_incr
17 shared_call shared_push shared_pop
18 shareda_get shareda_set shareda_delete shareda_exists shareda_incr
19 shareda_call shareda_push shareda_pop
20 shared_compile
21 sharedc_get sharedc_set sharedc_delete sharedc_exists sharedc_incr
22 sharedc_call sharedc_push sharedc_pop
23 shared_node shared_children
24 );
25  
26 39 require XSLoader;
27 39 XSLoader::load(__PACKAGE__, $VERSION);
28  
29 39 ▶use Data::Shared::Registry ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 39 ▶use Data::Shared::Compiled ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 39 ▶use Data::Shared::Node ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 39 ▶use Data::Shared::Composite ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 39 ▶use Data::Shared::Manifest ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 39 ▶use Data::Shared::Storage ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 39 ▶use Data::Shared::Adapter::Map ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 39 ▶use Data::Shared::Adapter::Set ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 39 ▶use Data::Shared::Adapter::Indexed ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 39 ▶use Data::Shared::Adapter::Queue ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 39 ▶use Data::Shared::Adapter::Sketch ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40 39 ▶use Data::Shared::Adapter::Sync ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 39 my %ADAPTER_FOR = (
43 map => 'Data::Shared::Adapter::Map',
44 set => 'Data::Shared::Adapter::Set',
45 indexed => 'Data::Shared::Adapter::Indexed',
46 queue => 'Data::Shared::Adapter::Queue',
47 sketch => 'Data::Shared::Adapter::Sketch',
48 sync => 'Data::Shared::Adapter::Sync',
49 );
50  
51 1 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: called CC=1 SCAR=0.0
52  
53 37 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
54 37 my $class = shift;
55 37 my @args = @_;
56 37 for my $a (@args) {
57 195 ▶ if ($a eq ':keywords') {
Branch: 1 branch
BranchTrueFalseTotal
if ($a eq ":keywords") 1 194 195
58 1 Carp::croak("Data::Shared: ':keywords' syntax is not available; use the shared_* functions");
59 }
60 }
61 36 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 33 3 36
62 33 $class->export_to_level(1, $class, @args);
63 }
64 }
65  
66 72849 ▶sub _parse_string_path {
Subroutine _parse_string_path: called CC=7 SCAR=19.5
67 72849 my ($path) = @_;
68 72849 ▶ Carp::croak("Data::Shared: path must be a defined string") unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 13 72836 72849
69 72836 ▶ Carp::croak("Data::Shared: path must not be a reference") if ref $path;
Branch: 1 branch
BranchTrueFalseTotal
if ref $path 7 72829 72836
70 72829 ▶ return [] if $path eq '' || $path eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "" or $path eq "/" 101 72728 72829
Condition100%3/3
$path eq "" or $path eq "/"
l!l&&r!l&&!r
416072728
MC/DC100%2/2
$path eq "" or $path eq "/"
$path eq "" $path eq "/"
Truth table100%3/3
A or B
A= $path eq ""B= $path eq "/"
ABresult
1X1
011
000
71 72728 $path =~ s{^/+}{};
72 72728 ▶ return [] if $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "" 0 72728 72728
73 # split drops trailing empty fields, so only an internal '//' needs the grep.
74 72728 ▶ return [ split m{/}, $path ] if index($path, '//') < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($path, "//") == -1 72694 34 72728
75 34 return [ grep { length } split m{/}, $path ];
76 }
77  
78 611 ▶sub _parse_array_path {
Subroutine _parse_array_path: called CC=5 SCAR=16.1
79 611 my ($aref) = @_;
80 611 ▶ Carp::croak("Data::Shared: array path must be an ARRAY reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $aref eq "ARRAY" 7 604 611
81 unless ref $aref eq 'ARRAY';
82 604 for my $c (@$aref) {
83 1097 ▶ return _check_components([ @$aref ]) unless defined $c && !ref $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c and not ref $c 39 1058 1097
Condition100%3/3
defined $c and not ref $c
!ll&&!rl&&r
3271058
MC/DC100%2/2
defined $c and not ref $c
defined $c not ref $c
Truth table100%3/3
A and not(B)
A= defined $cB= not ref $c
ABresult
0X0
100
111
84 }
85 565 return $aref;
86 }
87  
88 # Replaces overloaded components in place: callers must pass a fresh array.
89 127 ▶sub _check_components {
Subroutine _check_components: called CC=11 SCAR=24.0
90 127 my ($components) = @_;
91 127 for my $c (@$components) {
92 248 ▶ next if defined $c && !ref $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c and not ref $c 203 45 248
Condition100%3/3
defined $c and not ref $c
!ll&&!rl&&r
378203
MC/DC100%2/2
defined $c and not ref $c
defined $c not ref $c
Truth table100%3/3
A and not(B)
A= defined $cB= not ref $c
ABresult
0X0
100
111
93 45 ▶ my $stringify = defined $c && overload::Method($c, '""');
Condition100%3/3
defined $c && overload::Method($c, '""')
!ll&&!rl&&r
3726
MC/DC100%2/2
defined $c && overload::Method($c, '""')
defined $c overload::Method($c, '""')
Truth table100%3/3
A && B
A= defined $cB= overload::Method($c, '""')
ABresult
0X0
100
111
94 45 ▶ Carp::croak("Data::Shared: path component must be a defined string") unless $stringify;
Branch: 1 branch
BranchTrueFalseTotal
unless $stringify 39 6 45
95 6 my $string = $stringify->($c, undef, '');
96 # Bound overload chains explicitly; interpolation can hide undef or self-return.
97 6 ▶ for (my $depth = 0; ref $string; $depth++) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $string) 21 4 25
98 21 ▶ my $inner = overload::Method($string, '""') or last;
Branch: 1 branch
BranchTrueFalseTotal
my $inner = overload::Method($string, "\"\"") or last 20 1 21
99 20 ▶ Carp::croak("Data::Shared: path component must be a defined string") if $depth >= 16;
Branch: 1 branch
BranchTrueFalseTotal
if $depth >= 16 1 19 20
100 19 $string = $inner->($string, undef, '');
101 }
102 5 ▶ Carp::croak("Data::Shared: path component must be a defined string")
Branch: 1 branch
BranchTrueFalseTotal
if not defined $string or ref $string 2 3 5
Condition100%3/3
not defined $string or ref $string
l!l&&r!l&&!r
113
MC/DC100%2/2
not defined $string or ref $string
not defined $string ref $string
Truth table100%3/3
not(A) or B
A= not defined $stringB= ref $string
ABresult
1X1
011
000
103 if !defined $string || ref $string;
104 3 $c = $string;
105 }
106 85 return $components;
107 }
108  
109 87203 ▶sub _check_root {
Subroutine _check_root: called CC=4 SCAR=13.9
110 87203 my ($root) = @_;
111 87203 ▶ return $root if ref($root) eq 'Data::Shared';
Branch: 1 branch
BranchTrueFalseTotal
if ref $root eq "Data::Shared" 87198 5 87203
112 5 ▶ Carp::croak("Data::Shared: first argument must be a Data::Shared root")
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($root) and $root->isa("Data::Shared") 1 4 5
Condition66%2/3
builtin::blessed($root) and $root->isa("Data::Shared")
!ll&&!rl&&r
104
MC/DC50%1/2
builtin::blessed($root) and $root->isa("Data::Shared")
builtin::blessed($root) $root->isa("Data::Shared")
Truth table66%2/3
A and B
A= builtin::blessed($root)B= $root->isa("Data::Shared")
ABresult
0X0
100
111
113 unless blessed($root) && $root->isa('Data::Shared');
114 4 return $root;
115 }
116  
117 73290 ▶sub _resolve {
Subroutine _resolve: called CC=6 SCAR=17.9
118 73290 my ($root, $components) = @_;
119 73290 my $mounts = $root->{mounts};
120 73290 ▶ if (!$root->{_nest_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $root->{'_nest_depth'}) { } 72940 350 73290
121 72940 ▶ if (my $m = $mounts->{ $components->[0] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $$mounts{$components->[0]}) 72831 109 72940
122 72831 my @rest = @{$components}[1 .. $#$components];
123 72831 return ($components->[0], $m, \@rest);
124 }
125 } else {
126 # Longest prefix wins; no mount name is deeper than _nest_depth.
127 350 my $n = @$components;
128 350 ▶ $n = $root->{_nest_depth} if $root->{_nest_depth} < $n;
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"_nest_depth"} < $n 25 325 350
129 350 ▶ for (; $n >= 1; $n--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 1) 686 0 686
130 686 my $candidate = join('/', @{$components}[0 .. $n - 1]);
131 686 ▶ if (my $m = $mounts->{$candidate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $mounts->{$candidate}) 350 336 686
132 350 my @rest = @{$components}[$n .. $#$components];
133 350 return ($candidate, $m, \@rest);
134 }
135 }
136 }
137 109 my $shown = '/' . join('/', @$components);
138 109 Carp::croak("Data::Shared: no mount matches path '$shown' (mounts: "
139 . join(', ', sort keys %$mounts) . ")");
140 }
141  
142 25712 ▶sub _verb_code {
Subroutine _verb_code: called CC=3 SCAR=11.1
143 25712 my ($mount, $verb) = @_;
144 25712 ▶ my $dt = $mount->{dt} ||= {};
Condition50%1/2
$mount->{"dt"} ||= {}
l!l
257120
MC/DC0%0/1
$mount->{"dt"} ||= {}
$mount->{"dt"}
Truth table50%1/2
A
A= $mount->{"dt"}
Aresult
11
00
145 25712 ▶ return $dt->{$verb} if exists $dt->{$verb};
Branch: 1 branch
BranchTrueFalseTotal
if exists $dt->{$verb} 0 25712 25712
146 25712 my $adapter = _adapter_for($mount->{entry});
147 25712 my $code = $adapter->make_verb($verb, $mount->{handle}, $mount->{entry});
148 25712 $dt->{$verb} = $code;
149 25712 _fast_desc($mount, $verb);
150 25712 return $code;
151 }
152  
153 # What Shared.xs calls for this verb in place of the closure, cached beside it.
154 26047 ▶sub _fast_desc {
Subroutine _fast_desc: called CC=3 SCAR=11.0
155 26047 my ($mount, $verb) = @_;
156 26047 ▶ my $fast = $mount->{fast} ||= {};
Condition100%2/2
$mount->{"fast"} ||= {}
l!l
981516232
MC/DC100%1/1
$mount->{"fast"} ||= {}
$mount->{"fast"}
Truth table100%2/2
A
A= $mount->{"fast"}
Aresult
11
00
157 26047 ▶ return $fast->{$verb} if exists $fast->{$verb};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fast->{$verb} 107 25940 26047
158 return $fast->{$verb} = _adapter_for($mount->{entry})
159 25940 ->fast_verb($verb, $mount->{handle}, $mount->{entry});
160 }
161  
162 # Prefixed: push and pop share $mount->{dt} with the verbs.
163 39 my %PP_CACHE_KEY = (push => '_pp_push', pop => '_pp_pop');
164  
165 58 ▶sub _pushpop_code {
Subroutine _pushpop_code: called CC=4 SCAR=14.0
166 58 my ($mount, $which) = @_;
167 58 my $key = $PP_CACHE_KEY{$which};
168 58 ▶ my $dt = $mount->{dt} ||= {};
Condition50%1/2
$mount->{"dt"} ||= {}
l!l
580
MC/DC0%0/1
$mount->{"dt"} ||= {}
$mount->{"dt"}
Truth table50%1/2
A
A= $mount->{"dt"}
Aresult
11
00
169 58 ▶ return $dt->{$key} if exists $dt->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $dt->{$key} 0 58 58
170 58 my $adapter = _adapter_for($mount->{entry});
171 58 ▶ my $maker = $which eq 'push' ? 'make_push' : 'make_pop';
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'push' ? : 37 21 58
172 58 my $code = $adapter->$maker($mount->{handle}, $mount->{entry});
173 58 $dt->{$key} = $code;
174 58 return $code;
175 }
176  
177 52268 ▶sub _adapter_for {
Subroutine _adapter_for: called CC=3 SCAR=12.5
178 52268 my ($entry) = @_;
179 52268 ▶ my $pc = $entry->{path_class} || 'map';
Condition50%1/2
$entry->{'path_class'} || 'map'
l!l
522680
MC/DC0%0/1
$entry->{'path_class'} || 'map'
$entry->{'path_class'}
Truth table50%1/2
A
A= $entry->{'path_class'}
Aresult
11
00
180 52268 ▶ return $ADAPTER_FOR{$pc} || $ADAPTER_FOR{map};
Condition33%1/3
$ADAPTER_FOR{$pc} || $ADAPTER_FOR{'map'}
l!l&&r!l&&!r
5226800
MC/DC0%0/2
$ADAPTER_FOR{$pc} || $ADAPTER_FOR{'map'}
$ADAPTER_FOR{$pc} $ADAPTER_FOR{'map'}
Truth table33%1/3
A || B
A= $ADAPTER_FOR{$pc}B= $ADAPTER_FOR{'map'}
ABresult
1X1
011
000
181 }
182  
183 39 my %MUTATING = map { $_ => 1 } qw(set delete incr push pop);
184  
185 39 my $CALL_NEEDS_MOUNT = 'Data::Shared: a call path must name a mount';
186  
187 # Strip only the final location; a message may contain its own " at ...".
188 93 ▶sub _strip_location {
Subroutine _strip_location: called CC=2 SCAR=7.0
189 93 my ($msg) = @_;
190 93 ▶ return $msg if ref $msg;
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg 0 93 93
191 93 $msg =~ s/\A(.*[^\s])\s*\bat .+ line \d+\.?\s*\z/$1/s;
192 93 return $msg;
193 }
194  
195 121 ▶sub _root_verb {
Subroutine _root_verb: called CC=3 SCAR=11.0
196 121 my ($verb, $root) = @_;
197 121 ▶ return $root if $verb eq 'get';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "get" 33 88 121
198 88 ▶ return 1 if $verb eq 'exists';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "exists" 20 68 88
199 68 Carp::croak("Data::Shared: cannot $verb the root");
200 }
201  
202 # Callers must test $root->{readonly} first; this does not.
203 1246 ▶sub _refuse_readonly {
Subroutine _refuse_readonly: called CC=2 SCAR=6.9
204 1246 my ($root, $verb) = @_;
205 1246 ▶ Carp::croak("Data::Shared: root is read-only, cannot $verb") if $MUTATING{$verb};
Branch: 1 branch
BranchTrueFalseTotal
if $MUTATING{$verb} 75 1171 1246
206 1171 return;
207 }
208  
209 80491 ▶sub _dispatch_record {
Subroutine _dispatch_record: called CC=5 SCAR=16.1
210 80491 my ($verb, $mount, $rest, @args) = @_;
211 80491 ▶ my $code = $mount->{dt}{$verb} // _verb_code($mount, $verb);
Condition100%3/3
$mount->{"dt"}{$verb} // _verb_code($mount, $verb)
l!l&&r!l&&!r
547792568626
MC/DC100%2/2
$mount->{"dt"}{$verb} // _verb_code($mount, $verb)
$mount->{"dt"}{$verb} _verb_code($mount, $verb)
Truth table100%3/3
A // B
A= $mount->{"dt"}{$verb}B= _verb_code($mount, $verb)
ABresult
1X1
011
000
212 my $r = $code ? $code->($rest, @args)
213 : _adapter_for($mount->{entry})
214 80491 ▶ ->perform($verb, $mount->{handle}, $mount->{entry}, $rest, @args);
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 80465 26 80491
215 79961 ▶ return $verb eq 'exists' ? ($r ? 1 : 0) : $r;
Branch: 2 branches
BranchTrueFalseTotal
$verb eq 'exists' ? : 9993 69968 79961
$r ? : 2976 7017 9993
216 }
217  
218 68 ▶sub _dispatch_record_pushpop {
Subroutine _dispatch_record_pushpop: called CC=4 SCAR=13.9
219 68 my ($which, $mount, $rest, @args) = @_;
220 68 ▶ my $code = $mount->{dt}{ $PP_CACHE_KEY{$which} } // _pushpop_code($mount, $which);
Condition100%3/3
$mount->{"dt"}{$PP_CACHE_KEY{$which}} // _pushpop_code($mount, $which)
l!l&&r!l&&!r
10517
MC/DC100%2/2
$mount->{"dt"}{$PP_CACHE_KEY{$which}} // _pushpop_code($mount, $which)
$mount->{"dt"}{$PP_CACHE_KEY{$which}} _pushpop_code($mount, $which)
Truth table100%3/3
A // B
A= $mount->{"dt"}{$PP_CACHE_KEY{$which}}B= _pushpop_code($mount, $which)
ABresult
1X1
011
000
221 68 ▶ if (!$code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 7 61 68
222 7 my $adapter = _adapter_for($mount->{entry});
223 7 ▶ my $method = $which eq 'push' ? 'perform_push' : 'perform_pop';
Branch: 1 branch
BranchTrueFalseTotal
$which eq 'push' ? : 3 4 7
224 7 return $adapter->$method($mount->{handle}, $mount->{entry}, $rest, @args);
225 }
226 61 return $code->($rest, @args);
227 }
228  
229 # A leaf's native unlink/destroy removes its whole file: unmount at a mount,
230 # refuse below one. Returns the unmount result, or () to carry on.
231 16 ▶sub _retire_leaf {
Subroutine _retire_leaf: called CC=4 SCAR=13.9
232 16 my ($root, $components, $method, $name, $mount, $rest) = @_;
233 16 ▶ ($name, $mount, $rest) = _resolve($root, $components) unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 15 16
234 16 ▶ return ($root->unmount($name, unlink => 1)) unless @$rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rest 5 11 16
235 Carp::croak("Data::Shared: '$method' retires a mount or a composite child,"
236 . " not the record at '/" . join('/', @$components) . "';"
237 . " use shared_delete to remove a record")
238 11 ▶ unless $mount->{composite};
Branch: 1 branch
BranchTrueFalseTotal
unless $mount->{"composite"} 0 11 11
239 11 return ();
240 }
241  
242 214 ▶sub _dispatch_record_call {
Subroutine _dispatch_record_call: called CC=4 SCAR=13.9
243 214 my ($record, $rest, $method, @args) = @_;
244 214 my $handle = $record->{handle};
245 # Cached per mount: a handle's methods do not change while it is mounted.
246 214 ▶ my $code = $record->{can}{$method} ||= $handle->can($method);
Condition100%3/3
$record->{"can"}{$method} ||= $handle->can($method)
l!l&&r!l&&!r
819214
MC/DC100%2/2
$record->{"can"}{$method} ||= $handle->can($method)
$record->{"can"}{$method} $handle->can($method)
Truth table100%3/3
A ||= B
A= $record->{"can"}{$method}B= $handle->can($method)
ABresult
1X1
011
000
247 214 ▶ unless ($code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 14 200 214
248 14 ▶ my $label = defined $record->{name} ? "mount '$record->{name}'" : 'handle';
Branch: 1 branch
BranchTrueFalseTotal
defined $record->{'name'} ? : 14 0 14
249 14 Carp::croak("Data::Shared: $label (" . ref($handle) . ") has no method '$method'");
250 }
251 200 return $handle->$code(@$rest, @args);
252 }
253  
254 7949 ▶sub _construct_with {
Subroutine _construct_with: called CC=2 SCAR=6.9
255 7949 my ($dir, $readonly, $resolved, $name, $args, $mode) = @_;
256 my $tmp = bless { dir => $dir, mounts => {}, readonly => $readonly ? 1 : 0,
257 _opening => $mode->{opening}, strict_readonly => $mode->{strict_readonly},
258 _cleanup => $mode->{cleanup}, _frozen_ok => $mode->{frozen_ok},
259 7949 ▶ _pending_paths => $mode->{pending_paths} }, __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
$readonly ? : 246 7703 7949
260 7949 return $tmp->_construct($resolved, $name, @$args);
261 }
262  
263 72393 ▶sub _dispatch {
Subroutine _dispatch: called CC=4 SCAR=13.9
264 72393 my ($verb, $root, $components, @args) = @_;
265 72393 _check_root($root);
266 72392 ▶ return _root_verb($verb, $root) unless @$components;
Branch: 1 branch
BranchTrueFalseTotal
unless @$components 106 72286 72392
267 72286 ▶ _refuse_readonly($root, $verb) if $root->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"readonly"} 1188 71098 72286
268 72257 my (undef, $mount, $rest) = _resolve($root, $components);
269 72153 ▶ if (my $comp = $mount->{composite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $mount->{"composite"}) 5409 66744 72153
270 5409 return $comp->dispatch_verb($root, $verb, $rest, @args);
271 }
272 66744 return _dispatch_record($verb, $mount, $rest, @args);
273 }
274  
275 75 ▶sub _dispatch_pushpop {
Subroutine _dispatch_pushpop: called CC=4 SCAR=13.9
276 75 my ($which, $root, $components, @args) = @_;
277 75 _check_root($root);
278 75 ▶ return _root_verb($which, $root) unless @$components;
Branch: 1 branch
BranchTrueFalseTotal
unless @$components 0 75 75
279 75 ▶ _refuse_readonly($root, $which) if $root->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"readonly"} 3 72 75
280 72 my (undef, $mount, $rest) = _resolve($root, $components);
281 72 ▶ if (my $comp = $mount->{composite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $mount->{"composite"}) 15 57 72
282 15 return $comp->dispatch_pushpop($root, $which, $rest, @args);
283 }
284 57 return _dispatch_record_pushpop($which, $mount, $rest, @args);
285 }
286  
287 334 ▶sub _dispatch_call {
Subroutine _dispatch_call: called CC=8 SCAR=20.8
288 334 my ($root, $components, $method, @args) = @_;
289 334 _check_root($root);
290 334 ▶ Carp::croak("Data::Shared: a call requires a method name")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method and length $method 27 307 334
Condition100%3/3
defined $method and length $method
!ll&&!rl&&r
1512307
MC/DC100%2/2
defined $method and length $method
defined $method length $method
Truth table100%3/3
A and B
A= defined $methodB= length $method
ABresult
0X0
100
111
291 unless defined $method && length $method;
292 307 _check_native_call($root, $method);
293 286 ▶ Carp::croak($CALL_NEEDS_MOUNT) unless @$components;
Branch: 1 branch
BranchTrueFalseTotal
unless @$components 16 270 286
294 270 my ($name, $mount, $rest) = _resolve($root, $components);
295 270 ▶ if ($method eq 'unlink' || $method eq 'destroy') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "unlink" or $method eq "destroy") 15 255 270
Condition100%3/3
$method eq "unlink" or $method eq "destroy"
l!l&&r!l&&!r
105255
MC/DC100%2/2
$method eq "unlink" or $method eq "destroy"
$method eq "unlink" $method eq "destroy"
Truth table100%3/3
A or B
A= $method eq "unlink"B= $method eq "destroy"
ABresult
1X1
011
000
296 15 my @retired = _retire_leaf($root, $components, $method, $name, $mount, $rest);
297 14 ▶ return $retired[0] if @retired;
Branch: 1 branch
BranchTrueFalseTotal
if @retired 3 11 14
298 }
299 266 ▶ if (my $comp = $mount->{composite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $mount->{"composite"}) 70 196 266
300 70 return $comp->dispatch_call($root, $rest, $method, @args);
301 }
302 196 return _dispatch_record_call($mount, $rest, $method, @args);
303 }
304  
305 # The _pp_ subs are what the XSUBs of the same name in Shared.xs fall back to.
306 53282 ▶sub _pp_shared_get { my ($r, $p, @a) = @_; return _dispatch('get', $r, _parse_string_path($p), @a) }
Subroutine _pp_shared_get: called CC=1 SCAR=0.0
307 13748 ▶sub _pp_shared_set { my ($r, $p, @a) = @_; return _dispatch('set', $r, _parse_string_path($p), @a) }
Subroutine _pp_shared_set: called CC=1 SCAR=0.0
308 177 ▶sub _pp_shared_delete { my ($r, $p, @a) = @_; return _dispatch('delete', $r, _parse_string_path($p), @a) }
Subroutine _pp_shared_delete: called CC=1 SCAR=0.0
309 4377 ▶sub _pp_shared_exists { my ($r, $p, @a) = @_; return _dispatch('exists', $r, _parse_string_path($p), @a) }
Subroutine _pp_shared_exists: called CC=1 SCAR=0.0
310 331 ▶sub _pp_shared_incr { my ($r, $p, @a) = @_; return _dispatch('incr', $r, _parse_string_path($p), @a) }
Subroutine _pp_shared_incr: called CC=1 SCAR=0.0
311 45 ▶sub shared_push { my ($r, $p, @a) = @_; return _dispatch_pushpop('push', $r, _parse_string_path($p), @a) }
Subroutine shared_push: called CC=1 SCAR=0.0
Pod documented
312 28 ▶sub shared_pop { my ($r, $p, @a) = @_; return _dispatch_pushpop('pop', $r, _parse_string_path($p), @a) }
Subroutine shared_pop: called CC=1 SCAR=0.0
Pod documented
313 234 ▶sub _pp_shared_call { my ($r, $p, $m, @a) = @_; return _dispatch_call($r, _parse_string_path($p), $m, @a) }
Subroutine _pp_shared_call: called CC=1 SCAR=0.0
314  
315 118 ▶sub _pp_shareda_get { my ($r, $p, @a) = @_; return _dispatch('get', $r, _parse_array_path($p), @a) }
Subroutine _pp_shareda_get: called CC=1 SCAR=0.0
316 104 ▶sub _pp_shareda_set { my ($r, $p, @a) = @_; return _dispatch('set', $r, _parse_array_path($p), @a) }
Subroutine _pp_shareda_set: called CC=1 SCAR=0.0
317 103 ▶sub _pp_shareda_delete { my ($r, $p, @a) = @_; return _dispatch('delete', $r, _parse_array_path($p), @a) }
Subroutine _pp_shareda_delete: called CC=1 SCAR=0.0
318 103 ▶sub _pp_shareda_exists { my ($r, $p, @a) = @_; return _dispatch('exists', $r, _parse_array_path($p), @a) }
Subroutine _pp_shareda_exists: called CC=1 SCAR=0.0
319 104 ▶sub _pp_shareda_incr { my ($r, $p, @a) = @_; return _dispatch('incr', $r, _parse_array_path($p), @a) }
Subroutine _pp_shareda_incr: called CC=1 SCAR=0.0
320 1 ▶sub shareda_push { my ($r, $p, @a) = @_; return _dispatch_pushpop('push', $r, _parse_array_path($p), @a) }
Subroutine shareda_push: called CC=1 SCAR=0.0
Pod undocumented
321 1 ▶sub shareda_pop { my ($r, $p, @a) = @_; return _dispatch_pushpop('pop', $r, _parse_array_path($p), @a) }
Subroutine shareda_pop: called CC=1 SCAR=0.0
Pod undocumented
322 77 ▶sub _pp_shareda_call { my ($r, $p, $m, @a) = @_; return _dispatch_call($r, _parse_array_path($p), $m, @a) }
Subroutine _pp_shareda_call: called CC=1 SCAR=0.0
323  
324 561 ▶sub shared_compile {
Subroutine shared_compile: called CC=3 SCAR=11.0
Pod undocumented
325 561 my ($path) = @_;
326 561 my ($components, $is_array);
327 561 ▶ if (ref $path eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $path eq 'ARRAY') { } 79 482 561
328 79 $components = _check_components([ @$path ]);
329 78 $is_array = 1;
330 } else {
331 482 $components = _parse_string_path($path);
332 482 $is_array = 0;
333 }
334 560 ▶ return bless { components => $components, raw => ($is_array ? [ @$path ] : $path), is_array => $is_array },
Branch: 1 branch
BranchTrueFalseTotal
$is_array ? : 78 482 560
335 'Data::Shared::Compiled';
336 }
337  
338 736 ▶sub _check_compiled {
Subroutine _check_compiled: called CC=4 SCAR=15.6
339 736 my ($cp) = @_;
340 736 ▶ return $cp->{components} if ref($cp) eq 'Data::Shared::Compiled';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cp eq "Data::Shared::Compiled" 728 8 736
341 8 ▶ Carp::croak("Data::Shared: not a compiled path (use shared_compile)")
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($cp) and $cp->isa("Data::Shared::Compiled") 8 0 8
Condition33%1/3
builtin::blessed($cp) and $cp->isa("Data::Shared::Compiled")
!ll&&!rl&&r
800
MC/DC0%0/2
builtin::blessed($cp) and $cp->isa("Data::Shared::Compiled")
builtin::blessed($cp) $cp->isa("Data::Shared::Compiled")
Truth table33%1/3
A and B
A= builtin::blessed($cp)B= $cp->isa("Data::Shared::Compiled")
ABresult
0X0
100
111
342 unless blessed($cp) && $cp->isa('Data::Shared::Compiled');
343 0 return $cp->{components};
344 }
345  
346 631 ▶sub _compiled_code {
Subroutine _compiled_code: called CC=20 SCAR=30.0
347 631 my ($root, $cp, $kind, $extra) = @_;
348 631 ▶ my $key = defined $extra ? "call:$extra" : $kind;
Branch: 1 branch
BranchTrueFalseTotal
defined $extra ? : 106 525 631
349 631 ▶ if (my $code = _bound_hit($root, $cp, $key)) { return $code }
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($root, $cp, $key)) 22 609 631
350 # _bc holds one root's bindings; each root keeps its own as well.
351 609 ▶ if (my $owned = $root->{_compiled}{refaddr $cp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $owned = $root->{"_compiled"}{builtin::refaddr($cp)}) 36 573 609
352 36 ▶ if (my $code = $owned->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $owned->{$key}) 13 23 36
353 13 _cache_compiled($root, $cp, $key, $code);
354 13 return $code;
355 }
356 }
357 596 my $components = $cp->{components};
358 # Only sharedc_call arrives here with no components.
359 596 ▶ Carp::croak($CALL_NEEDS_MOUNT) unless @$components;
Branch: 1 branch
BranchTrueFalseTotal
unless @$components 14 582 596
360 582 my ($name, $mount, $rest) = _resolve($root, $components);
361 579 ▶ if (my $comp = $mount->{composite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $mount->{"composite"}) 54 525 579
362 54 my $weak = $root;
363 54 weaken($weak);
364 54 my $bound;
365 54 ▶ if ($kind eq 'call') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'call') { } 6 48 54
elsif ($kind eq 'push' or $kind eq 'pop') { } 3 45 48
366 6 ▶ $bound = sub { my @a = @_; my $r = $weak or Carp::croak("Data::Shared: root has gone away"); return $comp->dispatch_call($r, $rest, $extra, @a) };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $r = $weak or Carp::croak("Data::Shared: root has gone away") 12 0 12
367 ▶ } elsif ($kind eq 'push' || $kind eq 'pop') {
Condition100%3/3
$kind eq "push" or $kind eq "pop"
l!l&&r!l&&!r
1245
MC/DC100%2/2
$kind eq "push" or $kind eq "pop"
$kind eq "push" $kind eq "pop"
Truth table100%3/3
A or B
A= $kind eq "push"B= $kind eq "pop"
ABresult
1X1
011
000
368 3 ▶ $bound = sub { my @a = @_; my $r = $weak or Carp::croak("Data::Shared: root has gone away"); return $comp->dispatch_pushpop($r, $kind, $rest, @a) };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $r = $weak or Carp::croak("Data::Shared: root has gone away") 3 0 3
369 } else {
370 45 ▶ $bound = sub { my @a = @_; my $r = $weak or Carp::croak("Data::Shared: root has gone away"); return $comp->dispatch_verb($r, $kind, $rest, @a) };
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
my $r = $weak or Carp::croak("Data::Shared: root has gone away") 90 0 90
371 }
372 54 _cache_compiled($root, $cp, $key, $bound);
373 54 return $bound;
374 }
375 525 my $adapter = _adapter_for($mount->{entry});
376 525 my $bound;
377 525 ▶ if ($kind eq 'call') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'call') { } 62 463 525
elsif ($kind eq 'push' or $kind eq 'pop') { } 6 457 463
378 62 my $handle = $mount->{handle};
379 62 ▶ my $method = $handle->can($extra)
Branch: 1 branch
BranchTrueFalseTotal
my $method = $handle->can($extra) or Carp::croak("Data::Shared: mount '${name}' (" . ref($handle) . ") has no method '${extra}'") 50 12 62
380 or Carp::croak("Data::Shared: mount '$name' (" . ref($handle) . ") has no method '$extra'");
381 50 ▶ $bound = sub { my @a = @_; return $handle->$method(@$rest, @a) };
Subroutine __ANON__: called CC=1 SCAR=0.0
382 ▶ } elsif ($kind eq 'push' || $kind eq 'pop') {
Condition100%3/3
$kind eq "push" or $kind eq "pop"
l!l&&r!l&&!r
42457
MC/DC100%2/2
$kind eq "push" or $kind eq "pop"
$kind eq "push" $kind eq "pop"
Truth table100%3/3
A or B
A= $kind eq "push"B= $kind eq "pop"
ABresult
1X1
011
000
383 6 ▶ my $maker = $kind eq 'push' ? 'make_bound_push' : 'make_bound_pop';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'push' ? : 4 2 6
384 6 $bound = $adapter->$maker($mount->{handle}, $mount->{entry}, $rest);
385 5 ▶ if (!$bound) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bound) 1 4 5
386 1 ▶ my $method = $kind eq 'push' ? 'perform_push' : 'perform_pop';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'push' ? : 1 0 1
387 1 ▶ $bound = sub { my @a = @_; return $adapter->$method($mount->{handle}, $mount->{entry}, $rest, @a) };
Subroutine __ANON__: called CC=1 SCAR=0.0
388 }
389 } else {
390 457 $bound = $adapter->make_bound($kind, $mount->{handle}, $mount->{entry}, $rest);
391 335 ▶ if (!$bound) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bound) 18 317 335
392 18 ▶ $bound = sub { my @a = @_; return $adapter->perform($kind, $mount->{handle}, $mount->{entry}, $rest, @a) };
Subroutine __ANON__: called CC=1 SCAR=0.0
393 }
394 335 ▶ my $fast = @$rest == 1 && _fast_desc($mount, $kind);
Condition66%2/3
@$rest == 1 && _fast_desc($mount, $kind)
!ll&&!rl&&r
044291
MC/DC50%1/2
@$rest == 1 && _fast_desc($mount, $kind)
@$rest == 1 _fast_desc($mount, $kind)
Truth table66%2/3
A && B
A= @$rest == 1B= _fast_desc($mount, $kind)
ABresult
0X0
100
111
395 335 ▶ _cache_compiled($root, $cp, $key, $bound, $fast ? ($fast, $rest->[0]) : ());
Branch: 1 branch
BranchTrueFalseTotal
$fast ? : 291 44 335
396 335 return $bound;
397 }
398 55 _cache_compiled($root, $cp, $key, $bound);
399 55 return $bound;
400 }
401  
402 457 ▶sub _cache_compiled {
Subroutine _cache_compiled: called CC=3 SCAR=11.0
403 457 my ($root, $cp, $key, $bound, $fast, $fast_key) = @_;
404 457 my $id = refaddr($cp);
405 457 $root->{_compiled}{$id}{$key} = $bound;
406 457 my $ra = refaddr($root);
407 457 ▶ if (!$cp->{_owners}{$ra}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cp->{"_owners"}{$ra}) 418 39 457
408 # For DESTROY; dead roots are pruned so a long-lived path does not grow.
409 418 delete @{ $cp->{_owners} }{ grep { !$cp->{_owners}{$_} } keys %{ $cp->{_owners} } };
410 418 $cp->{_owners}{$ra} = $root;
411 418 weaken($cp->{_owners}{$ra});
412 }
413 457 my $entry = $cp->{_bc}{$key} = [$root->{gen}, $bound, $root];
414 457 weaken($entry->[1]);
415 457 weaken($entry->[2]);
416 # The mount record owns the descriptor and its handle; this only borrows.
417 457 ▶ if ($fast) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fast) 291 166 457
418 291 @$entry[3, 4] = ($fast, $fast_key);
419 291 weaken($entry->[3]);
420 }
421 }
422  
423 427 ▶sub _check_native_call {
Subroutine _check_native_call: called CC=6 SCAR=17.9
424 427 my ($root, $method) = @_;
425 # A qualified name (Pkg::unlink) still dispatches to unlink but evades every verb check.
426 427 ▶ Carp::croak("Data::Shared: a call takes a bare method name, not '$method'")
Branch: 1 branch
BranchTrueFalseTotal
if index($method, ":") != -1 30 397 427
427 if index($method, ':') >= 0;
428 Carp::croak("Data::Shared: root is read-only, cannot call '$method'")
429 397 ▶ if $root->{readonly} && ($method eq 'unlink' || $method eq 'destroy' || $method eq 'freeze');
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"readonly"} and $method eq "unlink" || $method eq "destroy" || $method eq "freeze" 4 393 397
Condition100%9/9
$root->{"readonly"} and $method eq "unlink" || $method eq "destroy" || $method eq "freeze"
!ll&&!rl&&r
38584
$method eq "unlink" or $method eq "destroy" or $method eq "freeze"
l!l&&r!l&&!r
318
$method eq "unlink" or $method eq "destroy"
l!l&&r!l&&!r
219
MC/DC100%4/4
$root->{"readonly"} and $method eq "unlink" || $method eq "destroy" || $method eq "freeze"
$root->{"readonly"} $method eq "unlink" $method eq "destroy" $method eq "freeze"
Truth table100%5/5
A and B or C or D
A= $root->{"readonly"}B= $method eq "unlink"C= $method eq "destroy"D= $method eq "freeze"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
430 }
431  
432 579 ▶sub _dispatch_compiled {
Subroutine _dispatch_compiled: called CC=5 SCAR=16.1
433 579 my ($verb, $root, $cp, @args) = @_;
434 579 _check_root($root);
435 579 my $components = _check_compiled($cp);
436 571 ▶ return _root_verb($verb, $root) unless @$components;
Branch: 1 branch
BranchTrueFalseTotal
unless @$components 15 556 571
437 556 ▶ _refuse_readonly($root, $verb) if $root->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"readonly"} 52 504 556
438 516 my $r = _compiled_code($root, $cp, $verb)->(@args);
439 319 ▶ return $verb eq 'exists' ? ($r ? 1 : 0) : $r;
Branch: 2 branches
BranchTrueFalseTotal
$verb eq 'exists' ? : 73 246 319
$r ? : 37 36 73
440 }
441  
442 12 ▶sub _dispatch_compiled_pushpop {
Subroutine _dispatch_compiled_pushpop: called CC=3 SCAR=11.0
443 12 my ($which, $root, $cp, @args) = @_;
444 12 _check_root($root);
445 12 ▶ return _root_verb($which, $root) unless @{ _check_compiled($cp) };
Branch: 1 branch
BranchTrueFalseTotal
unless @{_check_compiled($cp);} 0 12 12
446 12 ▶ _refuse_readonly($root, $which) if $root->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"readonly"} 3 9 12
447 9 my $bound = _compiled_code($root, $cp, $which);
448 8 return $bound->(@args);
449 }
450  
451 # Mutating callers must check readonly before taking this shortcut.
452 1394 ▶sub _bound_hit {
Subroutine _bound_hit: called CC=8 SCAR=20.8
453 1394 my ($root, $cp, $key) = @_;
454 1394 ▶ return undef unless ref $root && ref $cp eq 'Data::Shared::Compiled';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $root and ref $cp eq "Data::Shared::Compiled" 8 1386 1394
Condition66%2/3
ref $root and ref $cp eq "Data::Shared::Compiled"
!ll&&!rl&&r
081386
MC/DC50%1/2
ref $root and ref $cp eq "Data::Shared::Compiled"
ref $root ref $cp eq "Data::Shared::Compiled"
Truth table66%2/3
A and B
A= ref $rootB= ref $cp eq "Data::Shared::Compiled"
ABresult
0X0
100
111
455 1386 ▶ my $bc = $cp->{_bc} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $bc = $cp->{"_bc"} or return undef 282 1104 1386
456 282 ▶ my $hit = $bc->{$key} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $hit = $bc->{$key} or return undef 238 44 282
457 # [2] is weakened; test it survived rather than handing back dead code.
458 238 ▶ return undef unless $hit->[2] && $hit->[2] == $root && $hit->[0] == $root->{gen};
Branch: 1 branch
BranchTrueFalseTotal
unless $hit->[2] and $hit->[2] == $root and $hit->[0] == $root->{"gen"} 44 192 236
Condition100%6/6
$hit->[2] and $hit->[2] == $root and $hit->[0] == $root->{"gen"}
!ll&&!rl&&r
368192
$hit->[2] and $hit->[2] == $root
!ll&&!rl&&r
234202
MC/DC100%3/3
$hit->[2] and $hit->[2] == $root and $hit->[0] == $root->{"gen"}
$hit->[2] $hit->[2] == $root $hit->[0] == $root->{"gen"}
Truth table100%4/4
A and B and C
A= $hit->[2]B= $hit->[2] == $rootC= $hit->[0] == $root->{"gen"}
ABCresult
0XX0
10X0
1100
1111
459 192 return $hit->[1];
460 }
461  
462 # Bare &name and &$ref calls alias the caller's @_; never modify it here.
463 172 ▶sub _pp_sharedc_get {
Subroutine _pp_sharedc_get: called CC=3 SCAR=11.0
464 172 ▶ if (my $code = _bound_hit($_[0], $_[1], 'get')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "get")) 27 143 170
465 27 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->();
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 3 24 27
466 }
467 143 my ($r, $cp, @a) = @_; return _dispatch_compiled('get', $r, $cp, @a);
468 }
469  
470 113 ▶sub _pp_sharedc_exists {
Subroutine _pp_sharedc_exists: called CC=4 SCAR=13.9
471 113 ▶ if (my $code = _bound_hit($_[0], $_[1], 'exists')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "exists")) 33 80 113
472 33 ▶ my $r = @_ > 2 ? $code->(@_[2 .. $#_]) : $code->();
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 3 30 33
473 30 ▶ return $r ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 15 15 30
474 }
475 80 my ($r, $cp, @a) = @_; return _dispatch_compiled('exists', $r, $cp, @a);
476 }
477  
478 125 ▶sub _pp_sharedc_set {
Subroutine _pp_sharedc_set: called CC=4 SCAR=14.2
479 125 ▶ if (my $code = _bound_hit($_[0], $_[1], 'set')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "set")) 26 99 125
480 26 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->() unless $_[0]{readonly};
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0]{"readonly"} 26 0 26
@_ > 2 ? : 26 0 26
481 }
482 99 my ($r, $cp, @a) = @_; return _dispatch_compiled('set', $r, $cp, @a);
483 }
484  
485 112 ▶sub _pp_sharedc_delete {
Subroutine _pp_sharedc_delete: called CC=4 SCAR=14.2
486 112 ▶ if (my $code = _bound_hit($_[0], $_[1], 'delete')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "delete")) 24 88 112
487 24 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->() unless $_[0]{readonly};
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0]{"readonly"} 24 0 24
@_ > 2 ? : 0 24 24
488 }
489 88 my ($r, $cp, @a) = @_; return _dispatch_compiled('delete', $r, $cp, @a);
490 }
491  
492 225 ▶sub _pp_sharedc_incr {
Subroutine _pp_sharedc_incr: called CC=4 SCAR=13.9
493 225 ▶ if (my $code = _bound_hit($_[0], $_[1], 'incr')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "incr")) 56 169 225
494 56 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->() unless $_[0]{readonly};
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0]{"readonly"} 56 0 56
@_ > 2 ? : 32 24 56
495 }
496 169 my ($r, $cp, @a) = @_; return _dispatch_compiled('incr', $r, $cp, @a);
497 }
498  
499 9 ▶sub sharedc_push {
Subroutine sharedc_push: called CC=4 SCAR=14.2
Pod undocumented
500 9 ▶ if (my $code = _bound_hit($_[0], $_[1], 'push')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "push")) 2 7 9
501 2 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->() unless $_[0]{readonly};
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0]{"readonly"} 2 0 2
@_ > 2 ? : 2 0 2
502 }
503 7 my ($r, $cp, @a) = @_; return _dispatch_compiled_pushpop('push', $r, $cp, @a);
504 }
505  
506 7 ▶sub sharedc_pop {
Subroutine sharedc_pop: called CC=4 SCAR=14.2
Pod undocumented
507 7 ▶ if (my $code = _bound_hit($_[0], $_[1], 'pop')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = _bound_hit($_[0], $_[1], "pop")) 2 5 7
508 2 ▶ return @_ > 2 ? $code->(@_[2 .. $#_]) : $code->() unless $_[0]{readonly};
Branch: 2 branches
BranchTrueFalseTotal
unless $_[0]{"readonly"} 2 0 2
@_ > 2 ? : 0 2 2
509 }
510 5 my ($r, $cp, @a) = @_; return _dispatch_compiled_pushpop('pop', $r, $cp, @a);
511 }
512  
513 145 ▶sub _pp_sharedc_call {
Subroutine _pp_sharedc_call: called CC=7 SCAR=19.6
514 145 my ($r, $cp, $m, @a) = @_;
515 145 _check_root($r);
516 145 _check_compiled($cp);
517 145 ▶ Carp::croak("Data::Shared: a call requires a method name") unless defined $m && length $m;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m and length $m 25 120 145
Condition100%3/3
defined $m and length $m
!ll&&!rl&&r
1312120
MC/DC100%2/2
defined $m and length $m
defined $m length $m
Truth table100%3/3
A and B
A= defined $mB= length $m
ABresult
0X0
100
111
518 120 _check_native_call($r, $m);
519 107 ▶ if (($m eq 'unlink' || $m eq 'destroy') && @{ $cp->{components} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m eq "unlink" || $m eq "destroy" and @{$cp->{"components"};}) 1 106 107
Condition66%4/6
$m eq "unlink" || $m eq "destroy" and @{$cp->{"components"};}
!ll&&!rl&&r
10601
$m eq "unlink" or $m eq "destroy"
l!l&&r!l&&!r
10106
MC/DC33%1/3
$m eq "unlink" || $m eq "destroy" and @{$cp->{"components"};}
$m eq "unlink" $m eq "destroy" @{$cp->{"components"};}
Truth table40%2/5
A or B and C
A= $m eq "unlink"B= $m eq "destroy"C= @{$cp->{"components"};}
ABCresult
00X0
1X00
0100
1X11
0111
520 1 my @retired = _retire_leaf($r, $cp->{components}, $m);
521 1 ▶ return $retired[0] if @retired;
Branch: 1 branch
BranchTrueFalseTotal
if @retired 1 0 1
522 }
523 106 my $bound = _compiled_code($r, $cp, 'call', $m);
524 78 return $bound->(@a);
525 }
526  
527 1 ▶sub registry { return Data::Shared::Registry::registry() }
Subroutine registry: called CC=1 SCAR=0.0
Pod undocumented
528 5 ▶sub available_types { return Data::Shared::Registry::keys_list() }
Subroutine available_types: called CC=1 SCAR=0.0
Pod undocumented
529  
530 2881 ▶sub _empty_root {
Subroutine _empty_root: called CC=4 SCAR=13.9
531 2881 my ($class, $dir, %opt) = @_;
532 return bless { dir => $dir, mounts => {}, order => [], readonly => $opt{readonly} ? 1 : 0,
533 strict_readonly => $opt{strict} ? 1 : 0, gen => 0, _nest_depth => 0,
534 2881 ▶ _frozen_ok => $opt{frozen_ok} ? 1 : 0,
Branch: 3 branches
BranchTrueFalseTotal
$opt{'readonly'} ? : 95 2786 2881
$opt{'strict'} ? : 10 2871 2881
$opt{'frozen_ok'} ? : 4 2877 2881
535 _revision => 0, _compiled => {}, _retained => [] }, $class;
536 }
537  
538 2640 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
539 2640 my ($class, $dir) = @_;
540 2640 my $self = _empty_root($class, $dir);
541 2640 ▶ if (defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 429 2211 2640
542 429 require File::Path;
543 # Preserve existing directory modes.
544 429 ▶ File::Path::make_path($dir, { mode => 0700 }) unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 14 415 429
545 429 ▶ Carp::croak("Data::Shared: cannot create directory '$dir'") unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 429 429
546 429 ▶ Data::Shared::Manifest::with_lock($self, 1, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
547 429 ▶ if (-e $self->manifest_path) { $self->_replay_manifest }
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->manifest_path) { } 3 426 429
548 426 else { $self->_write_manifest }
549 429 });
550 }
551 2639 return $self;
552 }
553  
554 244 ▶sub _open_root {
Subroutine _open_root: called CC=3 SCAR=11.0
555 244 my ($class, $dir, %opt) = @_;
556 244 ▶ Carp::croak('Data::Shared: open requires a directory') unless defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 1 243 244
557 243 ▶ Carp::croak("Data::Shared: directory '$dir' does not exist") unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 2 241 243
558 241 my $self = _empty_root($class, $dir, %opt);
559 241 ▶ Data::Shared::Manifest::with_lock($self, 0, sub { $self->_replay_manifest });
Subroutine __ANON__: called CC=1 SCAR=0.0
560 212 return $self;
561 }
562  
563 144 ▶sub open { my ($class, $dir) = @_; return _open_root($class, $dir) }
Subroutine open: called CC=1 SCAR=0.0
Pod documented
564  
565 4 ▶sub open_sealed { my ($class, $dir) = @_; return _open_root($class, $dir, frozen_ok => 1) }
Subroutine open_sealed: called CC=1 SCAR=0.0
Pod documented
566  
567 96 ▶sub open_readonly {
Subroutine open_readonly: called CC=2 SCAR=7.0
Pod documented
568 96 my ($class, $dir, %opt) = @_;
569 96 ▶ Carp::croak('Data::Shared: unknown read-only option') if grep { $_ ne 'strict' } keys %opt;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ ne "strict";} keys %opt 0 96 96
570 96 return _open_root($class, $dir, readonly => 1, %opt);
571 }
572  
573 43 ▶sub dir { return $_[0]{dir} }
Subroutine dir: called CC=1 SCAR=0.0
Pod documented
574 4 ▶sub readonly { return $_[0]{readonly} ? 1 : 0 }
Subroutine readonly: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'readonly'} ? : 3 1 4
575 8565 ▶sub manifest_path { my ($s) = @_; return defined $s->{dir} ? "$s->{dir}/manifest.json" : undef }
Subroutine manifest_path: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{'dir'} ? : 8564 1 8565
576  
577 2374 ▶sub _require_class {
Subroutine _require_class: called CC=3 SCAR=11.0
578 2374 my ($cls, $dist) = @_;
579 2374 (my $file = $cls) =~ s{::}{/}g;
580 2374 $file .= '.pm';
581 2374 eval { require $file };
582 2374 ▶ if (my $e = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 5 2369 2374
583 5 $e =~ s/ \(\@INC.*//s;
584 5 $e =~ s/\s+\z//;
585 5 ▶ my $how = defined $dist
Branch: 1 branch
BranchTrueFalseTotal
defined $dist ? : 0 5 5
586 ? "install the $dist dist"
587 : "install the dist providing $cls";
588 5 Carp::croak("Data::Shared: backend $cls is not available; $how: $e");
589 }
590 2369 return 1;
591 }
592  
593 3927 ▶sub _storage_name {
Subroutine _storage_name: called CC=1 SCAR=0.0
594 3927 my ($name) = @_;
595 3927 $name =~ s{/}{__}g;
596 3927 $name =~ s{[^A-Za-z0-9_.-]}{_}g;
597 3927 return $name;
598 }
599  
600 3618 ▶sub _file_for {
Subroutine _file_for: called CC=1 SCAR=0.0
601 3618 my ($self, $name) = @_;
602 3618 return "$self->{dir}/" . _storage_name($name) . '.shm';
603 }
604  
605 21837 ▶sub _check_storage_paths {
Subroutine _check_storage_paths: called CC=9 SCAR=22.1
606 21837 my ($self, $name, @paths) = @_;
607 21837 ▶ return unless keys %{ $self->{mounts} };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$self{"mounts"};} 10860 10977 21837
608 10977 for my $path (grep { defined $_ } @paths) {
609 692 my $abs = $self->_abs_path($path);
610 692 for my $mount (values %{ $self->{mounts} }) {
611 1751 ▶ for my $used (@{ $mount->{storage_paths} || [] }) {
Condition50%1/2
$mount->{'storage_paths'} || []
l!l
17510
MC/DC0%0/1
$mount->{'storage_paths'} || []
$mount->{'storage_paths'}
Truth table50%1/2
A
A= $mount->{'storage_paths'}
Aresult
11
00
612 1759 my $used_abs = $self->_abs_path($used);
613 Carp::croak("Data::Shared: backing path '$path' for mount '$name' is already used by mount '$mount->{name}'")
614 1759 ▶ if $abs eq $used_abs || ($mount->{composite} && index($abs, "$used_abs/") == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $abs eq $used_abs or $mount->{"composite"} and index($abs, "$used_abs/") == 0 5 1754 1759
Condition66%4/6
$abs eq $used_abs or $mount->{"composite"} and index($abs, "$used_abs/") == 0
l!l&&r!l&&!r
501754
$mount->{"composite"} and index($abs, "$used_abs/") == 0
!ll&&!rl&&r
1732220
MC/DC33%1/3
$abs eq $used_abs or $mount->{"composite"} and index($abs, "$used_abs/") == 0
$abs eq $used_abs $mount->{"composite"} index($abs, "$used_abs/") == 0
Truth table75%3/4
A or B and C
A= $abs eq $used_absB= $mount->{"composite"}C= index($abs, "$used_abs/") == 0
ABCresult
1XX1
0111
00X0
0100
615 }
616 }
617 }
618 10972 return;
619 }
620  
621 # Cache paths for one manifest operation; symlinks may change between operations.
622 3730 ▶sub _abs_path {
Subroutine _abs_path: called CC=3 SCAR=11.0
623 3730 my ($self, $path) = @_;
624 3730 my $hit = $self->{_abs_cache}{$path};
625 3730 ▶ return $hit if defined $hit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hit 922 2808 3730
626 2808 require Cwd;
627 2808 require File::Spec;
628 2808 my $abs = Cwd::abs_path($path);
629 2808 ▶ return $self->{_abs_cache}{$path} = $abs if defined $abs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $abs 2711 97 2808
630 97 return File::Spec->rel2abs($path);
631 }
632  
633 20730 ▶sub _track_paths {
Subroutine _track_paths: called CC=3 SCAR=11.0
634 20730 my ($self, @paths) = @_;
635 20730 ▶ return unless $self->{_pending_paths};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_pending_paths"} 0 20730 20730
636 20730 ▶ push @{ $self->{_pending_paths} }, grep { defined $_ && !-e $_ } @paths;
Condition100%3/3
defined $_ && !(-e $_)
!ll&&!rl&&r
2086281959
MC/DC100%2/2
defined $_ && !(-e $_)
defined $_ !(-e $_)
Truth table100%3/3
A && not(B)
A= defined $_B= !(-e $_)
ABresult
0X0
100
111
637 }
638  
639 # Lock order: topology, then composites from parent to child.
640 55 ▶sub _lock_composite_dirs {
Subroutine _lock_composite_dirs: called CC=13 SCAR=27.4
641 55 my ($paths) = @_;
642 55 my @held;
643 55 require Fcntl;
644 # Discover each level under its parent's lock; children may be created lazily.
645 55 my @queue = @$paths;
646 55 ▶ while (my $path = shift @queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = shift @queue) 151 55 206
647 151 ▶ next unless -d $path && !-l $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $path and not -l $path 107 44 151
Condition66%2/3
-d $path and not -l $path
!ll&&!rl&&r
107044
MC/DC50%1/2
-d $path and not -l $path
-d $path not -l $path
Truth table66%2/3
A and not(B)
A= -d $pathB= not -l $path
ABresult
0X0
100
111
648 44 my $lockfile = "$path/.lock";
649 44 my $fh;
650 44 ▶ if (-e $lockfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $lockfile) 9 35 44
651 # Linux flocks a read-only fd exclusively; only ENOENT may skip the lock.
652 9 ▶ unless (CORE::open($fh, '+<', $lockfile)
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::open $fh, "+<", $lockfile or CORE::open $fh, "<", $lockfile) 0 9 9
Condition66%2/3
CORE::open $fh, "+<", $lockfile or CORE::open $fh, "<", $lockfile
l!l&&r!l&&!r
810
MC/DC0%0/2
CORE::open $fh, "+<", $lockfile or CORE::open $fh, "<", $lockfile
CORE::open $fh, "+<", $lockfile CORE::open $fh, "<", $lockfile
Truth table66%2/3
A or B
A= CORE::open $fh, "+<", $lockfileB= CORE::open $fh, "<", $lockfile
ABresult
1X1
011
000
653 || CORE::open($fh, '<', $lockfile)) {
654 Carp::croak("Data::Shared: cannot open composite lock '$lockfile': $!")
655 0 ▶ unless $!{ENOENT};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"ENOENT"} 0 0 0
656 }
657 }
658 44 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 9 35 44
659 9 ▶ until (flock $fh, Fcntl::LOCK_EX()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 2) 0 9 9
660 0 ▶ next if $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} 0 0 0
661 0 Carp::croak("Data::Shared: cannot lock composite '$lockfile': $!");
662 }
663 9 push @held, $fh;
664 }
665 44 ▶ opendir my $dh, $path or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $path or next 44 0 44
666 44 ▶ push @queue, map { "$path/$_" } grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition100%3/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
444462
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
667 44 closedir $dh;
668 }
669 55 return \@held;
670 }
671  
672 # Only ENOENT means gone; a path that cannot be checked counts as present.
673 230 ▶sub _present { my ($path) = @_; return -e $path || !$!{ENOENT} ? 1 : 0 }
Subroutine _present: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
-e $path || !$!{'ENOENT'} ? : 79 151 230
Condition100%3/3
-e $path or not $!{"ENOENT"}
l!l&&r!l&&!r
763151
MC/DC100%2/2
-e $path or not $!{"ENOENT"}
-e $path not $!{"ENOENT"}
Truth table100%3/3
A or not(B)
A= -e $pathB= not $!{"ENOENT"}
ABresult
1X1
011
000
674  
675 145 ▶sub _cleanup_paths {
Subroutine _cleanup_paths: called CC=8 SCAR=20.8
676 145 my ($paths) = @_;
677 145 my @errors;
678 my %seen;
679 145 for my $path (reverse @$paths) {
680 83 ▶ next if $seen{$path}++ || !_present($path);
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$path}++ or not _present($path) 29 54 83
Condition66%2/3
$seen{$path}++ or not _present($path)
l!l&&r!l&&!r
02954
MC/DC50%1/2
$seen{$path}++ or not _present($path)
$seen{$path}++ not _present($path)
Truth table66%2/3
A or not(B)
A= $seen{$path}++B= not _present($path)
ABresult
1X1
011
000
681 54 ▶ if (-d $path && !-l $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path and not -l $path) { } 36 18 54
Condition66%2/3
-d $path and not -l $path
!ll&&!rl&&r
18036
MC/DC50%1/2
-d $path and not -l $path
-d $path not -l $path
Truth table66%2/3
A and not(B)
A= -d $pathB= not -l $path
ABresult
0X0
100
111
682 36 require File::Path;
683 36 my $errors;
684 36 File::Path::remove_tree($path, { error => \$errors });
685 36 ▶ push @errors, "cannot clean '$path'" if @$errors;
Branch: 1 branch
BranchTrueFalseTotal
if @$errors 1 35 36
686 } else {
687 18 ▶ CORE::unlink($path) or push @errors, "cannot clean '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $path or CORE::push @errors, "cannot clean '${path}': $!" 16 2 18
688 }
689 }
690 145 return join('; ', @errors);
691 }
692  
693 1687 ▶sub _manifest_data {
Subroutine _manifest_data: called CC=6 SCAR=18.0
694 1687 my ($self) = @_;
695 1687 my @mounts;
696 1687 for my $name (@{ $self->{order} }) {
697 2878 ▶ my $m = $self->{mounts}{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $m = $self->{"mounts"}{$name} or next 2878 0 2878
698 2878 ▶ next if $m->{transient};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"transient"} 2 2876 2878
699 2876 push @mounts, { name => $name, spec => $m->{spec}, args => $m->{args} };
700 }
701 # Fixed at creation: a rebuilt store can repeat the old topology and revision.
702 1687 ▶ $self->{_store_id} //= _new_store_id();
Condition66%2/3
$self->{"_store_id"} //= _new_store_id()
l!l&&r!l&&!r
12614260
MC/DC0%0/2
$self->{"_store_id"} //= _new_store_id()
$self->{"_store_id"} _new_store_id()
Truth table66%2/3
A //= B
A= $self->{"_store_id"}B= _new_store_id()
ABresult
1X1
011
000
703 my $data = { version => 1, revision => $self->{_revision}, mounts => \@mounts,
704 1687 store => $self->{_store_id} };
705 # Omit an empty ledger to preserve manifests from stores that never retained storage.
706 1687 ▶ $data->{retained} = [ @{ $self->{_retained} } ] if @{ $self->{_retained} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"_retained"};} 252 1435 1687
707 1687 return $data;
708 }
709  
710 426 ▶sub _new_store_id {
Subroutine _new_store_id: called CC=4 SCAR=17.1
711 426 ▶ if (CORE::open my $fh, '<:raw', '/dev/urandom') {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::open my $fh, "<:raw", "/dev/urandom") 426 0 426
712 426 my $got = read $fh, my $bytes, 8;
713 426 ▶ return unpack 'H*', $bytes if $got && $got == 8;
Branch: 1 branch
BranchTrueFalseTotal
if $got and $got == 8 426 0 426
Condition33%1/3
$got and $got == 8
!ll&&!rl&&r
00426
MC/DC0%0/2
$got and $got == 8
$got $got == 8
Truth table33%1/3
A and B
A= $gotB= $got == 8
ABresult
0X0
100
111
714 }
715 0 return sprintf '%x%x%x', time, $$, int rand 2**31;
716 }
717  
718 14161 ▶sub _write_manifest {
Subroutine _write_manifest: called CC=3 SCAR=11.0
719 14161 my ($self) = @_;
720 14161 ▶ return unless defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 12474 1687 14161
721 1687 ▶ Carp::croak('Data::Shared: root is read-only, cannot write manifest') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 1687 1687
722 1687 my $data = $self->_manifest_data;
723 1687 $self->{_manifest_stamp} = Data::Shared::Manifest::write($self->manifest_path, $data);
724 1687 $self->_stamp_manifest_identity;
725 1687 return 1;
726 }
727  
728 # A restored copy of a store carries its nonce, revision and bytes; only the inode differs.
729 1901 ▶sub _stamp_manifest_identity {
Subroutine _stamp_manifest_identity: called CC=1 SCAR=0.0
730 1901 my ($self) = @_;
731 1901 @{$self}{qw(_manifest_dev _manifest_ino)} = (stat $self->manifest_path)[0, 1];
732 1901 return;
733 }
734  
735 13928 ▶sub _assert_revision {
Subroutine _assert_revision: called CC=13 SCAR=26.8
736 13928 my ($self) = @_;
737 13928 ▶ return unless defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 12523 1405 13928
738 Carp::croak('Data::Shared: this store was unlinked; create or open a root again')
739 1405 ▶ if defined $self->{_manifest_stamp} && !-e $self->manifest_path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_manifest_stamp"} and not -e $self->manifest_path 1 1404 1405
Condition66%2/3
defined $self->{"_manifest_stamp"} and not -e $self->manifest_path
!ll&&!rl&&r
014041
MC/DC50%1/2
defined $self->{"_manifest_stamp"} and not -e $self->manifest_path
defined $self->{"_manifest_stamp"} not -e $self->manifest_path
Truth table66%2/3
A and not(B)
A= defined $self->{"_manifest_stamp"}B= not -e $self->manifest_path
ABresult
0X0
100
111
740 1404 my ($current, $stamp) = Data::Shared::Manifest::read($self->manifest_path);
741 Carp::croak('Data::Shared: this store was replaced; open the root again')
742 1404 ▶ if defined $self->{_store_id} && ($current->{store} // '') ne $self->{_store_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_store_id"} and ($current->{"store"} // "") ne $self->{"_store_id"} 3 1401 1404
Condition60%3/5
defined $self->{"_store_id"} and ($current->{"store"} // "") ne $self->{"_store_id"}
!ll&&!rl&&r
014013
$current->{"store"} // ""
l!l
14040
MC/DC0%0/2
defined $self->{"_store_id"} and ($current->{"store"} // "") ne $self->{"_store_id"}
defined $self->{"_store_id"} $current->{"store"}
Truth table33%1/3
A and B
A= defined $self->{"_store_id"}B= $current->{"store"}
ABresult
0X0
100
111
743 Carp::croak('Data::Shared: stale manifest revision; reopen the root before changing mounts')
744 1401 ▶ unless $current->{revision} == $self->{_revision} && $stamp eq $self->{_manifest_stamp};
Branch: 1 branch
BranchTrueFalseTotal
unless $current->{"revision"} == $self->{"_revision"} and $stamp eq $self->{"_manifest_stamp"} 3 1398 1401
Condition66%2/3
$current->{"revision"} == $self->{"_revision"} and $stamp eq $self->{"_manifest_stamp"}
!ll&&!rl&&r
301398
MC/DC50%1/2
$current->{"revision"} == $self->{"_revision"} and $stamp eq $self->{"_manifest_stamp"}
$current->{"revision"} == $self->{"_revision"} $stamp eq $self->{"_manifest_stamp"}
Truth table66%2/3
A and B
A= $current->{"revision"} == $self->{"_revision"}B= $stamp eq $self->{"_manifest_stamp"}
ABresult
0X0
100
111
745 1398 my ($dev, $ino) = (stat $self->manifest_path)[0, 1];
746 Carp::croak('Data::Shared: this store was replaced; open the root again')
747 if defined $self->{_manifest_ino} && defined $ino
748 1398 ▶ && ($dev != $self->{_manifest_dev} || $ino != $self->{_manifest_ino});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_manifest_ino"} and defined $ino and $dev != $self->{"_manifest_dev"} || $ino != $self->{"_manifest_ino"} 1 1397 1398
Condition55%5/9
defined $self->{"_manifest_ino"} and defined $ino and $dev != $self->{"_manifest_dev"} || $ino != $self->{"_manifest_ino"}
!ll&&!rl&&r
013971
defined $self->{"_manifest_ino"} and defined $ino
!ll&&!rl&&r
001398
$dev != $self->{"_manifest_dev"} or $ino != $self->{"_manifest_ino"}
l!l&&r!l&&!r
011397
MC/DC25%1/4
defined $self->{"_manifest_ino"} and defined $ino and $dev != $self->{"_manifest_dev"} || $ino != $self->{"_manifest_ino"}
defined $self->{"_manifest_ino"} defined $ino $dev != $self->{"_manifest_dev"} $ino != $self->{"_manifest_ino"}
Truth table40%2/5
A and B and C or D
A= defined $self->{"_manifest_ino"}B= defined $inoC= $dev != $self->{"_manifest_dev"}D= $ino != $self->{"_manifest_ino"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
749 }
750  
751 13964 ▶sub _invalidate_compiled {
Subroutine _invalidate_compiled: called CC=1 SCAR=0.0
752 13964 my ($self) = @_;
753 13964 $self->{gen}++;
754 13964 $self->{_compiled} = {};
755 }
756  
757 13778 ▶sub _mutate {
Subroutine _mutate: called CC=3 SCAR=11.0
758 13778 my ($self, $code, $after) = @_;
759 13778 ▶ Carp::croak('Data::Shared: root is read-only, cannot change mounts') if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 2 13776 13778
760 13776 ▶ Carp::croak('Data::Shared: nested mount mutations are not supported') if $self->{_mutating};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_mutating"} 0 13776 13776
761 13776 ▶ return Data::Shared::Manifest::with_lock($self, 1, sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
762 13776 $self->_assert_revision;
763 13773 local $self->{_mutating} = 1;
764 13773 local $self->{_pending_paths} = [];
765 13773 local $self->{_abs_cache} = {};
766 13773 local $self->{_changed} = 0;
767 # Transient changes invalidate local bindings without publishing a new revision.
768 13773 local $self->{_published} = 0;
769 my ($mounts, $order, $nested, $revision, $stamp, $retained, $dev, $ino) =
770 13773 ({ %{ $self->{mounts} } }, [ @{ $self->{order} } ], $self->{_nest_depth}, $self->{_revision},
771 13773 $self->{_manifest_stamp}, [ @{ $self->{_retained} } ],
772 13773 $self->{_manifest_dev}, $self->{_manifest_ino});
773 13773 my $ret;
774 13773 my $ok = eval {
775 13773 $ret = $code->();
776 13699 ▶ if ($self->{_published}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_published"}) 13659 40 13699
777 13659 $self->{_revision}++;
778 13659 $self->_write_manifest;
779 }
780 13697 1;
781 };
782 13773 my $err = $@;
783 13773 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 76 13697 13773
784 76 @{$self}{qw(mounts order _nest_depth _revision _manifest_stamp _retained
785 _manifest_dev _manifest_ino)} =
786 ($mounts, $order, $nested, $revision, $stamp, $retained, $dev, $ino);
787 76 my $cleanup = _cleanup_paths($self->{_pending_paths});
788 76 ▶ die $err if ref $err;
Branch: 1 branch
BranchTrueFalseTotal
if ref $err 1 75 76
789 # Croak inline: a helper would shift the caller Carp reports.
790 75 ▶ Carp::croak(_strip_location($err) . (length $cleanup ? " (rollback: $cleanup)" : ''));
Branch: 1 branch
BranchTrueFalseTotal
length $cleanup ? : 0 75 75
791 }
792 13697 ▶ $self->_invalidate_compiled if $self->{_changed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_changed"} 13692 5 13697
793 # Retire storage under the topology lock, after publishing its removal.
794 13697 ▶ $after->() if $after;
Branch: 1 branch
BranchTrueFalseTotal
if $after 62 13635 13697
795 13696 return $ret;
796 13776 });
797 }
798  
799 13953 ▶sub _recipe {
Subroutine _recipe: called CC=37 SCAR=36.9
800 13953 my ($self, $name, $spec, @args) = @_;
801 13953 ▶ Carp::croak('Data::Shared: mount requires a name') unless defined $name && !ref $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name and length $name 1 13952 13953
Condition50%3/6
defined $name and not ref $name and length $name
!ll&&!rl&&r
0113952
defined $name and not ref $name
!ll&&!rl&&r
0013953
MC/DC33%1/3
defined $name and not ref $name and length $name
defined $name not ref $name length $name
Truth table50%2/4
A and not(B) and C
A= defined $nameB= not ref $nameC= length $name
ABCresult
0XX0
10X0
1100
1111
802 13952 $name =~ s{^/+}{};
803 13952 $name =~ s{/+$}{};
804 13952 ▶ Carp::croak('Data::Shared: mount requires a canonical name')
Branch: 1 branch
BranchTrueFalseTotal
unless length $name and $name ne "." and $name ne ".." and index($name, "//") == -1 and index($name, "\0") == -1 1 13951 13952
Condition66%8/12
length $name and $name ne "." and $name ne ".." and index($name, "//") == -1 and index($name, "\0") == -1
!ll&&!rl&&r
1013951
length $name and $name ne "." and $name ne ".." and index($name, "//") == -1
!ll&&!rl&&r
1013951
length $name and $name ne "." and $name ne ".."
!ll&&!rl&&r
1013951
length $name and $name ne "."
!ll&&!rl&&r
1013951
MC/DC20%1/5
length $name and $name ne "." and $name ne ".." and index($name, "//") == -1 and index($name, "\0") == -1
length $name $name ne "." $name ne ".." index($name, "//") == -1 index($name, "\0") == -1
Truth table33%2/6
A and B and C and D and E
A= length $nameB= $name ne "."C= $name ne ".."D= index($name, "//") == -1E= index($name, "\0") == -1
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
805 unless length $name && $name ne '.' && $name ne '..' && index($name, '//') < 0 && index($name, "\0") < 0;
806 13951 ▶ Carp::croak("Data::Shared: mount '$name' requires a spec, handle, or coderef") unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 1 13950 13951
807 13950 ▶ if (blessed($spec) || ref $spec eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($spec) or ref $spec eq "CODE") 34 13916 13950
Condition100%3/3
builtin::blessed($spec) or ref $spec eq "CODE"
l!l&&r!l&&!r
241013916
MC/DC100%2/2
builtin::blessed($spec) or ref $spec eq "CODE"
builtin::blessed($spec) ref $spec eq "CODE"
Truth table100%3/3
A or B
A= builtin::blessed($spec)B= ref $spec eq "CODE"
ABresult
1X1
011
000
808 34 return { name => $name, source => $spec, kind => 'transient', transient => 1, storage_paths => [] };
809 }
810 13916 my ($copy, $serializable) = Data::Shared::Manifest::snapshot([$spec, \@args]);
811 13912 ($spec, my $args) = @$copy;
812 13912 my $recipe = { name => $name, spec => $spec, manifest_args => $args,
813 transient => !$serializable, kind => 'leaf' };
814 13912 ▶ if (ref $spec eq 'ARRAY' || (ref $spec eq 'HASH' && exists $spec->{child})) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $spec eq 'ARRAY' or ref $spec eq 'HASH' and exists $spec->{'child'}) { } 2421 11491 13912
elsif (ref $spec eq 'HASH') { } 10 11481 11491
Condition100%6/6
ref $spec eq "ARRAY" or ref $spec eq "HASH" and exists $spec->{"child"}
l!l&&r!l&&!r
23754611491
ref $spec eq "HASH" and exists $spec->{"child"}
!ll&&!rl&&r
114811046
MC/DC100%3/3
ref $spec eq "ARRAY" or ref $spec eq "HASH" and exists $spec->{"child"}
ref $spec eq "ARRAY" ref $spec eq "HASH" exists $spec->{"child"}
Truth table100%4/4
A or B and C
A= ref $spec eq "ARRAY"B= ref $spec eq "HASH"C= exists $spec->{"child"}
ABCresult
1XX1
0111
00X0
0100
815 2421 my $node = Data::Shared::Composite::parse_node($spec);
816 2395 $recipe->{node} = $node;
817 2395 $recipe->{resolved} = $node->{resolved};
818 2395 $recipe->{args} = Data::Shared::Composite::_constructor_args($node->{resolved}, $node->{args});
819 2395 $recipe->{manifest_args} = [];
820 2395 ▶ if ($node->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"child"}) 2395 0 2395
821 2395 $recipe->{kind} = 'composite';
822 2395 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dir"}) 309 2086 2395
823 309 my $safe = _storage_name($name);
824 309 $recipe->{dir} = "$self->{dir}/.children/$safe";
825 }
826 }
827 } elsif (ref $spec eq 'HASH') {
828 10 ▶ my $inner = $spec->{spec} // $spec->{class} // $spec->{key};
Condition66%4/6
($spec->{"spec"} // $spec->{"class"}) // $spec->{"key"}
l!l&&r!l&&!r
901
$spec->{"spec"} // $spec->{"class"}
l!l&&r!l&&!r
901
MC/DC33%1/3
($spec->{"spec"} // $spec->{"class"}) // $spec->{"key"}
$spec->{"spec"} $spec->{"class"} $spec->{"key"}
Truth table50%2/4
A // B // C
A= $spec->{"spec"}B= $spec->{"class"}C= $spec->{"key"}
ABCresult
1XX1
01X1
0011
0000
829 10 ▶ Carp::croak("Data::Shared: mount '$name' hashref spec needs spec/class/key") unless defined $inner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $inner 1 9 10
830 9 $recipe->{resolved} = Data::Shared::Registry::resolve_spec($inner);
831 9 ▶ Carp::croak("Data::Shared: unknown mount spec '$inner'") unless $recipe->{resolved};
Branch: 1 branch
BranchTrueFalseTotal
unless $recipe->{"resolved"} 1 8 9
832 8 ▶ if (exists $spec->{ctor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"ctor"}) 3 5 8
833 Carp::croak('Data::Shared: invalid constructor name')
834 3 ▶ unless defined $spec->{ctor} && !ref $spec->{ctor} && $spec->{ctor} =~ /\A[A-Za-z_]\w*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec->{"ctor"} and not ref $spec->{"ctor"} and $spec->{"ctor"} =~ /\A[A-Za-z_]\w*\z/ 0 3 3
Condition33%2/6
defined $spec->{"ctor"} and not ref $spec->{"ctor"} and $spec->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
!ll&&!rl&&r
003
defined $spec->{"ctor"} and not ref $spec->{"ctor"}
!ll&&!rl&&r
003
MC/DC0%0/3
defined $spec->{"ctor"} and not ref $spec->{"ctor"} and $spec->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
defined $spec->{"ctor"} not ref $spec->{"ctor"} $spec->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
Truth table25%1/4
A and not(B) and C
A= defined $spec->{"ctor"}B= not ref $spec->{"ctor"}C= $spec->{"ctor"} =~ /\A[A-Za-z_]\w*\z/
ABCresult
0XX0
10X0
1100
1111
835 # resolve_spec returns a fresh hashref, so this stays local to the mount.
836 # ctor_named tells the caller's ctor from one the registry sets.
837 3 @{ $recipe->{resolved} }{qw(ctor ctor_named)} = ($spec->{ctor}, 1);
838 }
839 Carp::croak('Data::Shared: constructor args must be an ARRAY reference')
840 8 ▶ if exists $spec->{args} && ref $spec->{args} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $spec->{"args"} and ref $spec->{"args"} ne "ARRAY" 0 8 8
Condition66%2/3
exists $spec->{"args"} and ref $spec->{"args"} ne "ARRAY"
!ll&&!rl&&r
260
MC/DC0%0/2
exists $spec->{"args"} and ref $spec->{"args"} ne "ARRAY"
exists $spec->{"args"} ref $spec->{"args"} ne "ARRAY"
Truth table66%2/3
A and B
A= exists $spec->{"args"}B= ref $spec->{"args"} ne "ARRAY"
ABresult
0X0
100
111
841 8 ▶ $recipe->{args} = exists $spec->{args} ? $spec->{args} : $args;
Branch: 1 branch
BranchTrueFalseTotal
exists $spec->{'args'} ? : 6 2 8
842 8 ▶ $recipe->{manifest_args} = [] if exists $spec->{args};
Branch: 1 branch
BranchTrueFalseTotal
if exists $spec->{"args"} 6 2 8
843 } else {
844 11481 $recipe->{resolved} = Data::Shared::Registry::resolve_spec($spec);
845 11481 ▶ Carp::croak("Data::Shared: unknown mount spec '$spec' (see Data::Shared::Registry)") unless $recipe->{resolved};
Branch: 1 branch
BranchTrueFalseTotal
unless $recipe->{"resolved"} 2 11479 11481
846 11479 $recipe->{args} = $args;
847 }
848 13882 ▶ if ($recipe->{kind} eq 'composite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipe->{'kind'} eq 'composite') { } 2395 11487 13882
849 Data::Shared::Composite::_preflight($self, $recipe->{node}, $recipe->{dir},
850 2395 $self->{_opening}, $recipe->{name});
851 2386 ▶ $recipe->{storage_paths} = [defined $recipe->{dir} ? $recipe->{dir} : ()];
Branch: 1 branch
BranchTrueFalseTotal
defined $recipe->{'dir'} ? : 300 2086 2386
852 } else {
853 11487 my $plan = Data::Shared::Storage::plan($self, $recipe->{resolved}, $name, $recipe->{args});
854 11477 ▶ Data::Shared::Storage::require_files($plan) if $self->{_opening};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_opening"} 324 11153 11477
855 11473 ▶ Data::Shared::Storage::check_readonly($recipe->{resolved}, $name) if $self->{strict_readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"strict_readonly"} 6 11467 11473
856 # Reused at install; one manifest lock covers both, so it cannot go stale.
857 11471 $recipe->{plan} = $plan;
858 11471 $recipe->{storage_paths} = $plan->{paths};
859 # A perfecthash build key list is spent once the file exists; replay only loads it.
860 11471 ▶ if ($plan->{build} && ref $recipe->{manifest_args}[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"build"} and ref $recipe->{"manifest_args"}[0] eq "HASH") 7 11464 11471
Condition66%2/3
$plan->{"build"} and ref $recipe->{"manifest_args"}[0] eq "HASH"
!ll&&!rl&&r
1146407
MC/DC50%1/2
$plan->{"build"} and ref $recipe->{"manifest_args"}[0] eq "HASH"
$plan->{"build"} ref $recipe->{"manifest_args"}[0] eq "HASH"
Truth table66%2/3
A and B
A= $plan->{"build"}B= ref $recipe->{"manifest_args"}[0] eq "HASH"
ABresult
0X0
100
111
861 7 my %kept = %{ $recipe->{manifest_args}[0] };
862 7 delete @kept{qw(build_int build_str)};
863 7 $recipe->{manifest_args} = [\%kept];
864 }
865 }
866 13857 return $recipe;
867 }
868  
869 239 ▶sub _replay_manifest {
Subroutine _replay_manifest: called CC=8 SCAR=20.8
870 239 my ($self) = @_;
871 239 my $path = $self->manifest_path;
872 239 my ($data, $raw) = Data::Shared::Manifest::read($path);
873 227 local $self->{_opening} = 1;
874 227 local $self->{_abs_cache} = {}; # shared with $check by the copy below
875 # Load retained paths before replay so adopted storage can leave the ledger.
876 227 ▶ $self->{_retained} = [ @{ $data->{retained} || [] } ];
Condition100%2/2
$data->{'retained'} || []
l!l
76151
MC/DC100%1/1
$data->{'retained'} || []
$data->{'retained'}
Truth table100%2/2
A
A= $data->{'retained'}
Aresult
11
00
877 227 $self->{_store_id} = $data->{store};
878 227 my $check = bless { %$self, mounts => {} }, ref $self;
879 # Every recipe is checked before any handle is built, so a refused manifest installs nothing.
880 227 my @recipes;
881 227 my $ok = eval {
882 227 for my $m (@{ $data->{mounts} }) {
883 436 my $recipe = $self->_recipe($m->{name}, $m->{spec}, @{ $m->{args} });
884 # Unreachable: JSON cannot carry a transient spec.
885 427 ▶ Carp::croak('Data::Shared: transient spec in manifest') if $recipe->{transient};
Branch: 1 branch
BranchTrueFalseTotal
if $recipe->{"transient"} 0 427 427
886 427 ▶ Carp::croak("Data::Shared: duplicate mount '$recipe->{name}'") if $check->{mounts}{$recipe->{name}};
Branch: 1 branch
BranchTrueFalseTotal
if $check->{"mounts"}{$recipe->{"name"}} 1 426 427
887 426 $check->_check_storage_paths($recipe->{name}, @{ $recipe->{storage_paths} });
888 $check->{mounts}{$recipe->{name}} = { name => $recipe->{name}, storage_paths => $recipe->{storage_paths},
889 426 ▶ composite => $recipe->{kind} eq 'composite' ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'kind'} eq 'composite' ? : 109 317 426
890 426 push @recipes, $recipe;
891 }
892 217 $self->_install_recipe($_) for @recipes;
893 214 1;
894 };
895 227 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 13 214 227
896 13 my $why = _strip_location($@);
897 13 Carp::croak("Data::Shared: failed to replay manifest '$path': $why");
898 }
899 214 $self->{_revision} = $data->{revision};
900 214 $self->{_manifest_stamp} = $raw;
901 214 $self->_stamp_manifest_identity;
902 214 $self->_invalidate_compiled;
903 214 return 1;
904 }
905  
906 7948 ▶sub _construct {
Subroutine _construct: called CC=2 SCAR=6.9
907 7948 my ($self, $resolved, $name, @args) = @_;
908 7948 my $plan = Data::Shared::Storage::plan($self, $resolved, $name, \@args);
909 7948 $self->_check_storage_paths($name, @{ $plan->{paths} });
910 7948 ▶ $self->_track_paths(@{ $plan->{paths} }) unless $self->{_opening};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opening"} 7306 642 7948
911 7948 return Data::Shared::Storage::construct($self, $plan);
912 }
913  
914 13883 ▶sub _install_recipe {
Subroutine _install_recipe: called CC=18 SCAR=28.9
915 13883 my ($self, $recipe) = @_;
916 13883 my $name = $recipe->{name};
917 13883 ▶ Carp::croak("Data::Shared: mount '$name' already exists") if $self->{mounts}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mounts"}{$name} 1 13882 13883
918 # Replay checked every recipe up front.
919 13882 ▶ $self->_check_storage_paths($name, @{ $recipe->{storage_paths} }) unless $self->{_opening};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opening"} 13463 419 13882
920 13877 my ($handle, $file, $composite, $entry);
921 13877 ▶ if ($recipe->{kind} eq 'transient') {
Branch: 2 branches
BranchTrueFalseTotal
if ($recipe->{'kind'} eq 'transient') { } 34 13843 13877
elsif ($recipe->{'kind'} eq 'composite') { } 2384 11459 13843
922 34 ▶ $handle = ref $recipe->{source} eq 'CODE' ? $recipe->{source}->($self, $name) : $recipe->{source};
Branch: 1 branch
BranchTrueFalseTotal
ref $recipe->{'source'} eq 'CODE' ? : 10 24 34
923 28 ▶ Carp::croak("Data::Shared: mount '$name' factory did not return a handle") unless blessed($handle);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($handle) 1 27 28
924 27 $entry = Data::Shared::Registry::entry_for_class(ref $handle);
925 } elsif ($recipe->{kind} eq 'composite') {
926 2384 ▶ $self->_track_paths($recipe->{dir}) unless $self->{_opening};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opening"} 2276 108 2384
927 $composite = Data::Shared::Composite->new(root => $self, name => $name,
928 node => $recipe->{node}, dir => $recipe->{dir}, path => [split m{/}, $name],
929 readonly => $self->{readonly}, strict_readonly => $self->{strict_readonly},
930 pending_paths => $self->{_pending_paths}, frozen_ok => $self->{_frozen_ok},
931 # Adoption must validate the chosen spec; replay tolerates legacy specs.
932 replaying => $self->{_opening} ? 1 : 0,
933 2384 ▶ opening => $self->{_opening} || (defined $recipe->{dir} && -e $recipe->{dir}));
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_opening'} ? : 108 2276 2384
Condition100%6/6
$self->{'_opening'} || defined $recipe->{'dir'} && -e $recipe->{'dir'}
l!l&&r!l&&!r
10862270
defined $recipe->{"dir"} and -e $recipe->{"dir"}
!ll&&!rl&&r
20861846
MC/DC100%3/3
$self->{'_opening'} || defined $recipe->{'dir'} && -e $recipe->{'dir'}
$self->{'_opening'} defined $recipe->{"dir"} -e $recipe->{"dir"}
Truth table100%4/4
A || B and C
A= $self->{'_opening'}B= defined $recipe->{"dir"}C= -e $recipe->{"dir"}
ABCresult
1XX1
0111
00X0
0100
934 2381 $handle = $composite;
935 2381 $file = $recipe->{dir};
936 2381 $entry = $recipe->{resolved}{entry};
937 } else {
938 11459 ▶ $self->_track_paths(@{ $recipe->{storage_paths} }) unless $self->{_opening};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_opening"} 11148 311 11459
939 11459 ($handle, $file) = Data::Shared::Storage::construct($self, $recipe->{plan});
940 11451 $entry = $recipe->{resolved}{entry};
941 }
942 13859 ▶ $entry ||= { key => ref($handle), dist => 'unknown', path_class => 'map' };
Condition100%2/2
$entry ||= {"key", ref $handle, "dist", "unknown", "path_class", "map"}
l!l
1381940
MC/DC100%1/1
$entry ||= {"key", ref $handle, "dist", "unknown", "path_class", "map"}
$entry
Truth table100%2/2
A
A= $entry
Aresult
11
00
943 $self->{mounts}{$name} = { name => $name, handle => $handle, entry => $entry,
944 spec => $recipe->{spec}, args => $recipe->{manifest_args}, file => $file,
945 transient => $recipe->{transient} ? 1 : 0, class => ref($handle), composite => $composite,
946 13859 ▶ storage_paths => $recipe->{storage_paths} };
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'transient'} ? : 27 13832 13859
947 13859 push @{ $self->{order} }, $name;
948 13859 my $depth = _nest_depth($name);
949 13859 ▶ $self->{_nest_depth} = $depth if $depth > $self->{_nest_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $self->{"_nest_depth"} 17 13842 13859
950 13859 $self->{_changed} = 1;
951 13859 ▶ $self->{_published} = 1 unless $recipe->{transient};
Branch: 1 branch
BranchTrueFalseTotal
unless $recipe->{"transient"} 13832 27 13859
952 13859 ▶ $self->{_published} = 1 if $self->_drop_retained(@{ $recipe->{storage_paths} });
Branch: 1 branch
BranchTrueFalseTotal
if $self->_drop_retained(@{$$recipe{"storage_paths"};}) 25 13834 13859
953 13859 ▶ return $composite ? Data::Shared::Node->new($self, [split m{/}, $name]) : $handle;
Branch: 1 branch
BranchTrueFalseTotal
$composite ? : 2381 11478 13859
954 }
955  
956 13520 ▶sub mount {
Subroutine mount: called CC=1 SCAR=0.0
Pod documented
957 13520 my ($self, $name, $spec, @args) = @_;
958 13520 _check_root($self);
959 13520 ▶ return $self->_mutate(sub { $self->_install_recipe($self->_recipe($name, $spec, @args)) });
Subroutine __ANON__: called CC=1 SCAR=0.0
960 }
961  
962 # Canonicalize lookup names as mount does, so '/a/' finds 'a'.
963 6778 ▶sub _canon_mount_name {
Subroutine _canon_mount_name: called CC=4 SCAR=15.2
964 6778 my ($name) = @_;
965 6778 ▶ return undef unless defined $name && !ref $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name 0 6778 6778
Condition33%1/3
defined $name and not ref $name
!ll&&!rl&&r
006778
MC/DC0%0/2
defined $name and not ref $name
defined $name not ref $name
Truth table33%1/3
A and not(B)
A= defined $nameB= not ref $name
ABresult
0X0
100
111
966 6778 $name =~ s{^/+}{};
967 6778 $name =~ s{/+$}{};
968 6778 ▶ return length $name ? $name : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $name ? : 6778 0 6778
969 }
970  
971 # 0 unless some name has a '/', which keeps _resolve on its single-lookup path.
972 14110 ▶sub _nest_depth {
Subroutine _nest_depth: called CC=4 SCAR=13.9
973 14110 my $deepest = 0;
974 14110 for my $name (@_) {
975 14483 my @parts = split m{/}, $name;
976 14483 ▶ $deepest = @parts if @parts > 1 && @parts > $deepest;
Branch: 1 branch
BranchTrueFalseTotal
if @parts > 1 and @parts > $deepest 20 14463 14483
Condition66%2/3
@parts > 1 and @parts > $deepest
!ll&&!rl&&r
14463020
MC/DC50%1/2
@parts > 1 and @parts > $deepest
@parts > 1 @parts > $deepest
Truth table66%2/3
A and B
A= @parts > 1B= @parts > $deepest
ABresult
0X0
100
111
977 }
978 14110 return $deepest;
979 }
980  
981 263 ▶sub unmount {
Subroutine unmount: called CC=5 SCAR=16.1
Pod documented
982 263 my ($self, $name, %opt) = @_;
983 263 my @unknown = sort grep { $_ ne 'unlink' } keys %opt;
984 263 ▶ Carp::croak("Data::Shared: unknown unmount option '$unknown[0]'") if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 262 263
985 262 $name = _canon_mount_name($name);
986 262 ▶ return 0 unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 262 262
987 262 ▶ $self->_check_unlinkable($name) if $opt{unlink};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"unlink"} 66 196 262
988 258 my $gone;
989 256 ▶ my $ret = $self->_mutate(sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
990 256 ▶ $gone = delete $self->{mounts}{$name} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$gone = delete $self->{"mounts"}{$name} or return 0 251 5 256
991 251 @{ $self->{order} } = grep { $_ ne $name } @{ $self->{order} };
992 251 $self->{_nest_depth} = _nest_depth(keys %{ $self->{mounts} });
993 251 $self->{_changed} = 1;
994 251 ▶ $self->{_published} = 1 unless $gone->{transient};
Branch: 1 branch
BranchTrueFalseTotal
unless $gone->{"transient"} 243 8 251
995 # Retain paths until unlink succeeds, including the crash window after publication.
996 251 ▶ $self->_record_retained($gone->{storage_paths}) unless $gone->{transient};
Branch: 1 branch
BranchTrueFalseTotal
unless $gone->{"transient"} 243 8 251
997 251 return 1;
998 258 ▶ }, $opt{unlink} ? sub { $self->_retire_storage($gone) } : undef);
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$opt{'unlink'} ? : 62 196 258
999 254 return $ret;
1000 }
1001  
1002 # Ownership follows backing storage, including aliases held by other handle objects.
1003 66 ▶sub _check_unlinkable {
Subroutine _check_unlinkable: called CC=9 SCAR=22.0
1004 66 my ($self, $name) = @_;
1005 # This check precedes _mutate; keep path caching local to it.
1006 66 local $self->{_abs_cache} = {};
1007 66 ▶ my $mount = $self->{mounts}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mount = $self->{"mounts"}{$name} or return 65 1 66
1008 65 my $handle = $mount->{handle};
1009 65 ▶ return unless blessed($handle);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($handle) 0 65 65
1010 65 my $addr = refaddr($handle);
1011 # Compare canonical paths by containment; composites own their whole directory.
1012 65 my @mine = map { $self->_abs_path($_) } _storage_of($mount);
1013 65 for my $other (@{ $self->{order} }) {
1014 69 ▶ next if $other eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $other eq $name 62 7 69
1015 7 my $sibling = $self->{mounts}{$other};
1016 7 ▶ my $shared = blessed($sibling->{handle}) && refaddr($sibling->{handle}) == $addr;
Condition66%2/3
builtin::blessed($sibling->{'handle'}) && builtin::refaddr($sibling->{'handle'}) == $addr
!ll&&!rl&&r
052
MC/DC50%1/2
builtin::blessed($sibling->{'handle'}) && builtin::refaddr($sibling->{'handle'}) == $addr
builtin::blessed($sibling->{'handle'}) builtin::refaddr($sibling->{'handle'}) == $addr
Truth table66%2/3
A && B
A= builtin::blessed($sibling->{'handle'})B= builtin::refaddr($sibling->{'handle'}) == $addr
ABresult
0X0
100
111
1017 7 ▶ unless ($shared) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shared) 5 2 7
1018 5 my @theirs = map { $self->_abs_path($_) } _storage_of($sibling);
1019 5 ▶ $shared = grep { my $m = $_; grep { _covers($m, $_) || _covers($_, $m) } @theirs } @mine;
Condition100%3/3
_covers($m, $_) || _covers($_, $m)
l!l&&r!l&&!r
113
MC/DC100%2/2
_covers($m, $_) || _covers($_, $m)
_covers($m, $_) _covers($_, $m)
Truth table100%3/3
A || B
A= _covers($m, $_)B= _covers($_, $m)
ABresult
1X1
011
000
1020 }
1021 7 ▶ next unless $shared;
Branch: 1 branch
BranchTrueFalseTotal
unless $shared 3 4 7
1022 4 Carp::croak("Data::Shared: mount '$name' shares its storage with '$other';"
1023 . " unmount '$other' as well, or unmount '$name' without unlink");
1024 }
1025 61 return;
1026 }
1027  
1028 9 ▶sub _covers {
Subroutine _covers: called CC=3 SCAR=11.0
1029 9 my ($outer, $inner) = @_;
1030 9 ▶ return 1 if $outer eq $inner;
Branch: 1 branch
BranchTrueFalseTotal
if $outer eq $inner 1 8 9
1031 8 ▶ return index($inner, "$outer/") == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
index($inner, "$outer/") == 0 ? : 1 7 8
1032 }
1033  
1034 # Caller-built transient handles have no recorded storage paths.
1035 70 ▶sub _storage_of {
Subroutine _storage_of: called CC=8 SCAR=22.7
1036 70 my ($mount) = @_;
1037 70 ▶ my @paths = @{ $mount->{storage_paths} || [] };
Condition50%1/2
$mount->{'storage_paths'} || []
l!l
700
MC/DC0%0/1
$mount->{'storage_paths'} || []
$mount->{'storage_paths'}
Truth table50%1/2
A
A= $mount->{'storage_paths'}
Aresult
11
00
1038 70 my $handle = $mount->{handle};
1039 70 ▶ if (!@paths && blessed($handle) && $handle->can('path')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @paths and builtin::blessed($handle) and $handle->can("path")) 6 64 70
Condition66%4/6
not @paths and builtin::blessed($handle) and $handle->can("path")
!ll&&!rl&&r
6406
not @paths and builtin::blessed($handle)
!ll&&!rl&&r
6406
MC/DC33%1/3
not @paths and builtin::blessed($handle) and $handle->can("path")
not @paths builtin::blessed($handle) $handle->can("path")
Truth table50%2/4
not(A) and B and C
A= not @pathsB= builtin::blessed($handle)C= $handle->can("path")
ABCresult
0XX0
10X0
1100
1111
1040 6 my $path = eval { $handle->path };
1041 6 ▶ push @paths, $path if defined $path && !ref $path && length $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path and not ref $path and length $path 6 0 6
Condition33%2/6
defined $path and not ref $path and length $path
!ll&&!rl&&r
006
defined $path and not ref $path
!ll&&!rl&&r
006
MC/DC0%0/3
defined $path and not ref $path and length $path
defined $path not ref $path length $path
Truth table25%1/4
A and not(B) and C
A= defined $pathB= not ref $pathC= length $path
ABCresult
0XX0
10X0
1100
1111
1042 }
1043 70 return @paths;
1044 }
1045  
1046 62 ▶sub _retire_storage {
Subroutine _retire_storage: called CC=8 SCAR=21.0
1047 62 my ($self, $gone) = @_;
1048 62 ▶ my $handle = $gone && $gone->{handle};
Condition66%2/3
$gone && $gone->{'handle'}
!ll&&!rl&&r
1061
MC/DC50%1/2
$gone && $gone->{'handle'}
$gone $gone->{'handle'}
Truth table66%2/3
A && B
A= $goneB= $gone->{'handle'}
ABresult
0X0
100
111
1049 # A transient mount's storage belongs to whoever built the handle.
1050 62 ▶ return $self->_forget_retained($gone) if $gone->{transient};
Branch: 1 branch
BranchTrueFalseTotal
if $gone->{"transient"} 2 60 62
1051 60 ▶ return $self->_forget_retained($gone) unless $handle && $handle->can('unlink');
Branch: 1 branch
BranchTrueFalseTotal
unless $handle and $handle->can("unlink") 1 59 60
Condition66%2/3
$handle and $handle->can("unlink")
!ll&&!rl&&r
1059
MC/DC50%1/2
$handle and $handle->can("unlink")
$handle $handle->can("unlink")
Truth table66%2/3
A and B
A= $handleB= $handle->can("unlink")
ABresult
0X0
100
111
1052 # Some backends report a failed removal by returning false, not croaking.
1053 59 ▶ eval { $handle->unlink; 1 } or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $handle->unlink; 1 } } or die $@ 59 0 59
1054 59 ▶ my ($left) = grep { _present($_) } @{ $gone->{storage_paths} || [] };
Condition50%1/2
$gone->{'storage_paths'} || []
l!l
590
MC/DC0%0/1
$gone->{'storage_paths'} || []
$gone->{'storage_paths'}
Truth table50%1/2
A
A= $gone->{'storage_paths'}
Aresult
11
00
1055 59 ▶ Carp::croak("Data::Shared: cannot unlink '$left'") if defined $left;
Branch: 1 branch
BranchTrueFalseTotal
if defined $left 1 58 59
1056 58 return $self->_forget_retained($gone);
1057 }
1058  
1059 61 ▶sub _forget_retained {
Subroutine _forget_retained: called CC=5 SCAR=16.2
1060 61 my ($self, $gone) = @_;
1061 61 ▶ return unless $self->_drop_retained(@{ ($gone && $gone->{storage_paths}) || [] });
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_drop_retained(@{$gone and $gone->{"storage_paths"} or [];}) 3 58 61
Condition80%4/5
$gone && $gone->{'storage_paths'} || []
l!l
601
$gone and $gone->{"storage_paths"}
!ll&&!rl&&r
0160
MC/DC50%1/2
$gone && $gone->{'storage_paths'} || []
$gone $gone->{"storage_paths"}
Truth table66%2/3
A and B
A= $goneB= $gone->{"storage_paths"}
ABresult
111
0X0
100
1062 58 $self->{_revision}++;
1063 58 ▶ $self->_write_manifest unless $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"readonly"} 58 0 58
1064 58 return;
1065 }
1066  
1067 13920 ▶sub _drop_retained {
Subroutine _drop_retained: called CC=3 SCAR=11.0
1068 13920 my ($self, @paths) = @_;
1069 13920 ▶ return 0 unless @paths && @{ $self->{_retained} };
Branch: 1 branch
BranchTrueFalseTotal
unless @paths and @{$self->{"_retained"};} 13572 348 13920
Condition100%3/3
@paths and @{$self->{"_retained"};}
!ll&&!rl&&r
124921080348
MC/DC100%2/2
@paths and @{$self->{"_retained"};}
@paths @{$self->{"_retained"};}
Truth table100%3/3
A and B
A= @pathsB= @{$self->{"_retained"};}
ABresult
0X0
100
111
1070 348 my %drop = map { $self->_ledger_form($_) => 1 } @paths;
1071 348 my $before = @{ $self->{_retained} };
1072 348 @{ $self->{_retained} } = grep { !$drop{$_} } @{ $self->{_retained} };
1073 348 return @{ $self->{_retained} } != $before;
1074 }
1075  
1076 # Relative inside the root, so the ledger survives relocating it; absolute outside.
1077 605 ▶sub _ledger_form {
Subroutine _ledger_form: called CC=6 SCAR=18.5
1078 605 my ($self, $path) = @_;
1079 605 my $abs = $self->_abs_path($path);
1080 605 ▶ return $abs unless defined $self->{dir} && length $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} and length $self->{"dir"} 1 604 605
Condition66%2/3
defined $self->{"dir"} and length $self->{"dir"}
!ll&&!rl&&r
10604
MC/DC50%1/2
defined $self->{"dir"} and length $self->{"dir"}
defined $self->{"dir"} length $self->{"dir"}
Truth table66%2/3
A and B
A= defined $self->{"dir"}B= length $self->{"dir"}
ABresult
0X0
100
111
1081 604 my $dir = $self->_abs_path($self->{dir});
1082 604 ▶ return $abs unless defined $dir && length $dir && index($abs, "$dir/") == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and length $dir and index($abs, "$dir/") == 0 5 599 604
Condition50%3/6
defined $dir and length $dir and index($abs, "$dir/") == 0
!ll&&!rl&&r
05599
defined $dir and length $dir
!ll&&!rl&&r
00604
MC/DC33%1/3
defined $dir and length $dir and index($abs, "$dir/") == 0
defined $dir length $dir index($abs, "$dir/") == 0
Truth table50%2/4
A and B and C
A= defined $dirB= length $dirC= index($abs, "$dir/") == 0
ABCresult
0XX0
10X0
1100
1111
1083 599 return substr $abs, length($dir) + 1;
1084 }
1085  
1086 86 ▶sub _ledger_resolve {
Subroutine _ledger_resolve: called CC=4 SCAR=13.9
1087 86 my ($self, $entry) = @_;
1088 86 ▶ return $entry if $entry =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ m[\A/] 7 79 86
1089 79 ▶ return $entry unless defined $self->{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"dir"} 0 79 79
1090 # Cwd ledger entries are bytes; encode the root directory before concatenating.
1091 79 my $dir = $self->{dir};
1092 79 ▶ utf8::encode($dir) if utf8::is_utf8($dir);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($dir) 3 76 79
1093 79 return "$dir/$entry";
1094 }
1095  
1096 265 ▶sub _record_retained {
Subroutine _record_retained: called CC=4 SCAR=13.9
1097 265 my ($self, $paths) = @_;
1098 265 ▶ return unless $paths && @$paths;
Branch: 1 branch
BranchTrueFalseTotal
unless $paths and @$paths 9 256 265
Condition66%2/3
$paths and @$paths
!ll&&!rl&&r
09256
MC/DC50%1/2
$paths and @$paths
$paths @$paths
Truth table66%2/3
A and B
A= $pathsB= @$paths
ABresult
0X0
100
111
1099 # Deduplicate: rotation can retain the same path every cycle.
1100 256 my %have = map { $_ => 1 } @{ $self->{_retained} };
1101 256 my @new = grep { !$have{$_}++ } map { $self->_ledger_form($_) } @$paths;
1102 256 ▶ return unless @new;
Branch: 1 branch
BranchTrueFalseTotal
unless @new 0 256 256
1103 256 push @{ $self->{_retained} }, @new;
1104 256 $self->{_published} = 1;
1105 256 return;
1106 }
1107  
1108 37 ▶sub handle {
Subroutine handle: called CC=8 SCAR=20.8
Pod documented
1109 37 my ($self, $path) = @_;
1110 37 _check_root($self);
1111 37 ▶ return $self if !defined $path || (!ref $path && ($path eq '' || $path eq '/'));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or not ref $path and $path eq "" || $path eq "/" 2 35 37
Condition88%8/9
not defined $path or not ref $path and $path eq "" || $path eq "/"
l!l&&r!l&&!r
1135
not ref $path and $path eq "" || $path eq "/"
!ll&&!rl&&r
6291
$path eq "" or $path eq "/"
l!l&&r!l&&!r
0129
MC/DC75%3/4
not defined $path or not ref $path and $path eq "" || $path eq "/"
not defined $path not ref $path $path eq "" $path eq "/"
Truth table80%4/5
not(A) or not(B) and C or D
A= not defined $pathB= not ref $pathC= $path eq ""D= $path eq "/"
ABCDresult
1XXX1
011X1
01011
00XX0
01000
1112 35 my @components = @{ $self->_path_components($path) };
1113 34 ▶ return $self unless @components;
Branch: 1 branch
BranchTrueFalseTotal
unless @components 2 32 34
1114 32 my (undef, $mount, $rest) = _resolve($self, \@components);
1115 32 ▶ if (my $comp = $mount->{composite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $mount->{"composite"}) 10 22 32
1116 10 return $comp->handle_at($self, $rest);
1117 }
1118 22 ▶ Carp::croak("Data::Shared: handle() path must name a mount exactly (got extra components)")
Branch: 1 branch
BranchTrueFalseTotal
if @$rest 1 21 22
1119 if @$rest;
1120 21 return $mount->{handle};
1121 }
1122  
1123 # Also used by Node::_abs, which prepends its cursor.
1124 157 ▶sub _rel_components {
Subroutine _rel_components: called CC=4 SCAR=13.9
1125 157 my ($path) = @_;
1126 157 ▶ return [ @{ $path->{components} } ]
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($path) and $path->isa("Data::Shared::Compiled") 3 154 157
Condition66%2/3
builtin::blessed($path) and $path->isa("Data::Shared::Compiled")
!ll&&!rl&&r
15403
MC/DC50%1/2
builtin::blessed($path) and $path->isa("Data::Shared::Compiled")
builtin::blessed($path) $path->isa("Data::Shared::Compiled")
Truth table66%2/3
A and B
A= builtin::blessed($path)B= $path->isa("Data::Shared::Compiled")
ABresult
0X0
100
111
1127 if blessed($path) && $path->isa('Data::Shared::Compiled');
1128 154 ▶ return _check_components([ @$path ]) if ref $path eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $path eq "ARRAY" 9 145 154
1129 145 return _parse_string_path($path);
1130 }
1131  
1132 143 ▶sub _path_components {
Subroutine _path_components: called CC=4 SCAR=15.2
1133 143 my ($self, $path) = @_;
1134 143 ▶ return [] if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 143 143
1135 0 ▶ return [ @{ $path->{components} } ] if blessed($path) && $path->isa('Data::Shared::Node');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($path) and $path->isa("Data::Shared::Node") 0 143 143
Condition66%2/3
builtin::blessed($path) and $path->isa("Data::Shared::Node")
!ll&&!rl&&r
14120
MC/DC0%0/2
builtin::blessed($path) and $path->isa("Data::Shared::Node")
builtin::blessed($path) $path->isa("Data::Shared::Node")
Truth table66%2/3
A and B
A= builtin::blessed($path)B= $path->isa("Data::Shared::Node")
ABresult
0X0
100
111
1136 143 return _rel_components($path);
1137 }
1138  
1139 31 ▶sub node {
Subroutine node: called CC=1 SCAR=0.0
Pod undocumented
1140 31 my ($self, $path) = @_;
1141 31 _check_root($self);
1142 31 return Data::Shared::Node->new($self, $self->_path_components($path));
1143 }
1144  
1145 77 ▶sub children {
Subroutine children: called CC=3 SCAR=11.0
Pod undocumented
1146 77 my ($self, $path) = @_;
1147 77 _check_root($self);
1148 77 my @components = @{ $self->_path_components($path) };
1149 76 ▶ Carp::croak("Data::Shared: children() needs a composite path") unless @components;
Branch: 1 branch
BranchTrueFalseTotal
unless @components 0 76 76
1150 76 my ($name, $mount, $rest) = _resolve($self, \@components);
1151 74 ▶ Carp::croak("Data::Shared: mount '$name' is not composite") unless $mount->{composite};
Branch: 1 branch
BranchTrueFalseTotal
unless $mount->{"composite"} 2 72 74
1152 72 return $mount->{composite}->children_at($self, $rest);
1153 }
1154  
1155 {
1156 39 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1157 39 *shared_node = \&node;
1158 39 *shared_children = \&children;
1159 }
1160  
1161 # sort has undefined scalar-context behavior; a named array also returns a count.
1162 62 ▶sub mounts { my @k = sort keys %{ $_[0]{mounts} }; return @k }
Subroutine mounts: called CC=1 SCAR=0.0
Pod documented
1163 2 ▶sub mount_names { return $_[0]->mounts }
Subroutine mount_names: called CC=1 SCAR=0.0
Pod undocumented
1164  
1165 6516 ▶sub mount_info {
Subroutine mount_info: called CC=4 SCAR=13.9
Pod documented
1166 6516 my ($self, $name) = @_;
1167 6516 $name = _canon_mount_name($name);
1168 6516 ▶ my $m = defined $name ? $self->{mounts}{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 6516 0 6516
1169 6516 ▶ return undef unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 203 6313 6516
1170 return { name => $name, class => $m->{class}, key => $m->{entry}{key},
1171 dist => $m->{entry}{dist}, path_class => $m->{entry}{path_class},
1172 file => $m->{file}, transient => $m->{transient},
1173 6313 ▶ composite => $m->{composite} ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
$m->{'composite'} ? : 4 6309 6313
1174 }
1175  
1176 8 ▶sub sync_all {
Subroutine sync_all: called CC=4 SCAR=13.9
Pod documented
1177 8 my ($self) = @_;
1178 8 my $n = 0;
1179 8 for my $name (@{ $self->{order} }) {
1180 8 my $h = $self->{mounts}{$name}{handle};
1181 8 ▶ next unless $h->can('sync');
Branch: 1 branch
BranchTrueFalseTotal
unless $h->can("sync") 0 8 8
1182 8 ▶ if ($h->isa('Data::Shared::Composite')) { $n += $h->sync }
Branch: 1 branch
BranchTrueFalseTotal
if ($h->isa('Data::Shared::Composite')) { } 7 1 8
1183 1 else { $h->sync; $n++ }
1184 }
1185 8 return $n;
1186 }
1187  
1188 109 ▶sub freeze_all {
Subroutine freeze_all: called CC=2 SCAR=6.9
Pod documented
1189 109 my ($self) = @_;
1190 109 ▶ Carp::croak("Data::Shared: cannot freeze a read-only root") if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 1 108 109
1191 108 ▶ return Data::Shared::Manifest::with_lock($self, 1, sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
1192 108 $self->_assert_revision;
1193 107 my @shipped = grep { !$self->{mounts}{$_}{transient} } @{ $self->{order} };
1194 # Sealing is one-way, so a store that could not ship is refused whole.
1195 107 for my $name (@shipped) {
1196 324 my $m = $self->{mounts}{$name};
1197 324 my $h = $m->{handle};
1198 my $class = $h->isa('Data::Shared::Composite') ? $h->_unsealable
1199 324 ▶ : $h->can('freeze') || $m->{entry}{immutable} ? undef : ref $h;
Branch: 2 branches
BranchTrueFalseTotal
$h->isa('Data::Shared::Composite') ? : 97 227 324
$h->can('freeze') || $m->{'entry'}{'immutable'} ? : 226 1 227
Condition66%2/3
$h->can("freeze") or $m->{"entry"}{"immutable"}
l!l&&r!l&&!r
22601
MC/DC50%1/2
$h->can("freeze") or $m->{"entry"}{"immutable"}
$h->can("freeze") $m->{"entry"}{"immutable"}
Truth table66%2/3
A or B
A= $h->can("freeze")B= $m->{"entry"}{"immutable"}
ABresult
1X1
011
000
1200 324 ▶ Carp::croak("Data::Shared: cannot freeze: mount '$name' ($class) cannot be sealed;"
Branch: 1 branch
BranchTrueFalseTotal
if defined $class 2 322 324
1201 . " nothing was frozen") if defined $class;
1202 }
1203 105 my $n = 0;
1204 # A failing seal leaves the mounts before it sealed, in mount order.
1205 105 for my $name (@shipped) {
1206 318 my $h = $self->{mounts}{$name}{handle};
1207 318 ▶ next unless $h->can('freeze');
Branch: 1 branch
BranchTrueFalseTotal
unless $h->can("freeze") 0 318 318
1208 # Backends may reject a second freeze.
1209 318 ▶ next if $h->can('frozen') && $h->frozen;
Branch: 1 branch
BranchTrueFalseTotal
if $h->can("frozen") and $h->frozen 7 311 318
Condition66%2/3
$h->can("frozen") and $h->frozen
!ll&&!rl&&r
03117
MC/DC50%1/2
$h->can("frozen") and $h->frozen
$h->can("frozen") $h->frozen
Truth table66%2/3
A and B
A= $h->can("frozen")B= $h->frozen
ABresult
0X0
100
111
1210 311 ▶ if ($h->isa('Data::Shared::Composite')) { $n += $h->freeze }
Branch: 1 branch
BranchTrueFalseTotal
if ($h->isa('Data::Shared::Composite')) { } 93 218 311
1211 218 else { $h->freeze; $n++ }
1212 }
1213 104 return $n;
1214 108 });
1215 }
1216  
1217 14 ▶sub frozen {
Subroutine frozen: called CC=8 SCAR=20.9
Pod documented
1218 14 my ($self) = @_;
1219 14 my $shipped = 0;
1220 14 for my $name (@{ $self->{order} }) {
1221 24 my $mount = $self->{mounts}{$name};
1222 24 ▶ next if $mount->{transient};
Branch: 1 branch
BranchTrueFalseTotal
if $mount->{"transient"} 3 21 24
1223 21 $shipped++;
1224 21 my $handle = $mount->{handle};
1225 21 ▶ if ($handle->can('frozen')) { return 0 unless $handle->frozen }
Branch: 3 branches
BranchTrueFalseTotal
if ($handle->can('frozen')) { } 20 1 21
elsif (not $mount->{'entry'} && $mount->{'entry'}{'immutable'}) { } 1 0 1
unless $handle->frozen 2 18 20
1226 # Immutable build-then-load backends need no sealing.
1227 1 ▶ elsif (!($mount->{entry} && $mount->{entry}{immutable})) { return 0 }
Condition33%1/3
$mount->{'entry'} && $mount->{'entry'}{'immutable'}
!ll&&!rl&&r
010
MC/DC0%0/2
$mount->{'entry'} && $mount->{'entry'}{'immutable'}
$mount->{'entry'} $mount->{'entry'}{'immutable'}
Truth table33%1/3
A && B
A= $mount->{'entry'}B= $mount->{'entry'}{'immutable'}
ABresult
0X0
100
111
1228 }
1229 11 ▶ return $shipped ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$shipped ? : 9 2 11
1230 }
1231  
1232 49 ▶sub unlink_all {
Subroutine unlink_all: called CC=2 SCAR=7.0
Pod documented
1233 49 my ($self) = @_;
1234 49 ▶ Carp::croak("Data::Shared: root is read-only, cannot unlink") if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 2 47 49
1235 47 ▶ return Data::Shared::Manifest::with_lock($self, 1, sub {
Subroutine __ANON__: called CC=29 SCAR=34.5
1236 47 ▶ my $published = !defined $self->{dir} || -e $self->manifest_path;
Condition100%3/3
!defined($self->{'dir'}) || -e $self->manifest_path
l!l&&r!l&&!r
1433
MC/DC100%2/2
!defined($self->{'dir'}) || -e $self->manifest_path
!defined($self->{'dir'}) -e $self->manifest_path
Truth table100%3/3
not(A) || B
A= !defined($self->{'dir'})B= -e $self->manifest_path
ABresult
1X1
011
000
1237 47 ▶ return 0 unless $published || @{ $self->{order} } || @{ $self->{_retained} };
Branch: 1 branch
BranchTrueFalseTotal
unless $published or @{$self->{"order"};} or @{$self->{"_retained"};} 2 45 47
Condition83%5/6
$published or @{$self->{"order"};} or @{$self->{"_retained"};}
l!l&&r!l&&!r
4502
$published or @{$self->{"order"};}
l!l&&r!l&&!r
4412
MC/DC66%2/3
$published or @{$self->{"order"};} or @{$self->{"_retained"};}
$published @{$self->{"order"};} @{$self->{"_retained"};}
Truth table75%3/4
A or B or C
A= $publishedB= @{$self->{"order"};}C= @{$self->{"_retained"};}
ABCresult
1XX1
01X1
0011
0000
1238 45 ▶ $self->_assert_revision if $published;
Branch: 1 branch
BranchTrueFalseTotal
if $published 44 1 45
1239 41 my $n = 0;
1240 41 my @retiring = map { $self->{mounts}{$_} } @{ $self->{order} };
1241 # Publish the removal before taking the storage, as unmount does, so the
1242 # ledger lets any root finish a teardown that fails partway.
1243 41 ▶ if ($published && defined $self->{dir} && @retiring) {
Branch: 1 branch
BranchTrueFalseTotal
if ($published and defined $self->{"dir"} and @retiring) 20 21 41
Condition100%6/6
$published and defined $self->{"dir"} and @retiring
!ll&&!rl&&r
21920
$published and defined $self->{"dir"}
!ll&&!rl&&r
1139
MC/DC100%3/3
$published and defined $self->{"dir"} and @retiring
$published defined $self->{"dir"} @retiring
Truth table100%4/4
A and B and C
A= $publishedB= defined $self->{"dir"}C= @retiring
ABCresult
0XX0
10X0
1100
1111
1244 20 $self->_record_retained($_->{storage_paths}) for @retiring;
1245 20 @{$self}{qw(mounts order _nest_depth)} = ({}, [], 0);
1246 20 $self->{_revision}++;
1247 20 $self->_write_manifest;
1248 20 $self->_invalidate_compiled;
1249 }
1250 41 for my $mount (@retiring) {
1251 23 my $handle = $mount->{handle};
1252 23 ▶ next if $mount->{transient};
Branch: 1 branch
BranchTrueFalseTotal
if $mount->{"transient"} 1 22 23
1253 22 ▶ next unless $handle->can('unlink');
Branch: 1 branch
BranchTrueFalseTotal
unless $handle->can("unlink") 0 22 22
1254 # Native unlink's return value varies by backend; count removals instead.
1255 22 ▶ my @paths = grep { length } @{ $mount->{storage_paths} || [] };
Condition50%1/2
$mount->{'storage_paths'} || []
l!l
220
MC/DC0%0/1
$mount->{'storage_paths'} || []
$mount->{'storage_paths'}
Truth table50%1/2
A
A= $mount->{'storage_paths'}
Aresult
11
00
1256 22 my $before = grep { -e } @paths;
1257 22 $handle->unlink;
1258 21 ▶ $n += @paths ? $before - grep { -e } @paths : 1;
Branch: 1 branch
BranchTrueFalseTotal
@paths ? : 21 0 21
1259 }
1260 # Failed removals must stay retryable, so the manifest carrying the ledger goes last.
1261 40 ▶ if (@{ $self->{_retained} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_retained"};}) 37 3 40
1262 37 my %seen;
1263 37 my @entries = grep { !$seen{$_}++ } @{ $self->{_retained} };
1264 37 my %path = map { $_ => $self->_ledger_resolve($_) } @entries;
1265 37 my $existed = grep { _present($path{$_}) } @entries;
1266 37 my @paths = map { $path{$_} } @entries;
1267 37 my $held = _lock_composite_dirs(\@paths);
1268 37 my $failed = _cleanup_paths(\@paths);
1269 37 undef $held;
1270 37 my @left = grep { _present($path{$_}) } @entries;
1271 37 $n += $existed - @left;
1272 37 @{ $self->{_retained} } = @left;
1273 37 ▶ Carp::croak("Data::Shared: $failed") if length $failed;
Branch: 1 branch
BranchTrueFalseTotal
if length $failed 2 35 37
1274 }
1275 # Teardown also reclaims unpublished composite storage left by interrupted creation.
1276 38 ▶ if (defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dir"}) 37 1 38
1277 # readdir returns bytes: join names through _ledger_resolve, not to {dir}.
1278 37 my $children = $self->_ledger_resolve('.children');
1279 37 ▶ if (opendir my $dh, $children) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $children) 19 18 37
1280 0 ▶ my @orphans = map { "$children/$_" } grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition66%2/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
19190
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table66%2/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
1281 19 closedir $dh;
1282 19 ▶ if (@orphans) {
Branch: 1 branch
BranchTrueFalseTotal
if (@orphans) 0 19 19
1283 0 my $held = _lock_composite_dirs(\@orphans);
1284 0 my $failed = _cleanup_paths(\@orphans);
1285 0 undef $held;
1286 0 ▶ Carp::croak("Data::Shared: $failed") if length $failed;
Branch: 1 branch
BranchTrueFalseTotal
if length $failed 0 0 0
1287 0 $n += @orphans;
1288 }
1289 }
1290 37 rmdir $children;
1291 # Strays of interrupted mounts and manifest writes; every manifest write
1292 # holds this lock, so a .manifest- temp seen here is abandoned.
1293 37 ▶ if (opendir my $dh, $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $self->{"dir"}) 37 0 37
1294 5 my @stray = map { $self->_ledger_resolve($_) }
1295 37 ▶ grep { /\.shm\z/ || /\A\.manifest-/ } readdir $dh;
Condition100%3/3
/\.shm\z/ || /\A\.manifest-/
l!l&&r!l&&!r
41148
MC/DC100%2/2
/\.shm\z/ || /\A\.manifest-/
/\.shm\z/ /\A\.manifest-/
Truth table100%3/3
A || B
A= /\.shm\z/B= /\A\.manifest-/
ABresult
1X1
011
000
1296 37 closedir $dh;
1297 37 ▶ $n += grep { -f $_ && CORE::unlink $_ } @stray;
Condition66%2/3
-f $_ && unlink($_)
!ll&&!rl&&r
104
MC/DC50%1/2
-f $_ && unlink($_)
-f $_ unlink($_)
Truth table66%2/3
A && B
A= -f $_B= unlink($_)
ABresult
0X0
100
111
1298 }
1299 }
1300 38 ▶ if ($published && defined $self->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($published and defined $self->{"dir"}) 36 2 38
Condition100%3/3
$published and defined $self->{"dir"}
!ll&&!rl&&r
1136
MC/DC100%2/2
$published and defined $self->{"dir"}
$published defined $self->{"dir"}
Truth table100%3/3
A and B
A= $publishedB= defined $self->{"dir"}
ABresult
0X0
100
111
1301 36 ▶ if (CORE::unlink($self->manifest_path)) { $n++ }
Branch: 2 branches
BranchTrueFalseTotal
if (unlink $self->manifest_path) { } 36 0 36
elsif (not $!{'ENOENT'}) { } 0 0 0
1302 0 elsif (!$!{ENOENT}) { Carp::croak("Data::Shared: cannot unlink manifest: $!") }
1303 }
1304 38 $self->{mounts} = {};
1305 38 $self->{order} = [];
1306 38 $self->{_nest_depth} = 0;
1307 38 $self->_invalidate_compiled;
1308 38 return $n;
1309 47 });
1310 }
1311  
1312 13 ▶sub stats {
Subroutine stats: called CC=3 SCAR=11.0
Pod documented
1313 13 my ($self) = @_;
1314 13 my %out;
1315 13 for my $name ($self->mounts) {
1316 14 my $h = $self->{mounts}{$name}{handle};
1317 14 ▶ $out{$name} = $h->can('stats') ? $h->stats : { class => ref $h };
Branch: 1 branch
BranchTrueFalseTotal
$h->can('stats') ? : 13 1 14
1318 }
1319 13 return \%out;
1320 }
1321  
1322 {
1323 39 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
1324 39 *get = \&shared_get;
1325 39 *set = \&shared_set;
1326 39 *delete = \&shared_delete;
1327 39 *exists = \&shared_exists;
1328 39 *incr = \&shared_incr;
1329 39 *call = \&shared_call;
1330 39 *push = \&shared_push;
1331 39 *pop = \&shared_pop;
1332 }
1333 1 ▶sub compile { my ($s, @a) = @_; return shared_compile(@a) }
Subroutine compile: called CC=1 SCAR=0.0
Pod undocumented
1334  
1335 39 1;
1336  
1337 __END__
« blib/lib/Data/Shared/Registry.pm ↑ Summary blib/lib/Data/Shared/Adapter/Keyed.pm »