line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Parser; |
2
|
3
|
|
|
3
|
|
383
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
69
|
|
3
|
3
|
|
|
3
|
|
854
|
use JSON::RPC::Procedure; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
57
|
|
4
|
3
|
|
|
3
|
|
14
|
use Carp (); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
35
|
|
5
|
3
|
|
|
3
|
|
1232
|
use Plack::Request; |
|
3
|
|
|
|
|
96860
|
|
|
3
|
|
|
|
|
98
|
|
6
|
|
|
|
|
|
|
use Class::Accessor::Lite |
7
|
3
|
|
|
|
|
19
|
new => 1, |
8
|
|
|
|
|
|
|
rw => [ qw( |
9
|
|
|
|
|
|
|
coder |
10
|
|
|
|
|
|
|
) ] |
11
|
3
|
|
|
3
|
|
16
|
; |
|
3
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub construct_procedure { |
14
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
15
|
1
|
|
|
|
|
3
|
JSON::RPC::Procedure->new( @_ ); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub construct_from_req { |
19
|
1
|
|
|
1
|
0
|
951
|
my ($self, $req) = @_; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
3
|
my $method = $req->method; |
22
|
1
|
|
|
|
|
9
|
my $proc; |
23
|
1
|
50
|
|
|
|
4
|
if ($method eq 'POST') { |
|
|
50
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
$proc = $self->construct_from_post_req( $req ); |
25
|
|
|
|
|
|
|
} elsif ($method eq 'GET') { |
26
|
1
|
|
|
|
|
2
|
$proc = $self->construct_from_get_req( $req ); |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
0
|
Carp::croak( "Invalid method: $method" ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
6
|
return $proc; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub construct_from_post_req { |
35
|
0
|
|
|
0
|
0
|
0
|
my ($self, $req) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my $request = eval { $self->coder->decode( $req->content ) }; |
|
0
|
|
|
|
|
0
|
|
38
|
0
|
0
|
|
|
|
0
|
if ($@) { |
39
|
0
|
|
|
|
|
0
|
Carp::croak( "JSON parse error: $@" ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $ref = ref $request; |
43
|
0
|
0
|
|
|
|
0
|
if ($ref ne 'ARRAY') { |
44
|
0
|
|
|
|
|
0
|
$request = [ $request ]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
my @procs; |
48
|
0
|
|
|
|
|
0
|
foreach my $req ( @$request ) { |
49
|
0
|
0
|
|
|
|
0
|
Carp::croak( "Invalid parameter") unless ref $req eq 'HASH'; |
50
|
|
|
|
|
|
|
push @procs, $self->construct_procedure( |
51
|
|
|
|
|
|
|
method => $req->{method}, |
52
|
|
|
|
|
|
|
id => $req->{id}, |
53
|
|
|
|
|
|
|
params => $req->{params}, |
54
|
0
|
|
|
|
|
0
|
); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
0
|
return \@procs; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub construct_from_get_req { |
60
|
1
|
|
|
1
|
0
|
1
|
my ($self, $req) = @_; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
2
|
my $params = $req->query_parameters; |
63
|
1
|
|
|
|
|
101
|
my $decoded_params; |
64
|
1
|
50
|
|
|
|
3
|
if ($params->{params}) { |
65
|
1
|
|
|
|
|
1
|
$decoded_params = eval { $self->coder->decode( $params->{params} ) }; |
|
1
|
|
|
|
|
2
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
return [ |
68
|
|
|
|
|
|
|
$self->construct_procedure( |
69
|
|
|
|
|
|
|
method => $params->{method}, |
70
|
|
|
|
|
|
|
id => $params->{id}, |
71
|
1
|
|
|
|
|
11
|
params => $decoded_params |
72
|
|
|
|
|
|
|
) |
73
|
|
|
|
|
|
|
]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |