line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Spec::Common; |
2
|
8
|
|
|
8
|
|
50791
|
use Moo::Role; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
37
|
|
3
|
8
|
|
|
8
|
|
1633
|
use Carp (); |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
128
|
|
4
|
8
|
|
|
8
|
|
3092
|
use JSON::MaybeXS qw(JSON); |
|
8
|
|
|
|
|
42784
|
|
|
8
|
|
|
|
|
811
|
|
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
|
|
41
|
use namespace::clean; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
50
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_coder { |
23
|
6
|
|
|
6
|
|
4271
|
JSON->new->utf8; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _build__callback_key { |
27
|
10
|
|
|
10
|
|
2059
|
'_callback'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build__jsonrpc { |
31
|
12
|
|
|
12
|
|
2578
|
'2.0'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _error { |
35
|
29
|
|
|
29
|
|
30
|
my ($self, $error) = @_; |
36
|
|
|
|
|
|
|
return +{ |
37
|
29
|
|
|
|
|
51
|
jsonrpc => $self->_jsonrpc, |
38
|
|
|
|
|
|
|
error => $error, |
39
|
|
|
|
|
|
|
id => $self->_id |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _rpc_invalid_request { |
44
|
17
|
|
|
17
|
|
16
|
my ($self) = @_; |
45
|
17
|
|
|
|
|
36
|
my $error = { |
46
|
|
|
|
|
|
|
code => -32600, |
47
|
|
|
|
|
|
|
message => 'Invalid Request' |
48
|
|
|
|
|
|
|
}; |
49
|
17
|
|
|
|
|
24
|
$self->_is_notification(undef); |
50
|
17
|
|
|
|
|
22
|
$self->_id(undef); |
51
|
17
|
|
|
|
|
20
|
return $self->_error($error); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _rpc_method_not_found { |
55
|
4
|
|
|
4
|
|
6
|
my ($self) = @_; |
56
|
4
|
|
|
|
|
11
|
my $error = { |
57
|
|
|
|
|
|
|
code => -32601, |
58
|
|
|
|
|
|
|
message => 'Method not found' |
59
|
|
|
|
|
|
|
}; |
60
|
4
|
|
|
|
|
10
|
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
|
|
|
|
|
3
|
return $self->_error($error); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _rpc_internal_error { |
73
|
4
|
|
|
4
|
|
9
|
my ($self, @args) = @_; |
74
|
4
|
|
|
|
|
11
|
my $error = { |
75
|
|
|
|
|
|
|
code => -32603, |
76
|
|
|
|
|
|
|
message => 'Internal error', |
77
|
|
|
|
|
|
|
@args |
78
|
|
|
|
|
|
|
}; |
79
|
4
|
|
|
|
|
9
|
return $self->_error($error); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _rpc_parse_error { |
83
|
3
|
|
|
3
|
|
5
|
my ($self) = @_; |
84
|
3
|
|
|
|
|
6
|
my $error = { |
85
|
|
|
|
|
|
|
code => -32700, |
86
|
|
|
|
|
|
|
message => 'Parse error' |
87
|
|
|
|
|
|
|
}; |
88
|
3
|
|
|
|
|
7
|
$self->_id(undef); |
89
|
3
|
|
|
|
|
5
|
return $self->_error($error); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |