blib/lib/Data/Shared/Storage.pm

filter: Statementstmt 100% 132 / 132 Branchbran 91.8% 90 / 98 Conditioncond 79.1% 91 / 115 MC/DCmcdc 60.9% 39 / 64 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 85.4% 363 / 425 CC 91 SCAR 35.5
CC
91
Cov
91%
plan
53.8
construct
24.4
_load
8.2
CRAP 34.7
↑ Summary blib/lib/Data/Shared/Manifest.pm »
1 package Data::Shared::Storage;
2 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use Data::Shared::Manifest ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 our $VERSION = '0.02';
9  
10 39 our @CARP_NOT = qw(Data::Shared Data::Shared::Manifest Data::Shared::Storage
11 Data::Shared::Composite);
12 39 my %LOADED;
13  
14 24493 ▶sub plan {
Subroutine plan: called CC=52 SCAR=39.9
Pod undocumented
15 24493 my ($root, $resolved, $name, $args) = @_;
16 24493 my $class = $resolved->{class};
17 24493 my @args = @$args;
18 24493 my $plan = { resolved => $resolved, name => $name, args => \@args, paths => [] };
19 24493 my @explicit;
20 24493 $plan->{kind} = $resolved->{convention};
21 24493 ▶ if ($plan->{kind} eq 'handle') {
Branch: 2 branches
BranchTrueFalseTotal
if ($plan->{'kind'} eq 'handle') { } 20 24473 24493
elsif ($plan->{'kind'} eq 'options') { } 42 24431 24473
22 20 ▶ if (@args == 1 && defined $args[0] && !ref $args[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args == 1 and defined $args[0] and not ref $args[0]) { } 2 18 20
elsif (@args == 1 and ref $args[0] eq 'HASH') { } 17 1 18
Condition83%5/6
@args == 1 and defined $args[0] and not ref $args[0]
!ll&&!rl&&r
1172
@args == 1 and defined $args[0]
!ll&&!rl&&r
1019
MC/DC66%2/3
@args == 1 and defined $args[0] and not ref $args[0]
@args == 1 defined $args[0] not ref $args[0]
Truth table75%3/4
A and B and not(C)
A= @args == 1B= defined $args[0]C= not ref $args[0]
ABCresult
0XX0
10X0
1100
1111
23 2 $plan->{file} = $args[0];
24 2 push @explicit, $args[0];
25 ▶ } elsif (@args == 1 && ref $args[0] eq 'HASH') {
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
1017
MC/DC50%1/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
26 17 my $opt = $args[0];
27 17 $plan->{file} = $opt->{path};
28 17 ▶ push @explicit, $opt->{path} if defined $opt->{path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"path"} 3 14 17
29 17 ▶ $plan->{file} = $root->_file_for($name) if !defined $plan->{file} && defined $root->{dir};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $plan->{"file"} and defined $root->{"dir"} 14 3 17
Condition66%2/3
not defined $plan->{"file"} and defined $root->{"dir"}
!ll&&!rl&&r
3014
MC/DC50%1/2
not defined $plan->{"file"} and defined $root->{"dir"}
not defined $plan->{"file"} defined $root->{"dir"}
Truth table66%2/3
not(A) and B
A= not defined $plan->{"file"}B= defined $root->{"dir"}
ABresult
0X0
100
111
30 17 ▶ $plan->{build} = exists $opt->{build_int} ? 'build_int' : exists $opt->{build_str} ? 'build_str' : undef;
Branch: 2 branches
BranchTrueFalseTotal
exists $opt->{'build_int'} ? : 9 8 17
exists $opt->{'build_str'} ? : 2 6 8
31 17 ▶ $plan->{keys} = $opt->{ $plan->{build} } if $plan->{build};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"build"} 11 6 17
32 Carp::croak('Data::Shared: perfecthash build keys must be an ARRAY reference')
33 17 ▶ if $plan->{build} && ref $plan->{keys} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"build"} and ref $plan->{"keys"} ne "ARRAY" 0 17 17
Condition66%2/3
$plan->{"build"} and ref $plan->{"keys"} ne "ARRAY"
!ll&&!rl&&r
6110
MC/DC0%0/2
$plan->{"build"} and ref $plan->{"keys"} ne "ARRAY"
$plan->{"build"} ref $plan->{"keys"} ne "ARRAY"
Truth table66%2/3
A and B
A= $plan->{"build"}B= ref $plan->{"keys"} ne "ARRAY"
ABresult
0X0
100
111
34 } else {
35 1 Carp::croak('Data::Shared: a perfecthash spec takes a built file path or a'
36 . ' {build_int|build_str, path} hashref; pass a factory or a loaded'
37 . ' handle as the spec itself instead');
38 }
39 19 ▶ Carp::croak('Data::Shared: perfecthash mount requires a path') unless defined $plan->{file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plan->{"file"} 0 19 19
40 } elsif ($plan->{kind} eq 'options') {
41 42 ▶ Carp::croak("Data::Shared: sortedset:strings takes options, not a path"
Branch: 1 branch
BranchTrueFalseTotal
if @args and !defined($args[0]) || !ref($args[0]) && $args[0] eq ":file" 2 40 42
Condition88%8/9
@args and !defined($args[0]) || !ref($args[0]) && $args[0] eq ":file"
!ll&&!rl&&r
0402
not defined $args[0] or not ref $args[0] and $args[0] eq ":file"
l!l&&r!l&&!r
1140
not ref $args[0] and $args[0] eq ":file"
!ll&&!rl&&r
3821
MC/DC75%3/4
@args and !defined($args[0]) || !ref($args[0]) && $args[0] eq ":file"
@args not defined $args[0] not ref $args[0] $args[0] eq ":file"
Truth table80%4/5
A and not(B) or not(C) and D
A= @argsB= not defined $args[0]C= not ref $args[0]D= $args[0] eq ":file"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
42 . " placeholder: pass max => N (and optionally set/keys)")
43 if @args && (!defined $args[0] || (!ref $args[0] && $args[0] eq ':file'));
44 40 ▶ Carp::croak('Data::Shared: sortedset:strings options must be a hashref or key/value pairs')
Branch: 1 branch
BranchTrueFalseTotal
if not @args == 1 && ref $args[0] eq "HASH" and @args % 2 1 39 40
Condition83%5/6
not @args == 1 && ref $args[0] eq "HASH" and @args % 2
!ll&&!rl&&r
3721
@args == 1 && ref $args[0] eq 'HASH'
!ll&&!rl&&r
3037
MC/DC66%2/3
not @args == 1 && ref $args[0] eq "HASH" and @args % 2
@args == 1 ref $args[0] eq 'HASH' @args % 2
Truth table60%3/5
not(A && B) and C
A= @args == 1B= ref $args[0] eq 'HASH'C= @args % 2
ABCresult
11X0
0X00
1000
0X11
1011
45 if !(@args == 1 && ref $args[0] eq 'HASH') && @args % 2;
46 39 ▶ my %opt = @args == 1 && ref $args[0] eq 'HASH' ? %{ $args[0] } : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 && ref $args[0] eq 'HASH' ? : 37 2 39
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
2037
MC/DC50%1/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
47 39 ▶ Carp::croak("Data::Shared: sortedset:strings mount requires 'max'") unless defined $opt{max};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt{"max"} 3 36 39
48 36 push @explicit, grep { defined $_ } @opt{qw(set keys)};
49 36 ▶ if (defined $root->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $root->{"dir"}) 25 11 36
50 25 ▶ $opt{set} = $root->_file_for($name) unless defined $opt{set};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt{"set"} 23 2 25
51 25 ▶ $opt{keys} = $root->_file_for($name . '__keys') unless defined $opt{keys};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt{"keys"} 24 1 25
52 }
53 36 $plan->{options} = \%opt;
54 36 $plan->{file} = $opt{set};
55 36 $plan->{paths} = [grep { defined $_ } @opt{qw(set keys)}];
56 } else {
57 24431 ▶ if (defined $root->{dir} && (!@args || !defined $args[0] || (!ref $args[0] && $args[0] eq ':file'))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $root->{'dir'} and !(@args && defined $args[0]) || !ref($args[0]) && $args[0] eq ':file') { } 3557 20874 24431
elsif (@args and defined $args[0] and not ref $args[0]) { } 26 41693 41719
Condition75%9/12
defined $root->{"dir"} and !(@args && defined $args[0]) || !ref($args[0]) && $args[0] eq ":file"
!ll&&!rl&&r
20847273557
not @args && defined $args[0] or not ref $args[0] and $args[0] eq ":file"
l!l&&r!l&&!r
3557027
@args && defined $args[0]
!ll&&!rl&&r
0355727
not ref $args[0] and $args[0] eq ":file"
!ll&&!rl&&r
3240
MC/DC40%2/5
defined $root->{"dir"} and !(@args && defined $args[0]) || !ref($args[0]) && $args[0] eq ":file"
defined $root->{"dir"} @args defined $args[0] not ref $args[0] $args[0] eq ":file"
Truth table66%4/6
A and not(B && C) or not(D) and E
A= defined $root->{"dir"}B= @argsC= defined $args[0]D= not ref $args[0]E= $args[0] eq ":file"
ABCDEresult
0XXXX0
1110X0
111100
10XXX1
110XX1
111111
58 3557 ▶ shift @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 3557 0 3557
59 3557 unshift @args, $root->_file_for($name);
60 }
61 ▶ elsif (@args && defined $args[0] && !ref $args[0]) {
Condition100%6/6
@args and defined $args[0] and not ref $args[0]
!ll&&!rl&&r
20845326
@args and defined $args[0]
!ll&&!rl&&r
12084429
MC/DC100%3/3
@args and defined $args[0] and not ref $args[0]
@args defined $args[0] not ref $args[0]
Truth table100%4/4
A and B and not(C)
A= @argsB= defined $args[0]C= not ref $args[0]
ABCresult
0XX0
10X0
1100
1111
62 26 push @explicit, $args[0];
63 }
64 # Slot 0 is the backing file; a reference there is refused below.
65 24431 ▶ $plan->{file} = $args[0] if @args && defined $args[0];
Branch: 1 branch
BranchTrueFalseTotal
if @args and defined $args[0] 3586 20845 24431
Condition100%3/3
@args and defined $args[0]
!ll&&!rl&&r
1208443586
MC/DC100%2/2
@args and defined $args[0]
@args defined $args[0]
Truth table100%3/3
A and B
A= @argsB= defined $args[0]
ABresult
0X0
100
111
66 }
67 # construct uses load() or new() for these kinds and would ignore a named ctor.
68 Carp::croak("Data::Shared: a $class spec does not take a ctor;"
69 . ' it is constructed by ' . ($plan->{kind} eq 'handle' ? 'load' : 'new'))
70 24486 ▶ if $resolved->{ctor_named} && $plan->{kind} ne 'leading';
Branch: 2 branches
BranchTrueFalseTotal
if $resolved->{"ctor_named"} and $plan->{"kind"} ne "leading" 2 24484 24486
$plan->{'kind'} eq 'handle' ? : 1 1 2
Condition100%3/3
$resolved->{"ctor_named"} and $plan->{"kind"} ne "leading"
!ll&&!rl&&r
2448222
MC/DC100%2/2
$resolved->{"ctor_named"} and $plan->{"kind"} ne "leading"
$resolved->{"ctor_named"} $plan->{"kind"} ne "leading"
Truth table100%3/3
A and B
A= $resolved->{"ctor_named"}B= $plan->{"kind"} ne "leading"
ABresult
0X0
100
111
71 24484 ▶ $plan->{paths} = [$plan->{file}] if $plan->{kind} ne 'options' && defined $plan->{file};
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"kind"} ne "options" and defined $plan->{"file"} 3604 20880 24484
Condition100%3/3
$plan->{"kind"} ne "options" and defined $plan->{"file"}
!ll&&!rl&&r
35208453604
MC/DC100%2/2
$plan->{"kind"} ne "options" and defined $plan->{"file"}
$plan->{"kind"} ne "options" defined $plan->{"file"}
Truth table100%3/3
A and B
A= $plan->{"kind"} ne "options"B= defined $plan->{"file"}
ABresult
0X0
100
111
72 # SortedSet::Strings may mix one explicit backing path with one derived path.
73 24484 my %explicit = map { $_ => 1 } grep { !ref $_ } @explicit;
74 24484 for my $path (@{ $plan->{paths} }) {
75 3651 ▶ Carp::croak("Data::Shared: invalid backing path for '$name'")
Branch: 1 branch
BranchTrueFalseTotal
if ref $path or not length $path or index($path, "\0") != -1 3 3648 3651
Condition66%4/6
ref $path or not length $path or index($path, "\0") != -1
l!l&&r!l&&!r
303648
ref $path or not length $path
l!l&&r!l&&!r
303648
MC/DC33%1/3
ref $path or not length $path or index($path, "\0") != -1
ref $path not length $path index($path, "\0") != -1
Truth table50%2/4
A or not(B) or C
A= ref $pathB= not length $pathC= index($path, "\0") != -1
ABCresult
1XX1
01X1
0011
0000
76 if ref $path || !length($path) || index($path, "\0") >= 0;
77 # Explicit paths must be absolute; derived paths follow the root's directory spelling.
78 Carp::croak("Data::Shared: backing path for '$name' must be absolute,"
79 . " since every process that opens this store resolves it again"
80 . " (got '$path')")
81 3648 ▶ if $explicit{$path} && $path !~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $explicit{$path} and not $path =~ m[\A/] 3 3645 3648
Condition100%3/3
$explicit{$path} and not $path =~ m[\A/]
!ll&&!rl&&r
3614313
MC/DC100%2/2
$explicit{$path} and not $path =~ m[\A/]
$explicit{$path} not $path =~ m[\A/]
Truth table100%3/3
A and not(B)
A= $explicit{$path}B= not $path =~ m[\A/]
ABresult
0X0
100
111
82 }
83 24478 return $plan;
84 }
85  
86 1735 ▶sub require_files {
Subroutine require_files: called CC=4 SCAR=13.9
Pod undocumented
87 1735 my ($plan) = @_;
88 1735 ▶ Carp::croak("Data::Shared: mount '$plan->{name}' has no backing file to reopen") unless @{ $plan->{paths} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$plan->{"paths"};} 0 1735 1735
89 1735 for my $path (@{ $plan->{paths} }) {
90 1736 ▶ Carp::croak("Data::Shared: missing backing file '$path' for '$plan->{name}'; refusing to recreate storage")
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path 6 1730 1736
91 unless -f $path;
92 }
93 1729 return;
94 }
95  
96 29236 ▶sub _load {
Subroutine _load: called CC=8 SCAR=21.0
97 29236 my ($resolved) = @_;
98 29236 ▶ my $load = $resolved->{load} || $resolved->{class};
Condition33%1/3
$resolved->{'load'} || $resolved->{'class'}
l!l&&r!l&&!r
2923600
MC/DC0%0/2
$resolved->{'load'} || $resolved->{'class'}
$resolved->{'load'} $resolved->{'class'}
Truth table33%1/3
A || B
A= $resolved->{'load'}B= $resolved->{'class'}
ABresult
1X1
011
000
99 29236 ▶ my $minimum = $resolved->{entry} && $resolved->{entry}{min_version};
Condition66%2/3
$resolved->{'entry'} && $resolved->{'entry'}{'min_version'}
!ll&&!rl&&r
35029201
MC/DC50%1/2
$resolved->{'entry'} && $resolved->{'entry'}{'min_version'}
$resolved->{'entry'} $resolved->{'entry'}{'min_version'}
Truth table66%2/3
A && B
A= $resolved->{'entry'}B= $resolved->{'entry'}{'min_version'}
ABresult
0X0
100
111
100 29236 ▶ my $key = $load . "\0" . ($minimum // '');
Condition100%2/2
$minimum // ""
l!l
2920135
MC/DC100%1/1
$minimum // ""
$minimum
Truth table100%2/2
A
A= $minimum
Aresult
11
00
101 29236 ▶ return if $LOADED{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $LOADED{$key} 28952 284 29236
102 # Variant module names do not determine the distribution that provides them.
103 284 ▶ Data::Shared::_require_class($load, $resolved->{entry} && $resolved->{entry}{dist});
Condition66%2/3
$resolved->{'entry'} && $resolved->{'entry'}{'dist'}
!ll&&!rl&&r
80276
MC/DC50%1/2
$resolved->{'entry'} && $resolved->{'entry'}{'dist'}
$resolved->{'entry'} $resolved->{'entry'}{'dist'}
Truth table66%2/3
A && B
A= $resolved->{'entry'}B= $resolved->{'entry'}{'dist'}
ABresult
0X0
100
111
104 # Too old reads as absent: the remedy is the same install, and callers that
105 # tolerate a missing backend must tolerate this too.
106 279 ▶ if ($minimum && !eval { $load->VERSION($minimum); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minimum and not eval { do { $load->VERSION($minimum); 1 } }) 1 278 279
Condition100%3/3
$minimum and not eval { do { $load->VERSION($minimum); 1 } }
!ll&&!rl&&r
32751
MC/DC100%2/2
$minimum and not eval { do { $load->VERSION($minimum); 1 } }
$minimum not eval { do { $load->VERSION($minimum); 1 } }
Truth table100%3/3
A and not(B)
A= $minimumB= not eval { do { $load->VERSION($minimum); 1 } }
ABresult
0X0
100
111
107 1 (my $e = $@) =~ s/ at \S+ line \d+\.?\s*\z//;
108 1 Carp::croak("Data::Shared: backend $load is not available; install the"
109 . " $resolved->{entry}{dist} dist $minimum or newer: $e");
110 }
111 278 $LOADED{$key} = 1;
112 }
113  
114 264 ▶sub readonly_capable {
Subroutine readonly_capable: called CC=4 SCAR=13.9
Pod undocumented
115 264 my ($resolved) = @_;
116 264 _load($resolved);
117 264 ▶ return 1 if $resolved->{entry} && $resolved->{entry}{immutable};
Branch: 1 branch
BranchTrueFalseTotal
if $resolved->{"entry"} and $resolved->{"entry"}{"immutable"} 2 262 264
Condition66%2/3
$resolved->{"entry"} and $resolved->{"entry"}{"immutable"}
!ll&&!rl&&r
02622
MC/DC50%1/2
$resolved->{"entry"} and $resolved->{"entry"}{"immutable"}
$resolved->{"entry"} $resolved->{"entry"}{"immutable"}
Truth table66%2/3
A and B
A= $resolved->{"entry"}B= $resolved->{"entry"}{"immutable"}
ABresult
0X0
100
111
118 262 ▶ return $resolved->{class}->can('new_readonly') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$resolved->{'class'}->can('new_readonly') ? : 257 5 262
119 }
120  
121 47 ▶sub check_readonly {
Subroutine check_readonly: called CC=4 SCAR=14.9
Pod undocumented
122 47 my ($resolved, $name) = @_;
123 47 ▶ return if readonly_capable($resolved);
Branch: 1 branch
BranchTrueFalseTotal
if readonly_capable($resolved) 44 3 47
124 3 ▶ Carp::croak("Data::Shared: strict read-only access is not supported by $resolved->{class}"
Branch: 1 branch
BranchTrueFalseTotal
defined $name && length $name ? : 3 0 3
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
003
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
125 . (defined $name && length $name ? " at mount '$name'" : ''));
126 }
127  
128 19407 ▶sub construct {
Subroutine construct: called CC=24 SCAR=31.9
Pod undocumented
129 19407 my ($root, $plan) = @_;
130 19407 my $resolved = $plan->{resolved};
131 19407 my $class = $resolved->{class};
132 19407 ▶ my $ctor = $resolved->{ctor} || 'new';
Condition50%1/2
$resolved->{'ctor'} || 'new'
l!l
194070
MC/DC0%0/1
$resolved->{'ctor'} || 'new'
$resolved->{'ctor'}
Truth table50%1/2
A
A= $resolved->{'ctor'}
Aresult
11
00
133 19407 ▶ my $opening = $root->{_opening} || $root->{readonly};
Condition66%2/3
$root->{'_opening'} || $root->{'readonly'}
l!l&&r!l&&!r
953018454
MC/DC50%1/2
$root->{'_opening'} || $root->{'readonly'}
$root->{'_opening'} $root->{'readonly'}
Truth table66%2/3
A || B
A= $root->{'_opening'}B= $root->{'readonly'}
ABresult
1X1
011
000
134 19407 ▶ require_files($plan) if $opening;
Branch: 1 branch
BranchTrueFalseTotal
if $opening 953 18454 19407
135 19406 ▶ check_readonly($resolved, $plan->{name}) if $root->{strict_readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"strict_readonly"} 19 19387 19406
136 19406 _load($resolved);
137 19402 my $handle;
138 19402 ▶ if ($plan->{kind} eq 'handle') {
Branch: 3 branches
BranchTrueFalseTotal
if ($plan->{'kind'} eq 'handle') { } 15 19387 19402
elsif ($plan->{'kind'} eq 'options') { } 21 19366 19387
elsif ($root->{'readonly'} and $class->can('new_readonly')) { } 453 18913 19366
139 15 ▶ if (!-e $plan->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $plan->{"file"}) 9 6 15
140 Carp::croak("Data::Shared: perfecthash file '$plan->{file}' does not exist;"
141 . " build it first or mount a loaded handle")
142 9 ▶ unless $plan->{build} && !$opening;
Branch: 1 branch
BranchTrueFalseTotal
unless $plan->{"build"} and not $opening 1 8 9
Condition66%2/3
$plan->{"build"} and not $opening
!ll&&!rl&&r
108
MC/DC50%1/2
$plan->{"build"} and not $opening
$plan->{"build"} not $opening
Truth table66%2/3
A and not(B)
A= $plan->{"build"}B= not $opening
ABresult
0X0
100
111
143 8 my $build = $plan->{build};
144 8 my ($keys) = Data::Shared::Manifest::snapshot($plan->{keys});
145 8 $class->$build($plan->{file}, $keys);
146 }
147 14 $handle = $class->load($plan->{file});
148 } elsif ($plan->{kind} eq 'options') {
149 21 my ($options) = Data::Shared::Manifest::snapshot($plan->{options});
150 21 $handle = $class->new(%$options);
151 ▶ } elsif ($root->{readonly} && $class->can('new_readonly')) {
Condition100%3/3
$root->{"readonly"} and $class->can("new_readonly")
!ll&&!rl&&r
189103453
MC/DC100%2/2
$root->{"readonly"} and $class->can("new_readonly")
$root->{"readonly"} $class->can("new_readonly")
Truth table100%3/3
A and B
A= $root->{"readonly"}B= $class->can("new_readonly")
ABresult
0X0
100
111
152 453 $handle = $class->new_readonly($plan->{file});
153 } else {
154 18913 my ($args) = Data::Shared::Manifest::snapshot($plan->{args});
155 # Frozen files refuse writable constructors, including during a subtree walk.
156 18913 ▶ if (($root->{_cleanup} || $root->{_frozen_ok}) && $class->can('new_readonly')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($root->{'_cleanup'} || $root->{'_frozen_ok'} and $class->can('new_readonly')) { } 343 18570 18913
elsif (not defined $root->{'dir'} and @$args and not defined $args->[0] and $class->can('new_anon')) { } 2057 16513 18570
Condition83%5/6
$root->{"_cleanup"} || $root->{"_frozen_ok"} and $class->can("new_readonly")
!ll&&!rl&&r
185700343
$root->{"_cleanup"} or $root->{"_frozen_ok"}
l!l&&r!l&&!r
633718570
MC/DC66%2/3
$root->{"_cleanup"} || $root->{"_frozen_ok"} and $class->can("new_readonly")
$root->{"_cleanup"} $root->{"_frozen_ok"} $class->can("new_readonly")
Truth table60%3/5
A or B and C
A= $root->{"_cleanup"}B= $root->{"_frozen_ok"}C= $class->can("new_readonly")
ABCresult
00X0
1X00
0100
1X11
0111
157 343 $handle = eval { $class->$ctor(@$args) };
158 343 my $error = $@;
159 343 ▶ if (!$handle) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handle) 17 326 343
160 17 $handle = eval { $class->new_readonly($plan->{file}) };
161 17 ▶ die $error unless $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless $handle 0 17 17
162 }
163 ▶ } elsif (!defined $root->{dir} && @$args && !defined $args->[0]
Condition88%8/9
not defined $root->{"dir"} and @$args and not defined $args->[0] and $class->can("new_anon")
!ll&&!rl&&r
1907146062057
not defined $root->{"dir"} and @$args and not defined $args->[0]
!ll&&!rl&&r
1905216663
not defined $root->{"dir"} and @$args
!ll&&!rl&&r
1905016665
MC/DC75%3/4
not defined $root->{"dir"} and @$args and not defined $args->[0] and $class->can("new_anon")
not defined $root->{"dir"} @$args not defined $args->[0] $class->can("new_anon")
Truth table80%4/5
not(A) and B and not(C) and D
A= not defined $root->{"dir"}B= @$argsC= not defined $args->[0]D= $class->can("new_anon")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
164 && $class->can('new_anon')) {
165 # Buffer's new(undef, ...) fails with EFAULT; new_anon only after the ordinary ctor fails.
166 2057 $handle = eval { $class->$ctor(@$args) };
167 2057 ▶ if (!$handle) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handle) 2057 0 2057
168 2057 my $error = $@;
169 2057 $handle = eval { $class->new_anon(@{$args}[1 .. $#$args]) };
170 2057 ▶ die $error unless $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless $handle 1 2056 2057
171 }
172 } else {
173 16513 $handle = $class->$ctor(@$args);
174 }
175 }
176 19397 ▶ Carp::croak("Data::Shared: constructor for '$plan->{name}' did not return a handle")
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($handle) 0 19397 19397
177 unless Scalar::Util::blessed($handle);
178 19397 return ($handle, $plan->{file}, $plan->{paths});
179 }
180  
181 39 1;
182  
183 __END__
↑ Summary blib/lib/Data/Shared/Manifest.pm »