line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Parser; |
2
|
3
|
|
|
3
|
|
906
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1413
|
|
3
|
3
|
|
|
3
|
|
1669
|
use JSON::RPC::Procedure; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
19
|
use Carp (); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
47
|
|
5
|
3
|
|
|
3
|
|
1804
|
use Plack::Request; |
|
3
|
|
|
|
|
165856
|
|
|
3
|
|
|
|
|
126
|
|
6
|
|
|
|
|
|
|
use Class::Accessor::Lite |
7
|
3
|
|
|
|
|
27
|
new => 1, |
8
|
|
|
|
|
|
|
rw => [ qw( |
9
|
|
|
|
|
|
|
coder |
10
|
|
|
|
|
|
|
) ] |
11
|
3
|
|
|
3
|
|
34
|
; |
|
3
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub construct_procedure { |
14
|
19
|
|
|
19
|
0
|
39
|
my $self = shift; |
15
|
19
|
|
|
|
|
179
|
JSON::RPC::Procedure->new( @_ ); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub construct_from_req { |
19
|
20
|
|
|
20
|
0
|
10279
|
my ($self, $req) = @_; |
20
|
|
|
|
|
|
|
|
21
|
20
|
|
|
|
|
67
|
my $method = $req->method; |
22
|
20
|
|
|
|
|
126
|
my $proc; |
23
|
20
|
100
|
|
|
|
57
|
if ($method eq 'POST') { |
|
|
100
|
|
|
|
|
|
24
|
14
|
|
|
|
|
50
|
$proc = $self->construct_from_post_req( $req ); |
25
|
|
|
|
|
|
|
} elsif ($method eq 'GET') { |
26
|
5
|
|
|
|
|
17
|
$proc = $self->construct_from_get_req( $req ); |
27
|
|
|
|
|
|
|
} else { |
28
|
1
|
|
|
|
|
167
|
Carp::croak( "Invalid method: $method" ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
17
|
|
|
|
|
124
|
return $proc; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub construct_from_post_req { |
35
|
14
|
|
|
14
|
0
|
21
|
my ($self, $req) = @_; |
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
|
|
20
|
my $request = eval { $self->coder->decode( $req->content ) }; |
|
14
|
|
|
|
|
51
|
|
38
|
14
|
100
|
|
|
|
14058
|
if ($@) { |
39
|
1
|
|
|
|
|
108
|
Carp::croak( "JSON parse error: $@" ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
210
|
my $ref = ref $request; |
43
|
13
|
100
|
|
|
|
42
|
if ($ref ne 'ARRAY') { |
44
|
8
|
|
|
|
|
17
|
$request = [ $request ]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
13
|
|
|
|
|
24
|
my @procs; |
48
|
13
|
|
|
|
|
27
|
foreach my $req ( @$request ) { |
49
|
15
|
100
|
|
|
|
240
|
Carp::croak( "Invalid parameter") unless ref $req eq 'HASH'; |
50
|
14
|
|
|
|
|
89
|
push @procs, $self->construct_procedure( |
51
|
|
|
|
|
|
|
method => $req->{method}, |
52
|
|
|
|
|
|
|
id => $req->{id}, |
53
|
|
|
|
|
|
|
params => $req->{params}, |
54
|
|
|
|
|
|
|
jsonrpc => $req->{jsonrpc}, |
55
|
|
|
|
|
|
|
has_id => exists $req->{id}, # when not true it's a notification in JSON-RPC 2.0 |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
12
|
|
|
|
|
189
|
return \@procs; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub construct_from_get_req { |
62
|
5
|
|
|
5
|
0
|
8
|
my ($self, $req) = @_; |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
20
|
my $params = $req->query_parameters; |
65
|
5
|
|
|
|
|
546
|
my $decoded_params; |
66
|
5
|
100
|
|
|
|
31
|
if ($params->{params}) { |
67
|
4
|
|
|
|
|
6
|
$decoded_params = eval { $self->coder->decode( $params->{params} ) }; |
|
4
|
|
|
|
|
15
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
return [ |
70
|
5
|
|
|
|
|
90
|
$self->construct_procedure( |
71
|
|
|
|
|
|
|
method => $params->{method}, |
72
|
|
|
|
|
|
|
id => $params->{id}, |
73
|
|
|
|
|
|
|
params => $decoded_params, |
74
|
|
|
|
|
|
|
jsonrpc => $params->{jsonrpc}, |
75
|
|
|
|
|
|
|
has_id => exists $params->{id}, |
76
|
|
|
|
|
|
|
) |
77
|
|
|
|
|
|
|
]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |