line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Spec::Procedure; |
2
|
8
|
|
|
8
|
|
20634
|
use Moo; |
|
8
|
|
|
|
|
9354
|
|
|
8
|
|
|
|
|
46
|
|
3
|
8
|
|
|
8
|
|
3003
|
use Carp (); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
133
|
|
4
|
8
|
|
|
8
|
|
35
|
use Try::Tiny; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
505
|
|
5
|
|
|
|
|
|
|
with qw( |
6
|
|
|
|
|
|
|
JSON::RPC::Spec::Common |
7
|
|
|
|
|
|
|
); |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
100
|
8
|
|
45
|
use constant DEBUG => $ENV{PERL_JSON_RPC_SPEC_DEBUG} || 0; |
|
8
|
|
|
|
|
37
|
|
|
8
|
|
|
|
|
826
|
|
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
|
|
3018
|
use namespace::clean; |
|
8
|
|
|
|
|
58419
|
|
|
8
|
|
|
|
|
51
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse { |
24
|
49
|
|
|
49
|
1
|
1826
|
my ($self, $obj, $extra_args) = @_; |
25
|
49
|
100
|
|
|
|
155
|
if (ref $obj ne 'HASH') { |
26
|
4
|
|
|
|
|
12
|
return $self->_rpc_invalid_request; |
27
|
|
|
|
|
|
|
} |
28
|
45
|
|
|
|
|
138
|
$self->_is_notification(!exists $obj->{id}); |
29
|
45
|
|
|
|
|
135
|
$self->_id($obj->{id}); |
30
|
45
|
|
100
|
|
|
129
|
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
|
|
|
288
|
if ($method eq '' or $method =~ m!\A\.|\A[0-9]+\z!) { |
36
|
9
|
|
|
|
|
34
|
return $self->_rpc_invalid_request; |
37
|
|
|
|
|
|
|
} |
38
|
36
|
|
|
|
|
67
|
my ($result, $err); |
39
|
|
|
|
|
|
|
try { |
40
|
36
|
|
|
36
|
|
1366
|
$result = $self->_trigger($method, $obj->{params}, $extra_args); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
catch { |
43
|
13
|
|
|
13
|
|
451
|
$err = $_; |
44
|
13
|
|
|
|
|
71
|
warn qq{-- error : @{[$err]} } if DEBUG; |
|
36
|
|
|
|
|
5488
|
|
45
|
36
|
|
|
|
|
210
|
}; |
46
|
8
|
100
|
|
|
|
23
|
if ($self->_is_notification) { |
47
|
28
|
|
|
|
|
79
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
9
|
100
|
|
|
|
16
|
if ($err) { |
50
|
9
|
|
|
|
|
42
|
my $error; |
51
|
4
|
100
|
|
|
|
20
|
if ($err =~ m!rpc_method_not_found!) { |
|
|
100
|
|
|
|
|
|
52
|
1
|
|
|
|
|
6
|
$error = $self->_rpc_method_not_found; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ($err =~ m!rpc_invalid_params!) { |
55
|
4
|
|
|
|
|
16
|
$error = $self->_rpc_invalid_params; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
9
|
|
|
|
|
106
|
$error = $self->_rpc_internal_error(data => $err); |
59
|
|
|
|
|
|
|
} |
60
|
19
|
|
|
|
|
334
|
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
|
|
1710
|
my ($self, $name, $params, $extra_args) = @_; |
72
|
37
|
|
|
|
|
92
|
my $router = $self->router; |
73
|
37
|
|
|
|
|
119
|
my $matched = $router->match($name); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# rpc call of non-existent method: |
76
|
37
|
100
|
|
|
|
2260
|
unless ($matched) { |
77
|
6
|
|
|
|
|
844
|
Carp::croak 'rpc_method_not_found on trigger'; |
78
|
|
|
|
|
|
|
} |
79
|
31
|
|
|
|
|
588
|
my $cb = delete $matched->{$self->_callback_key}; |
80
|
31
|
|
|
|
|
230
|
return $cb->($params, $matched, @{$extra_args}); |
|
31
|
|
|
|
|
102
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |