blib/lib/Data/Shared/Adapter/Indexed.pm

filter: Statementstmt 94.6% 71 / 75 Branchbran 93.7% 30 / 32 Conditioncond 86.6% 13 / 15 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 4 totaltotal 89.6% 139 / 155 CC 23 SCAR 14.6
CC
23
Cov
93%
_check_indices
8.0
make_bound
6.2
make_verb
6.0
CRAP 4.3
« blib/lib/Data/Shared/Adapter/Keyed.pm ↑ Summary blib/lib/Data/Shared/Adapter/Queue.pm »
1 package Data::Shared::Adapter::Indexed;
2 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use parent 'Data::Shared::Adapter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Data::Shared::Registry ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 our $VERSION = '0.02';
9  
10 40 our @CARP_NOT = qw(Data::Shared);
11  
12 # Fixed for a handle's lifetime, so closures resolve it once at bind time.
13 55 ▶sub _dims {
Subroutine _dims: called CC=4 SCAR=13.9
14 55 my ($entry, $handle) = @_;
15 55 my $dims = $entry->{dims};
16 55 ▶ return $dims if defined $dims;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dims 38 17 55
17 17 ▶ return $handle && $handle->can('ndim') ? $handle->ndim : undef;
Branch: 1 branch
BranchTrueFalseTotal
$handle && $handle->can('ndim') ? : 9 8 17
Condition66%2/3
$handle and $handle->can("ndim")
!ll&&!rl&&r
089
MC/DC50%1/2
$handle and $handle->can("ndim")
$handle $handle->can("ndim")
Truth table66%2/3
A and B
A= $handleB= $handle->can("ndim")
ABresult
0X0
100
111
18 }
19  
20 82 ▶sub _check_indices {
Subroutine _check_indices: called CC=8 SCAR=20.8
21 82 my ($entry, $rest, $verb, $dims) = @_;
22 82 ▶ Carp::croak("Data::Shared: path too short: mount has no index") unless @$rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rest 3 79 82
23 # Excess components would fall through as arguments: '/fenwick/1/99' would set index 1 to 99.
24 79 ▶ Carp::croak("Data::Shared: path too long: $entry->{key} takes "
Branch: 2 branches
BranchTrueFalseTotal
if defined $dims and @$rest > $dims 7 72 79
$dims == 1 ? : 4 3 7
Condition100%3/3
defined $dims and @$rest > $dims
!ll&&!rl&&r
6667
MC/DC100%2/2
defined $dims and @$rest > $dims
defined $dims @$rest > $dims
Truth table100%3/3
A and B
A= defined $dimsB= @$rest > $dims
ABresult
0X0
100
111
25 . ($dims == 1 ? 'one index component' : "$dims index components"))
26 if defined $dims && @$rest > $dims;
27 72 ▶ return unless $entry->{key_int} && $verb ne 'exists';
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"key_int"} and $verb ne "exists" 27 45 72
Condition100%3/3
$entry->{"key_int"} and $verb ne "exists"
!ll&&!rl&&r
62145
MC/DC100%2/2
$entry->{"key_int"} and $verb ne "exists"
$entry->{"key_int"} $verb ne "exists"
Truth table100%3/3
A and B
A= $entry->{"key_int"}B= $verb ne "exists"
ABresult
0X0
100
111
28 45 Data::Shared::Registry::_assert_index($entry->{key}, $_) for @$rest;
29 40 return;
30 }
31  
32 56 ▶sub make_verb {
Subroutine make_verb: called CC=6 SCAR=17.9
Pod undocumented
33 56 my ($class, $verb, $handle, $entry) = @_;
34 56 my $spec = Data::Shared::Adapter::_spec($entry, $verb);
35 56 ▶ return undef unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 7 49 56
36 49 my $dims = _dims($entry, $handle);
37 49 ▶ if (ref $spec eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "CODE") 9 40 49
38 26 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 26 my ($rest, @a) = @_;
40 26 _check_indices($entry, $rest, $verb, $dims);
41 24 return $spec->($handle, @$rest, @a);
42 9 };
43 }
44 40 my $method = $handle->can($spec);
45 40 ▶ if (!$method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 1 39 40
46 1 my $msg = Data::Shared::Adapter::_unsupported($entry, $handle, $spec);
47 1 ▶ return sub { Carp::croak($msg) };
Subroutine __ANON__: called CC=1 SCAR=0.0
48 }
49 39 ▶ if ($verb eq 'set' || $verb eq 'incr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "set" or $verb eq "incr") 26 13 39
Condition100%3/3
$verb eq "set" or $verb eq "incr"
l!l&&r!l&&!r
21513
MC/DC100%2/2
$verb eq "set" or $verb eq "incr"
$verb eq "set" $verb eq "incr"
Truth table100%3/3
A or B
A= $verb eq "set"B= $verb eq "incr"
ABresult
1X1
011
000
50 33 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 33 my ($rest, @a) = @_;
52 33 ▶ Data::Shared::Registry::_assert_delta($entry->{key}, @a) if $verb eq 'incr';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "incr" 6 27 33
53 33 _check_indices($entry, $rest, $verb, $dims);
54 26 return $handle->$method(@$rest, @a);
55 26 };
56 }
57 17 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 17 my ($rest) = @_;
59 17 _check_indices($entry, $rest, $verb, $dims);
60 14 return $handle->$method(@$rest);
61 13 };
62 }
63  
64 7 ▶sub make_bound {
Subroutine make_bound: called CC=6 SCAR=18.2
Pod undocumented
65 7 my ($class, $verb, $handle, $entry, $rest) = @_;
66 7 my $spec = Data::Shared::Adapter::_spec($entry, $verb);
67 7 ▶ return undef unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 1 6 7
68 6 _check_indices($entry, $rest, $verb, _dims($entry, $handle));
69 3 my @idx = @$rest;
70 3 ▶ if (ref $spec eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "CODE") 1 2 3
71 1 ▶ return sub { my @a = @_; return $spec->($handle, @idx, @a) };
Subroutine __ANON__: called CC=1 SCAR=0.0
72 }
73 2 my $method = $handle->can($spec);
74 2 ▶ if (!$method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 0 2 2
75 0 my $msg = Data::Shared::Adapter::_unsupported($entry, $handle, $spec);
76 0 ▶ return sub { Carp::croak($msg) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 }
78 2 ▶ if ($verb eq 'set' || $verb eq 'incr') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "set" or $verb eq "incr") 1 1 2
Condition66%2/3
$verb eq "set" or $verb eq "incr"
l!l&&r!l&&!r
101
MC/DC50%1/2
$verb eq "set" or $verb eq "incr"
$verb eq "set" $verb eq "incr"
Truth table66%2/3
A or B
A= $verb eq "set"B= $verb eq "incr"
ABresult
1X1
011
000
79 1 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
80 1 my @a = @_;
81 1 ▶ Data::Shared::Registry::_assert_delta($entry->{key}, @a) if $verb eq 'incr';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "incr" 0 1 1
82 1 return $handle->$method(@idx, @a);
83 1 };
84 }
85 1 ▶ return sub { return $handle->$method(@idx) };
Subroutine __ANON__: called CC=1 SCAR=0.0
86 }
87  
88 1 ▶sub perform_push { Carp::croak("Data::Shared: push is not supported for indexed mounts (use shared_call)") }
Subroutine perform_push: called CC=1 SCAR=0.0
Pod undocumented
89 0 ▶sub perform_pop { Carp::croak("Data::Shared: pop is not supported for indexed mounts (use shared_call)") }
Subroutine perform_pop: not called CC=1 SCAR=6.9
Pod undocumented
90  
91 40 1;
92  
93 __END__
« blib/lib/Data/Shared/Adapter/Keyed.pm ↑ Summary blib/lib/Data/Shared/Adapter/Queue.pm »