| 1 | package Data::Shared::Adapter::Queue; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 7 | 40 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 40 | our @CARP_NOT = qw(Data::Shared); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Extra components are refused, not forwarded: a heap would read one as a priority. | ||||||||||||||||||||||||||||
| 12 | # The length test stays inline at each call site so a push pays no sub call. | ||||||||||||||||||||||||||||
| 13 | 10 | ▶ | sub _too_long { | ||||||||||||||||||||||||||
|
Subroutine
_too_long: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 14 | 10 | my ($entry, $what, $max) = @_; | |||||||||||||||||||||||||||
| 15 | 10 | ▶ | Carp::croak("Data::Shared: path too long: $entry->{key} takes " | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 16 | . ($max ? 'one path component' : "no path component for $what") | ||||||||||||||||||||||||||||
| 17 | . ($what eq 'push' | ||||||||||||||||||||||||||||
| 18 | ? "; pass the value as an argument (through a node cursor: \$node->push('', \$value))" | ||||||||||||||||||||||||||||
| 19 | : '')); | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | sub make_verb { | ||||||||||||||||||||||||||
|
Subroutine
make_verb: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 10 | my ($class, $verb, $handle, $entry) = @_; | |||||||||||||||||||||||||||
| 24 | 10 | my $spec = Data::Shared::Adapter::_spec($entry, $verb); | |||||||||||||||||||||||||||
| 25 | 10 | ▶ | return undef unless defined $spec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | if (ref $spec eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | return sub { my ($rest, @a) = @_; _too_long($entry, $verb, 1) if @$rest > 1; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 3 | return $spec->($handle, @$rest, @a) }; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 3 | my $method = $handle->can($spec); | |||||||||||||||||||||||||||
| 31 | 3 | ▶ | if (!$method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | my $msg = Data::Shared::Adapter::_unsupported($entry, $handle, $spec); | |||||||||||||||||||||||||||
| 33 | 1 | ▶ | return sub { Carp::croak($msg) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 2 | ▶ | return sub { my ($rest, @a) = @_; _too_long($entry, $verb, 1) if @$rest > 1; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 2 | return $handle->$method(@$rest, @a) }; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | sub make_bound { | ||||||||||||||||||||||||||
|
Subroutine
make_bound: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 3 | my ($class, $verb, $handle, $entry, $rest) = @_; | |||||||||||||||||||||||||||
| 41 | 3 | my $spec = Data::Shared::Adapter::_spec($entry, $verb); | |||||||||||||||||||||||||||
| 42 | 3 | ▶ | return undef unless defined $spec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | _too_long($entry, $verb, 1) if $rest && @$rest > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rest and @$rest > 1
MC/DC0%0/2
$rest and @$rest > 1
$rest
@$rest > 1
Truth table33%1/3
A and B
A= $restB= @$rest > 1
| |||||||||||||||||||||||||||||
| 44 | 2 | my @idx = @$rest; | |||||||||||||||||||||||||||
| 45 | 2 | ▶ | if (ref $spec eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | return sub { my @a = @_; return $spec->($handle, @idx, @a) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 1 | my $method = $handle->can($spec); | |||||||||||||||||||||||||||
| 49 | 1 | ▶ | if (!$method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | my $msg = Data::Shared::Adapter::_unsupported($entry, $handle, $spec); | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | return sub { Carp::croak($msg) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | return sub { my @a = @_; return $handle->$method(@idx, @a) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | sub make_bound_push { | ||||||||||||||||||||||||||
|
Subroutine
make_bound_push: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 4 | my ($class, $handle, $entry, $rest) = @_; | |||||||||||||||||||||||||||
| 58 | 4 | return _make_pushpop($entry, $handle, 'push', $rest); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub make_bound_pop { | ||||||||||||||||||||||||||
|
Subroutine
make_bound_pop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 4 | my ($class, $handle, $entry, $rest) = @_; | |||||||||||||||||||||||||||
| 63 | 4 | return _make_pushpop($entry, $handle, 'pop', $rest); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub _unsupported_verb { | ||||||||||||||||||||||||||
|
Subroutine
_unsupported_verb: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 67 | 2 | my ($class, $verb, $entry) = @_; | |||||||||||||||||||||||||||
| 68 | 2 | my @routes; | |||||||||||||||||||||||||||
| 69 | 2 | ▶ | push @routes, 'shared_push' if $entry->{push}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | push @routes, 'shared_pop' if $entry->{pop}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 2 | ▶ | push @routes, 'shared_get' if $entry->{verbs} && $entry->{verbs}{get}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$entry->{"verbs"} and $entry->{"verbs"}{"get"}
MC/DC0%0/2
$entry->{"verbs"} and $entry->{"verbs"}{"get"}
$entry->{"verbs"}
$entry->{"verbs"}{"get"}
Truth table66%2/3
A and B
A= $entry->{"verbs"}B= $entry->{"verbs"}{"get"}
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | return "Data::Shared: operation '$verb' is not supported for queue mount '$entry->{key}';" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | . ' use ' . join(', ', @routes) . (@routes ? ' or ' : '') . 'shared_call'; | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 71 | ▶ | sub _make_pushpop { | ||||||||||||||||||||||||||
|
Subroutine
_make_pushpop: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 77 | 71 | my ($entry, $handle, $field, $rest) = @_; | |||||||||||||||||||||||||||
| 78 | 71 | my $name = $entry->{$field}; | |||||||||||||||||||||||||||
| 79 | 71 | ▶ | return undef unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 65 | my $method = $handle->can($name); | |||||||||||||||||||||||||||
| 81 | 65 | ▶ | if (!$method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 2 | my $msg = Data::Shared::Adapter::_unsupported($entry, $handle, $name); | |||||||||||||||||||||||||||
| 83 | 2 | ▶ | return sub { Carp::croak($msg) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 63 | ▶ | if (defined $rest) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 8 | ▶ | _too_long($entry, $field, 0) if @$rest; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | # Copy @_: forwarding it would pass the caller's own SVs to the backend. | ||||||||||||||||||||||||||||
| 88 | 7 | ▶ | return sub { my @a = @_; return $handle->$method(@a) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 65 | ▶ | return sub { my ($r, @a) = @_; _too_long($entry, $field, 0) if @$r; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 55 | return $handle->$method(@a) }; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 39 | ▶ | sub make_push { my ($class, $handle, $entry) = @_; return _make_pushpop($entry, $handle, 'push') } | ||||||||||||||||||||||||||
|
Subroutine
make_push: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 24 | ▶ | sub make_pop { my ($class, $handle, $entry) = @_; return _make_pushpop($entry, $handle, 'pop') } | ||||||||||||||||||||||||||
|
Subroutine
make_pop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub perform_push { | ||||||||||||||||||||||||||
|
Subroutine
perform_push: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 2 | my ($class, $handle, $entry, $rest, @args) = @_; | |||||||||||||||||||||||||||
| 99 | 2 | my $code = $class->make_push($handle, $entry); | |||||||||||||||||||||||||||
| 100 | 2 | ▶ | Carp::croak("Data::Shared: push is not supported for $entry->{key} (use shared_call)") unless $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | return $code->($rest, @args); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | sub perform_pop { | ||||||||||||||||||||||||||
|
Subroutine
perform_pop: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 3 | my ($class, $handle, $entry, $rest, @args) = @_; | |||||||||||||||||||||||||||
| 106 | 3 | my $code = $class->make_pop($handle, $entry); | |||||||||||||||||||||||||||
| 107 | 3 | ▶ | Carp::croak("Data::Shared: pop is not supported for $entry->{key} (use shared_call)") unless $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 1 | return $code->($rest, @args); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 40 | 1; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||