| 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
| |||||||||||||||||||||||||||||||||
| 17 | 17 | ▶ | return $handle && $handle->can('ndim') ? $handle->ndim : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$handle and $handle->can("ndim")
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")
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $dims and @$rest > $dims
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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$entry->{"key_int"} and $verb ne "exists"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 36 | 49 | my $dims = _dims($entry, $handle); | |||||||||||||||||||||||||||||||
| 37 | 49 | ▶ | if (ref $spec eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$verb eq "set" or $verb eq "incr"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$verb eq "set" or $verb eq "incr"
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"
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||