blib/lib/Net/Async/MCP/JSONRPC.pm

filter: Statementstmt 100% 19 / 19 Branchbran 100% 6 / 6 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 95.3% 41 / 43 CC 7 SCAR 12.1
CC
7
Cov
97%
error_failure
5.0
error_text
3.0
BEGIN
1.0
CRAP 3.4
« blib/lib/Net/Async/MCP/Transport/InProcess.pm ↑ Summary
1 package Net::Async::MCP::JSONRPC;
2 # ABSTRACT: How the transports read the error of a JSON-RPC response
3  
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 # The message alone cannot carry a code to switch on or an error->{data} to
11 # read, so the raw error object travels with it as the details of a failure in
12 # category "mcp". The message stays the first element, so a caller reading the
13 # failure in scalar context sees exactly what it saw before. Not every "error"
14 # is a JSON-RPC one: an MCP server answers a bad HTTP method with
15 # {error => 'Method not allowed'}, a gateway may invent its own shape and a
16 # foreign stdio server may write anything, so the shape is checked before it
17 # is read as an object.
18 53 ▶sub error_failure {
Subroutine error_failure: called CC=5 SCAR=16.1
Pod documented
19 53 my ( $self, $response ) = @_;
20  
21 53 ▶ return () unless ref $response eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response eq "HASH" 4 49 53
22  
23 49 my $err = $response->{error};
24 49 ▶ return () unless ref $err eq 'HASH' && defined $err->{code};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err eq "HASH" and defined $err->{"code"} 14 35 49
Condition100%3/3
ref $err eq "HASH" and defined $err->{"code"}
!ll&&!rl&&r
12235
MC/DC100%2/2
ref $err eq "HASH" and defined $err->{"code"}
ref $err eq "HASH" defined $err->{"code"}
Truth table100%3/3
A and B
A= ref $err eq "HASH"B= defined $err->{"code"}
ABresult
0X0
100
111
25  
26 return (
27 35 ▶ 'MCP error '.$err->{code}.': '.($err->{message} // '(no message)'),
Condition100%2/2
$err->{"message"} // "(no message)"
l!l
341
MC/DC100%1/1
$err->{"message"} // "(no message)"
$err->{"message"}
Truth table100%2/2
A
A= $err->{"message"}
Aresult
11
00
28 mcp => $err,
29 );
30 }
31  
32  
33 13 ▶sub error_text {
Subroutine error_text: called CC=3 SCAR=11.0
Pod documented
34 13 my ( $self, $err ) = @_;
35  
36 13 ▶ return $err unless ref $err;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $err 9 4 13
37 4 ▶ return eval {
Condition50%1/2
eval { do { "JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err) } } // "unknown error"
l!l
40
MC/DC0%0/1
eval { do { "JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err) } } // "unknown error"
eval { do { "JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err) } }
Truth table50%1/2
A
A= eval { do { "JSON::MaybeXS"->new("utf8", 1, "canonical", 1, "convert_blessed", 1)->encode($err) } }
Aresult
11
00
38 4 JSON::MaybeXS->new(utf8 => 1, canonical => 1, convert_blessed => 1)->encode($err)
39 } // 'unknown error';
40 }
41  
42  
43 11 1;
44  
45 __END__
« blib/lib/Net/Async/MCP/Transport/InProcess.pm ↑ Summary