| 1 | package JSON::RPC2::Client; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = 'v2.1.1'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Scalar::Util qw( weaken refaddr ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | next_id => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | free_id => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | call => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | id => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub batch { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my ($self, @requests) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
batch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my @call = grep {ref} @requests; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | @requests = grep {!ref} @requests; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | croak 'at least one request required' if !@requests; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $request = '['.join(q{,}, @requests).']'; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return ($request, @call); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub notify { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my ($self, $method, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notify: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | croak 'method required' if !defined $method; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return encode_json({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | (!@params ? () : ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | params => \@params, | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | )), | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | sub notify_named { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my ($self, $method, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notify_named: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | croak 'method required' if !defined $method; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | croak 'odd number of elements in %params' if @params % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my %params = @params; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return encode_json({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | (!@params ? () : ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | )), | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sub call { | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | my ($self, $method, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | croak 'method required' if !defined $method; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | my ($id, $call) = $self->_get_id(); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | my $request = encode_json({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | (!@params ? () : ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | params => \@params, | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | )), | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | return wantarray ? ($request, $call) : $request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub call_named { | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my ($self, $method, @params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call_named: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | croak 'method required' if !defined $method; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | croak 'odd number of elements in %params' if @params % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my %params = @params; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my ($id, $call) = $self->_get_id(); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $request = encode_json({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | jsonrpc => '2.0', | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | (!@params ? () : ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | )), | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return wantarray ? ($request, $call) : $request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | sub _get_id { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_id: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | my $id = @{$self->{free_id}} ? pop @{$self->{free_id}} : $self->{next_id}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my $call = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | $self->{call}{ refaddr($call) } = $call; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $self->{id}{ $id } = $call; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | weaken($self->{id}{ $id }); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | return ($id, $call); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | sub pending { | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pending: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return values %{ $self->{call} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub cancel { | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my ($self, $call) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | croak 'no such request' if !delete $self->{call}{ refaddr($call) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub batch_response { | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my ($self, $json) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
batch_response: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | croak 'require 1 param' if @_ != 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | undef $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $response = ref $json ? $json : eval { decode_json($json) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return [ 'Parse error' ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($response && ref $response eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response and ref $response eq "HASH"
MC/DC0%0/2
$response and ref $response eq "HASH"
$response
ref $response eq "HASH"
Truth table0%0/3
A and B
A= $responseB= ref $response eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return [ $self->response($response) ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if (!$response || ref $response ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $response or ref $response ne "ARRAY"
MC/DC0%0/2
not $response or ref $response ne "ARRAY"
not $response
ref $response ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not $responseB= ref $response ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return [ 'expect Array or Object' ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if (!@{$response}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return [ 'empty Array' ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return map {[ $self->response($_) ]} @{$response}; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub response { ## no critic (ProhibitExcessComplexity RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | my ($self, $json) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: called CC=25 SCAR=42.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | croak 'require 1 param' if @_ != 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | undef $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | my $response = ref $json ? $json : eval { decode_json($json) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return 'Parse error'; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6 | ▶ | if (ref $response ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return 'expect Object'; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | if (!defined $response->{jsonrpc} || $response->{jsonrpc} ne '2.0') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $response->{"jsonrpc"} or $response->{"jsonrpc"} ne "2.0"
MC/DC0%0/2
not defined $response->{"jsonrpc"} or $response->{"jsonrpc"} ne "2.0"
not defined $response->{"jsonrpc"}
$response->{"jsonrpc"} ne "2.0"
Truth table33%1/3
not(A) or B
A= not defined $response->{"jsonrpc"}B= $response->{"jsonrpc"} ne "2.0"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return 'expect {jsonrpc}="2.0"'; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | ▶ | if (!exists $response->{id} || ref $response->{id} || !defined $response->{id}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not exists $response->{"id"} or ref $response->{"id"} or not defined $response->{"id"}
not exists $response->{"id"} or ref $response->{"id"}
MC/DC0%0/3
not exists $response->{"id"} or ref $response->{"id"} or not defined $response->{"id"}
not exists $response->{"id"}
ref $response->{"id"}
not defined $response->{"id"}
Truth table25%1/4
not(A) or B or not(C)
A= not exists $response->{"id"}B= ref $response->{"id"}C= not defined $response->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return 'expect {id} is scalar'; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | ▶ | if (!exists $self->{id}{ $response->{id} }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | return 'unknown {id}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | if (!(exists $response->{result} xor exists $response->{error})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
exists $response->{"result"} xor exists $response->{"error"}
MC/DC0%0/2
exists $response->{"result"} xor exists $response->{"error"}
exists $response->{"result"}
exists $response->{"error"}
Truth table50%2/4
A xor B
A= exists $response->{"result"}B= exists $response->{"error"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return 'expect {result} or {error}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | ▶ | if (exists $response->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | my $e = $response->{error}; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | if (ref $e ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return 'expect {error} is Object'; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | ▶ | if (!defined $e->{code} || ref $e->{code} || $e->{code} !~ /\A-?\d+\z/xms) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $e->{"code"} or ref $e->{"code"} or not $e->{"code"} =~ /\A-?\d+\z/msx
not defined $e->{"code"} or ref $e->{"code"}
MC/DC0%0/3
not defined $e->{"code"} or ref $e->{"code"} or not $e->{"code"} =~ /\A-?\d+\z/msx
not defined $e->{"code"}
ref $e->{"code"}
not $e->{"code"} =~ /\A-?\d+\z/msx
Truth table25%1/4
not(A) or B or not(C)
A= not defined $e->{"code"}B= ref $e->{"code"}C= not $e->{"code"} =~ /\A-?\d+\z/msx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return 'expect {error}{code} is Integer'; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | if (!defined $e->{message} || ref $e->{message}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $e->{"message"} or ref $e->{"message"}
MC/DC0%0/2
not defined $e->{"message"} or ref $e->{"message"}
not defined $e->{"message"}
ref $e->{"message"}
Truth table33%1/3
not(A) or B
A= not defined $e->{"message"}B= ref $e->{"message"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return 'expect {error}{message} is String'; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ## no critic (ProhibitMagicNumbers) | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if ((3 == keys %{$e} && !exists $e->{data}) || 3 < keys %{$e}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
3 == keys %{$e;} and not exists $e->{"data"} or 3 < keys %{$e;}
3 == keys %{$e;} and not exists $e->{"data"}
MC/DC0%0/3
3 == keys %{$e;} and not exists $e->{"data"} or 3 < keys %{$e;}
3 == keys %{$e;}
not exists $e->{"data"}
3 < keys %{$e;}
Truth table20%1/5
A and not(B) or C
A= 3 == keys %{$e;}B= not exists $e->{"data"}C= 3 < keys %{$e;}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return 'only optional key must be {error}{data}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | my $id = $response->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | push @{ $self->{free_id} }, $id; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | my $call = delete $self->{id}{ $id }; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | ▶ | if ($call) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | $call = delete $self->{call}{ refaddr($call) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | if (!$call) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return; # call was canceled | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | return (undef, $response->{result}, $response->{error}, $call); | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||