line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Server::JSONRPC::Batch; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
31977
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1163
|
use Class::Load (); |
|
1
|
|
|
|
|
420785
|
|
|
1
|
|
|
|
|
54
|
|
7
|
1
|
|
|
1
|
|
1487
|
use HTTP::Body (); |
|
1
|
|
|
|
|
439931
|
|
|
1
|
|
|
|
|
218
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $Method = 'system.handle_batch'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
1
|
|
|
1
|
|
2
|
my $class = 'JSON::RPC::Common::Procedure::Call'; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
6
|
Class::Load::load_class($class); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $meta = $class->meta; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$meta->make_mutable(); |
23
|
|
|
|
|
|
|
$meta->add_around_method_modifier( |
24
|
|
|
|
|
|
|
'inflate', |
25
|
|
|
|
|
|
|
sub { |
26
|
0
|
|
|
|
|
|
my ($meth, $class, @args) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
0
|
|
|
|
if (@args == 1 && ref($args[0]) eq 'ARRAY') { |
29
|
0
|
|
|
|
|
|
return $class->new_from_data( |
30
|
|
|
|
|
|
|
jsonrpc => '2.0', |
31
|
|
|
|
|
|
|
id => scalar(time()), |
32
|
|
|
|
|
|
|
method => $Catalyst::Plugin::Server::JSONRPC::Batch::Method, |
33
|
|
|
|
|
|
|
params => $args[0] |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
|
return $meth->($class, @args); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
); |
41
|
0
|
|
|
|
|
|
$meta->make_immutable(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub setup_engine { |
46
|
|
|
|
|
|
|
my $app = shift(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$app->server->jsonrpc->add_private_method( |
49
|
|
|
|
|
|
|
$Method => sub { |
50
|
|
|
|
|
|
|
my ($c, @args) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $config = $c->server->jsonrpc->config; |
53
|
|
|
|
|
|
|
my $req = $c->req; |
54
|
|
|
|
|
|
|
my $res = $c->res; |
55
|
|
|
|
|
|
|
my $stash = $c->stash; |
56
|
|
|
|
|
|
|
my $parser = $req->jsonrpc->_jsonrpc_parser; |
57
|
|
|
|
|
|
|
my @results; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# HACK: Store values. |
60
|
|
|
|
|
|
|
my $body = $req->_body; |
61
|
|
|
|
|
|
|
my $path = $config->path; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
foreach (map { $parser->encode($_) } @{$req->args}) { |
64
|
|
|
|
|
|
|
$config->path(''); |
65
|
|
|
|
|
|
|
$stash->{jsonrpc_generated} = 0; |
66
|
|
|
|
|
|
|
$req->_body(HTTP::Body->new($req->content_type, length($_))); |
67
|
|
|
|
|
|
|
$req->_body->add($_); |
68
|
|
|
|
|
|
|
$res->body(''); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$c->prepare_action(); |
71
|
|
|
|
|
|
|
$c->dispatch(); |
72
|
|
|
|
|
|
|
$stash->{current_view_instance}->process($c) |
73
|
|
|
|
|
|
|
unless $stash->{jsonrpc_generated}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
push(@results, $res->body); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Restore values. |
79
|
|
|
|
|
|
|
$req->_body($body); |
80
|
|
|
|
|
|
|
$config->path($path); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $result = '[' . join(',', @results) . ']'; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$res->content_length(length($result)); |
85
|
|
|
|
|
|
|
$res->body($result); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$app->next::method(@_); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=pod |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Catalyst::Plugin::Server::JSONRPC::Batch - batch requests implementation for |
102
|
|
|
|
|
|
|
Catalyst JSON-RPC server plugin. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use Catalyst qw/ |
107
|
|
|
|
|
|
|
Server |
108
|
|
|
|
|
|
|
Server::JSONRPC |
109
|
|
|
|
|
|
|
Server::JSONRPC::Batch |
110
|
|
|
|
|
|
|
/; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Catalyst::Plugin::Server::JSONRPC::Batch implements batch JSON-RPC requests as |
115
|
|
|
|
|
|
|
its described in specification version 2.0. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SEE ALSO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Plugin::Server::JSONRPC>. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L<JSON-RPC 2.0 Specification|http://www.jsonrpc.org/specification>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SUPPORT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 4 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item Repository |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<http://github.com/dionys/catalyst-plugin-server-jsonrpc-batch> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item Bug tracker |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<http://github.com/dionys/catalyst-plugin-server-jsonrpc-batch/issues> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Denis Ibaev, C<dionys@cpan.org>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 THANKS TO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Ivan Fomichev (IFOMICHEV), Sergey Romanov. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright (C) 2012, Denis Ibaev. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
150
|
|
|
|
|
|
|
the same terms as Perl itself. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> for more information. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |