line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Spec::Procedure; |
2
|
8
|
|
|
8
|
|
31173
|
use Moo; |
|
8
|
|
|
|
|
14507
|
|
|
8
|
|
|
|
|
50
|
|
3
|
8
|
|
|
8
|
|
4599
|
use Carp (); |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
137
|
|
4
|
8
|
|
|
8
|
|
35
|
use Try::Tiny; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
651
|
|
5
|
|
|
|
|
|
|
with qw( |
6
|
|
|
|
|
|
|
JSON::RPC::Spec::Common |
7
|
|
|
|
|
|
|
); |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
100
|
8
|
|
36
|
use constant DEBUG => $ENV{PERL_JSON_RPC_SPEC_DEBUG} || 0; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
1032
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has router => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
isa => sub { |
15
|
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
$self->can('match') or Carp::croak('method match required.'); |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
8
|
|
5909
|
use namespace::clean; |
|
8
|
|
|
|
|
83172
|
|
|
8
|
|
|
|
|
79
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse { |
24
|
49
|
|
|
49
|
1
|
1716
|
my ($self, $obj, $extra_args) = @_; |
25
|
49
|
100
|
|
|
|
148
|
if (ref $obj ne 'HASH') { |
26
|
4
|
|
|
|
|
14
|
return $self->_rpc_invalid_request; |
27
|
|
|
|
|
|
|
} |
28
|
45
|
|
|
|
|
160
|
$self->_is_notification(!exists $obj->{id}); |
29
|
45
|
|
|
|
|
129
|
$self->_id($obj->{id}); |
30
|
45
|
|
100
|
|
|
171
|
my $method = $obj->{method} || ''; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# rpc call with invalid Request object: |
33
|
|
|
|
|
|
|
# rpc call with an invalid Batch (but not empty): |
34
|
|
|
|
|
|
|
# rpc call with invalid Batch: |
35
|
45
|
100
|
100
|
|
|
311
|
if ($method eq '' or $method =~ m!\A\.|\A[0-9]+\z!) { |
36
|
9
|
|
|
|
|
34
|
return $self->_rpc_invalid_request; |
37
|
|
|
|
|
|
|
} |
38
|
36
|
|
|
|
|
47
|
my ($result, $err); |
39
|
|
|
|
|
|
|
try { |
40
|
36
|
|
|
36
|
|
944
|
$result = $self->_trigger($method, $obj->{params}, $extra_args); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
catch { |
43
|
13
|
|
|
13
|
|
437
|
$err = $_; |
44
|
13
|
|
|
|
|
40
|
warn qq{-- error : @{[$err]} } if DEBUG; |
|
36
|
|
|
|
|
5152
|
|
45
|
36
|
|
|
|
|
233
|
}; |
46
|
8
|
100
|
|
|
|
23
|
if ($self->_is_notification) { |
47
|
28
|
|
|
|
|
69
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
9
|
100
|
|
|
|
15
|
if ($err) { |
50
|
9
|
|
|
|
|
39
|
my $error; |
51
|
4
|
100
|
|
|
|
20
|
if ($err =~ m!rpc_method_not_found!) { |
|
|
100
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
$error = $self->_rpc_method_not_found; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ($err =~ m!rpc_invalid_params!) { |
55
|
4
|
|
|
|
|
17
|
$error = $self->_rpc_invalid_params; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
9
|
|
|
|
|
306
|
$error = $self->_rpc_internal_error(data => $err); |
59
|
|
|
|
|
|
|
} |
60
|
19
|
|
|
|
|
65
|
return $error; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
return +{ |
63
|
0
|
|
|
|
|
0
|
jsonrpc => $self->_jsonrpc, |
64
|
|
|
|
|
|
|
result => $result, |
65
|
|
|
|
|
|
|
id => $self->_id |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# trigger registered method |
70
|
|
|
|
|
|
|
sub _trigger { |
71
|
37
|
|
|
37
|
|
1609
|
my ($self, $name, $params, $extra_args) = @_; |
72
|
37
|
|
|
|
|
93
|
my $router = $self->router; |
73
|
37
|
|
|
|
|
130
|
my $matched = $router->match($name); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# rpc call of non-existent method: |
76
|
37
|
100
|
|
|
|
2019
|
unless ($matched) { |
77
|
6
|
|
|
|
|
962
|
Carp::croak 'rpc_method_not_found on trigger'; |
78
|
|
|
|
|
|
|
} |
79
|
31
|
|
|
|
|
108
|
my $cb = delete $matched->{$self->_callback_key}; |
80
|
31
|
|
|
|
|
1186
|
return $cb->($params, $matched, @{$extra_args}); |
|
31
|
|
|
|
|
109
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |