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

filter: Statementstmt 96.6% 87 / 90 Branchbran 90.9% 40 / 44 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 95.8% 23 / 24 Podpod 0.0% 0 / 8 totaltotal 86.9% 153 / 176 CC 25 SCAR 12.1
CC
25
Cov
93%
make_bound
6.6
_unsupported_verb
6.1
_make_pushpop
5.0
CRAP 3.3
« blib/lib/Data/Shared/Adapter/Indexed.pm ↑ Summary blib/lib/Data/Shared/Node.pm »
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
BranchTrueFalseTotal
$max ? : 1 9 10
$what eq 'push' ? : 6 4 10
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
BranchTrueFalseTotal
unless defined $spec 4 6 10
26 6 ▶ if (ref $spec eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "CODE") 3 3 6
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
BranchTrueFalseTotal
if @$rest > 1 1 4 5
28 3 return $spec->($handle, @$rest, @a) };
29 }
30 3 my $method = $handle->can($spec);
31 3 ▶ if (!$method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 1 2 3
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
BranchTrueFalseTotal
if @$rest > 1 0 2 2
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
BranchTrueFalseTotal
unless defined $spec 1 2 3
43 2 ▶ _too_long($entry, $verb, 1) if $rest && @$rest > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $rest and @$rest > 1 0 2 2
Condition33%1/3
$rest and @$rest > 1
!ll&&!rl&&r
020
MC/DC0%0/2
$rest and @$rest > 1
$rest @$rest > 1
Truth table33%1/3
A and B
A= $restB= @$rest > 1
ABresult
0X0
100
111
44 2 my @idx = @$rest;
45 2 ▶ if (ref $spec eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "CODE") 1 1 2
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
BranchTrueFalseTotal
unless ($method) 0 1 1
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
BranchTrueFalseTotal
if $entry->{"push"} 1 1 2
70 2 ▶ push @routes, 'shared_pop' if $entry->{pop};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"pop"} 1 1 2
71 2 ▶ push @routes, 'shared_get' if $entry->{verbs} && $entry->{verbs}{get};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"verbs"} and $entry->{"verbs"}{"get"} 0 2 2
Condition66%2/3
$entry->{"verbs"} and $entry->{"verbs"}{"get"}
!ll&&!rl&&r
110
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"}
ABresult
0X0
100
111
72 2 ▶ return "Data::Shared: operation '$verb' is not supported for queue mount '$entry->{key}';"
Branch: 1 branch
BranchTrueFalseTotal
@routes ? : 1 1 2
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
BranchTrueFalseTotal
unless $name 6 65 71
80 65 my $method = $handle->can($name);
81 65 ▶ if (!$method) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method) 2 63 65
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
BranchTrueFalseTotal
if (defined $rest) 8 55 63
86 8 ▶ _too_long($entry, $field, 0) if @$rest;
Branch: 1 branch
BranchTrueFalseTotal
if @$rest 1 7 8
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
BranchTrueFalseTotal
if @$r 8 57 65
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
BranchTrueFalseTotal
unless $code 1 1 2
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
BranchTrueFalseTotal
unless $code 2 1 3
108 1 return $code->($rest, @args);
109 }
110  
111 40 1;
112  
113 __END__
« blib/lib/Data/Shared/Adapter/Indexed.pm ↑ Summary blib/lib/Data/Shared/Node.pm »