| 1 | package Data::Shared::Adapter::Keyed; | ||||||||||||||||||||||||||||||||||
| 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 | 23754 | ▶ | sub _noun { 'key' } | ||||||||||||||||||||||||||||||||
|
Subroutine
_noun: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 80731 | ▶ | sub _key { | ||||||||||||||||||||||||||||||||
|
Subroutine
_key: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 15 | 80731 | my ($entry, $rest, $verb, $noun) = @_; | |||||||||||||||||||||||||||||||||
| 16 | 80731 | ▶ | Carp::croak("Data::Shared: path too short: mount has no $noun") unless @$rest; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 17 | 80627 | ▶ | return join('/', @$rest) if $entry->{key_join}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 18 | 80611 | ▶ | Carp::croak("Data::Shared: path too long: $entry->{key} takes one $noun component") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 19 | if @$rest > 1; | ||||||||||||||||||||||||||||||||||
| 20 | # A non-integer key would numify to element 0; exists answers 0 instead (see _absent). | ||||||||||||||||||||||||||||||||||
| 21 | Data::Shared::Registry::_assert_index($entry->{key}, $rest->[0]) | ||||||||||||||||||||||||||||||||||
| 22 | 80539 | ▶ | if $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"
| |||||||||||||||||||||||||||||||||||
| 23 | 80234 | return $rest->[0]; | |||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | # key_int_from: the key type comes from the built file, asked once per binding. | ||||||||||||||||||||||||||||||||||
| 27 | 52074 | ▶ | sub _entry_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
_entry_for: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 28 | 52074 | my ($entry, $handle) = @_; | |||||||||||||||||||||||||||||||||
| 29 | 52074 | ▶ | my $ask = $entry->{key_int_from} or return $entry; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 30 | 25 | ▶ | return { %$entry, key_int => $ask->($handle) ? 1 : 0 }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | # exists on an integer mount: a non-integer key would numify to 0 and probe that. | ||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub _absent { | ||||||||||||||||||||||||||||||||
|
Subroutine
_absent: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | my ($entry, $verb, $key) = @_; | |||||||||||||||||||||||||||||||||
| 36 | return $verb eq 'exists' && $entry->{key_int} | ||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | && !Data::Shared::Registry::_index_shape_ok($key); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$verb eq 'exists' && $entry->{'key_int'} && !Data::Shared::Registry::_index_shape_ok($key)
$verb eq "exists" and $entry->{"key_int"}
MC/DC0%0/3
$verb eq 'exists' && $entry->{'key_int'} && !Data::Shared::Registry::_index_shape_ok($key)
$verb eq "exists"
$entry->{"key_int"}
!Data::Shared::Registry::_index_shape_ok($key)
Truth table0%0/4
A and B && not(C)
A= $verb eq "exists"B= $entry->{"key_int"}C= !Data::Shared::Registry::_index_shape_ok($key)
| |||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | # {code, by, absent} or {missing}: code->($handle, $key, @args), by is incr_by for a delta. | ||||||||||||||||||||||||||||||||||
| 41 | # The closures and fast_verb both build on this, so they cannot disagree. | ||||||||||||||||||||||||||||||||||
| 42 | 52063 | ▶ | sub _native { | ||||||||||||||||||||||||||||||||
|
Subroutine
_native: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 43 | 52063 | my ($verb, $handle, $entry) = @_; | |||||||||||||||||||||||||||||||||
| 44 | 52063 | my $spec = Data::Shared::Adapter::_spec($entry, $verb); | |||||||||||||||||||||||||||||||||
| 45 | 52063 | ▶ | return undef unless defined $spec; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | 51925 | ▶ | return { code => $spec } if ref $spec eq 'CODE'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 51410 | ▶ | my $method = $handle->can($spec) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 48 | or return { missing => Data::Shared::Adapter::_unsupported($entry, $handle, $spec) }; | ||||||||||||||||||||||||||||||||||
| 49 | return { code => $method, by => $verb eq 'incr' ? $handle->can('incr_by') : undef, | ||||||||||||||||||||||||||||||||||
| 50 | 51190 | ▶ | absent => $verb eq 'exists' && $entry->{key_int} }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$verb eq 'exists' && $entry->{'key_int'}
MC/DC100%2/2
$verb eq 'exists' && $entry->{'key_int'}
$verb eq 'exists'
$entry->{'key_int'}
Truth table100%3/3
A && B
A= $verb eq 'exists'B= $entry->{'key_int'}
| |||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 25731 | ▶ | sub make_verb { | ||||||||||||||||||||||||||||||||
|
Subroutine
make_verb: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 54 | 25731 | my ($class, $verb, $handle, $entry) = @_; | |||||||||||||||||||||||||||||||||
| 55 | 25731 | $entry = _entry_for($entry, $handle); | |||||||||||||||||||||||||||||||||
| 56 | 25731 | ▶ | my $n = _native($verb, $handle, $entry) or return undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | 25651 | my $missing = $n->{missing}; | |||||||||||||||||||||||||||||||||
| 58 | 25651 | ▶ | return sub { Carp::croak($missing) } if $missing; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | 25564 | my ($code, $by, $absent) = @$n{qw(code by absent)}; | |||||||||||||||||||||||||||||||||
| 60 | 25564 | my $noun = $class->_noun; | |||||||||||||||||||||||||||||||||
| 61 | 80295 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 62 | 80295 | my ($rest, @a) = @_; | |||||||||||||||||||||||||||||||||
| 63 | 80295 | ▶ | Data::Shared::Registry::_assert_delta($entry->{key}, @a) if $verb eq 'incr'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 80285 | my $key = _key($entry, $rest, $verb, $noun); | |||||||||||||||||||||||||||||||||
| 65 | 79924 | ▶ | return 0 if $absent && !Data::Shared::Registry::_index_shape_ok($key); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$absent and not Data::Shared::Registry::_index_shape_ok($key)
MC/DC100%2/2
$absent and not Data::Shared::Registry::_index_shape_ok($key)
$absent
not Data::Shared::Registry::_index_shape_ok($key)
Truth table100%3/3
A and not(B)
A= $absentB= not Data::Shared::Registry::_index_shape_ok($key)
| |||||||||||||||||||||||||||||||||||
| 66 | 79887 | ▶ | return $by->($handle, $key, $a[0]) if @a && $by; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@a and $by
MC/DC100%2/2
@a and $by
@a
$by
Truth table100%3/3
A and B
A= @aB= $by
| |||||||||||||||||||||||||||||||||||
| 67 | 79832 | return $code->($handle, $key, @a); | |||||||||||||||||||||||||||||||||
| 68 | 25564 | }; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 466 | ▶ | sub make_bound { | ||||||||||||||||||||||||||||||||
|
Subroutine
make_bound: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 72 | 466 | my ($class, $verb, $handle, $entry, $rest) = @_; | |||||||||||||||||||||||||||||||||
| 73 | 466 | $entry = _entry_for($entry, $handle); | |||||||||||||||||||||||||||||||||
| 74 | 466 | ▶ | my $n = _native($verb, $handle, $entry) or return undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 446 | my $key = _key($entry, $rest, $verb, $class->_noun); | |||||||||||||||||||||||||||||||||
| 76 | 326 | my $missing = $n->{missing}; | |||||||||||||||||||||||||||||||||
| 77 | 326 | ▶ | return sub { Carp::croak($missing) } if $missing; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 301 | ▶ | return sub { 0 } if $n->{absent} && !Data::Shared::Registry::_index_shape_ok($key); | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
$n->{"absent"} and not Data::Shared::Registry::_index_shape_ok($key)
MC/DC100%2/2
$n->{"absent"} and not Data::Shared::Registry::_index_shape_ok($key)
$n->{"absent"}
not Data::Shared::Registry::_index_shape_ok($key)
Truth table100%3/3
A and not(B)
A= $n->{"absent"}B= not Data::Shared::Registry::_index_shape_ok($key)
| |||||||||||||||||||||||||||||||||||
| 79 | 292 | my ($code, $by) = @$n{qw(code by)}; | |||||||||||||||||||||||||||||||||
| 80 | 429 | ▶ | return sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 81 | 429 | my @a = @_; | |||||||||||||||||||||||||||||||||
| 82 | 429 | ▶ | Data::Shared::Registry::_assert_delta($entry->{key}, @a) if $verb eq 'incr'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | 414 | ▶ | return $by->($handle, $key, $a[0]) if @a && $by; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@a and $by
MC/DC100%2/2
@a and $by
@a
$by
Truth table100%3/3
A and B
A= @aB= $by
| |||||||||||||||||||||||||||||||||||
| 84 | 381 | return $code->($handle, $key, @a); | |||||||||||||||||||||||||||||||||
| 85 | 292 | }; | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | # The flags Shared.xs reads from a fast_verb descriptor. | ||||||||||||||||||||||||||||||||||
| 89 | 40 | ▶ | use constant { FAST_KEY_INT => 1, FAST_ABSENT => 2, FAST_INCR => 4 }; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | # [handle, code, by, flags] for the XS dispatch, or undef where only the closure is exact. | ||||||||||||||||||||||||||||||||||
| 92 | 25877 | ▶ | sub fast_verb { | ||||||||||||||||||||||||||||||||
|
Subroutine
fast_verb: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 93 | 25877 | my ($class, $verb, $handle, $entry) = @_; | |||||||||||||||||||||||||||||||||
| 94 | 25877 | $entry = _entry_for($entry, $handle); | |||||||||||||||||||||||||||||||||
| 95 | 25877 | ▶ | return undef if $entry->{key_join}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | 25866 | ▶ | my $n = _native($verb, $handle, $entry) or return undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 97 | 25828 | ▶ | return undef if $n->{missing}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | return [$handle, $n->{code}, $n->{by}, | ||||||||||||||||||||||||||||||||||
| 99 | 25720 | ▶ | ($entry->{key_int} ? FAST_KEY_INT : 0) | ($n->{absent} ? FAST_ABSENT : 0) | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 100 | | ($verb eq 'incr' ? FAST_INCR : 0)]; | ||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 40 | 1; | |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||||||||