line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Spec::Common; |
2
|
8
|
|
|
8
|
|
78912
|
use Moo::Role; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
52
|
|
3
|
8
|
|
|
8
|
|
2419
|
use Carp (); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
175
|
|
4
|
8
|
|
|
8
|
|
5950
|
use JSON::MaybeXS qw(JSON); |
|
8
|
|
|
|
|
124265
|
|
|
8
|
|
|
|
|
1227
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has coder => ( |
7
|
|
|
|
|
|
|
is => 'lazy', |
8
|
|
|
|
|
|
|
isa => sub { |
9
|
|
|
|
|
|
|
my $self = shift; |
10
|
|
|
|
|
|
|
$self->can('encode') or Carp::croak('method encode required.'); |
11
|
|
|
|
|
|
|
$self->can('decode') or Carp::croak('method decode required.'); |
12
|
|
|
|
|
|
|
}, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has [qw(_callback_key _jsonrpc)] => (is => 'lazy'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has [qw(_id _is_notification)] => (is => 'rw'); |
18
|
|
|
|
|
|
|
|
19
|
8
|
|
|
8
|
|
56
|
use namespace::clean; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
73
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_coder { |
23
|
6
|
|
|
6
|
|
5693
|
JSON->new->utf8; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _build__callback_key { |
27
|
10
|
|
|
10
|
|
3196
|
'_callback'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build__jsonrpc { |
31
|
12
|
|
|
12
|
|
3500
|
'2.0'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _error { |
35
|
29
|
|
|
29
|
|
48
|
my ($self, $error) = @_; |
36
|
|
|
|
|
|
|
return +{ |
37
|
29
|
|
|
|
|
94
|
jsonrpc => $self->_jsonrpc, |
38
|
|
|
|
|
|
|
error => $error, |
39
|
|
|
|
|
|
|
id => $self->_id |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _rpc_invalid_request { |
44
|
17
|
|
|
17
|
|
28
|
my ($self) = @_; |
45
|
17
|
|
|
|
|
49
|
my $error = { |
46
|
|
|
|
|
|
|
code => -32600, |
47
|
|
|
|
|
|
|
message => 'Invalid Request' |
48
|
|
|
|
|
|
|
}; |
49
|
17
|
|
|
|
|
46
|
$self->_is_notification(undef); |
50
|
17
|
|
|
|
|
37
|
$self->_id(undef); |
51
|
17
|
|
|
|
|
40
|
return $self->_error($error); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _rpc_method_not_found { |
55
|
4
|
|
|
4
|
|
7
|
my ($self) = @_; |
56
|
4
|
|
|
|
|
16
|
my $error = { |
57
|
|
|
|
|
|
|
code => -32601, |
58
|
|
|
|
|
|
|
message => 'Method not found' |
59
|
|
|
|
|
|
|
}; |
60
|
4
|
|
|
|
|
15
|
return $self->_error($error); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _rpc_invalid_params { |
64
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
65
|
1
|
|
|
|
|
3
|
my $error = { |
66
|
|
|
|
|
|
|
code => -32602, |
67
|
|
|
|
|
|
|
message => 'Invalid params' |
68
|
|
|
|
|
|
|
}; |
69
|
1
|
|
|
|
|
4
|
return $self->_error($error); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _rpc_internal_error { |
73
|
4
|
|
|
4
|
|
10
|
my ($self, @args) = @_; |
74
|
4
|
|
|
|
|
15
|
my $error = { |
75
|
|
|
|
|
|
|
code => -32603, |
76
|
|
|
|
|
|
|
message => 'Internal error', |
77
|
|
|
|
|
|
|
@args |
78
|
|
|
|
|
|
|
}; |
79
|
4
|
|
|
|
|
12
|
return $self->_error($error); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _rpc_parse_error { |
83
|
3
|
|
|
3
|
|
44
|
my ($self) = @_; |
84
|
3
|
|
|
|
|
14
|
my $error = { |
85
|
|
|
|
|
|
|
code => -32700, |
86
|
|
|
|
|
|
|
message => 'Parse error' |
87
|
|
|
|
|
|
|
}; |
88
|
3
|
|
|
|
|
13
|
$self->_id(undef); |
89
|
3
|
|
|
|
|
8
|
return $self->_error($error); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |