blib/lib/JSON/RPC/Spec/Common.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 100% 60 / 60 CC 3 SCAR 3.2
CC
3
Cov
100%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« blib/lib/JSON/RPC/Spec/Client.pm ↑ Summary Build »
1 package JSON::RPC::Spec::Common;
2 8 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use JSON::MaybeXS qw(JSON);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 has coder => (
7 is => 'lazy',
8 isa => sub {
9 12 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
10 12 ▶ $self->can('encode') or Carp::croak('method encode required.');
Branch: 1 branch
BranchTrueFalseTotal
$self->can("encode") or Carp::croak("method encode required.") 1 10 11
11 10 ▶ $self->can('decode') or Carp::croak('method decode required.');
Branch: 1 branch
BranchTrueFalseTotal
$self->can("decode") or Carp::croak("method decode required.") 1 9 10
12 },
13 8 );
14  
15 8 has [qw(_callback_key _jsonrpc)] => (is => 'lazy');
16  
17 8 has [qw(_id _is_notification)] => (is => 'rw');
18  
19 8 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub _build_coder {
23 6 ▶ JSON->new->utf8;
Subroutine _build_coder: called CC=1 SCAR=0.0
24 }
25  
26 sub _build__callback_key {
27 10 ▶ '_callback';
Subroutine _build__callback_key: called CC=1 SCAR=0.0
28 }
29  
30 sub _build__jsonrpc {
31 12 ▶ '2.0';
Subroutine _build__jsonrpc: called CC=1 SCAR=0.0
32 }
33  
34 sub _error {
35 29 ▶ my ($self, $error) = @_;
Subroutine _error: called CC=1 SCAR=0.0
36 return +{
37 29 jsonrpc => $self->_jsonrpc,
38 error => $error,
39 id => $self->_id
40 };
41 }
42  
43 sub _rpc_invalid_request {
44 17 ▶ my ($self) = @_;
Subroutine _rpc_invalid_request: called CC=1 SCAR=0.0
45 17 my $error = {
46 code => -32600,
47 message => 'Invalid Request'
48 };
49 17 $self->_is_notification(undef);
50 17 $self->_id(undef);
51 17 return $self->_error($error);
52 }
53  
54 sub _rpc_method_not_found {
55 4 ▶ my ($self) = @_;
Subroutine _rpc_method_not_found: called CC=1 SCAR=0.0
56 4 my $error = {
57 code => -32601,
58 message => 'Method not found'
59 };
60 4 return $self->_error($error);
61 }
62  
63 sub _rpc_invalid_params {
64 1 ▶ my ($self) = @_;
Subroutine _rpc_invalid_params: called CC=1 SCAR=0.0
65 1 my $error = {
66 code => -32602,
67 message => 'Invalid params'
68 };
69 1 return $self->_error($error);
70 }
71  
72 sub _rpc_internal_error {
73 4 ▶ my ($self, @args) = @_;
Subroutine _rpc_internal_error: called CC=1 SCAR=0.0
74 4 my $error = {
75 code => -32603,
76 message => 'Internal error',
77 @args
78 };
79 4 return $self->_error($error);
80 }
81  
82 sub _rpc_parse_error {
83 3 ▶ my ($self) = @_;
Subroutine _rpc_parse_error: called CC=1 SCAR=0.0
84 3 my $error = {
85 code => -32700,
86 message => 'Parse error'
87 };
88 3 $self->_id(undef);
89 3 return $self->_error($error);
90 }
91  
92 8 1;
93 __END__
« blib/lib/JSON/RPC/Spec/Client.pm ↑ Summary Build »