line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::RPC::Dispatcher::Procedure; |
2
|
|
|
|
|
|
|
$JSON::RPC::Dispatcher::Procedure::VERSION = '0.0508'; |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
JSON::RPC::Dispatcher::Procedure - The data holder between RPC requests and responses. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
version 0.0508 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use JSON::RPC::Dispatcher::Procedure; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $proc = JSON::RPC::Dispatcher::Procedure->new; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$proc->error_code(300); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $method = $proc->method; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Something needs to act as an intermediary to hold the data and state of requests coming in, RPC being called, and responses going out. THis module fits that bill. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
17
|
use Moose; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
25
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#-------------------------------------------------------- |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 error_code ( [ code ] ) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Returns the current error code. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head3 code |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
An integer. Sets an error code. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 has_error_code ( ) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns a boolean indicating whether an error code has been set. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has error_code => ( |
47
|
|
|
|
|
|
|
is => 'rw', |
48
|
|
|
|
|
|
|
predicate => 'has_error_code', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#-------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 error_message ( [ message ] ) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Returns the current error message. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head3 message |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
A string. Sets an error message. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has error_message => ( |
64
|
|
|
|
|
|
|
is => 'rw', |
65
|
|
|
|
|
|
|
default => undef, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#-------------------------------------------------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 error_data ( [ data ] ) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns the current error data. Error data is entirely defined by the application (e.g. detailed error information, nested errors etc.). |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head3 data |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
A scalar or reference. Sets an error data. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has error_data => ( |
81
|
|
|
|
|
|
|
is => 'rw', |
82
|
|
|
|
|
|
|
default => undef, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#-------------------------------------------------------- |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 error ( code, message, [ data ] ) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub error { |
92
|
0
|
|
|
0
|
1
|
|
my ($self, $code, $message, $data) = @_; |
93
|
0
|
|
|
|
|
|
$self->error_code($code); |
94
|
0
|
|
|
|
|
|
$self->error_message($message); |
95
|
0
|
|
|
|
|
|
$self->error_data($data); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#-------------------------------------------------------- |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 invalid_request ( [ data ] ) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Sets an Invalid Request error as defined by the JSON-RPC 2.0 spec. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head3 data |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Optionally set some error data for the error. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub invalid_request { |
111
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
112
|
0
|
|
|
|
|
|
$self->error_code(-32600); |
113
|
0
|
|
|
|
|
|
$self->error_message('Invalid Request.'); |
114
|
0
|
|
|
|
|
|
$self->error_data($msg); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#-------------------------------------------------------- |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 method_not_found ( [ data ] ) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Sets a Method Not Found error as defined by the JSON-RPC 2.0 spec. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head3 data |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Optionally set some error data for the error. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub method_not_found { |
130
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
131
|
0
|
|
|
|
|
|
$self->error_code(-32601); |
132
|
0
|
|
|
|
|
|
$self->error_message('Method not found.'); |
133
|
0
|
|
|
|
|
|
$self->error_data($msg); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#-------------------------------------------------------- |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 invalid_params ( [ data ] ) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Sets an Invalid Params error as defined by the JSON-RPC 2.0 spec. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 data |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Optionally set some error data for the error. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub invalid_params { |
149
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
150
|
0
|
|
|
|
|
|
$self->error_code(-32602); |
151
|
0
|
|
|
|
|
|
$self->error_message('Invalid params.'); |
152
|
0
|
|
|
|
|
|
$self->error_data($msg); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#-------------------------------------------------------- |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 internal_error ( [ data ] ) |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Sets an Internal Error as defined by the JSON-RPC 2.0 spec. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head3 data |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Optionally set some error data for the error. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub internal_error { |
168
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
169
|
0
|
|
|
|
|
|
$self->error_code(-32603); |
170
|
0
|
|
|
|
|
|
$self->error_message('Internal error.'); |
171
|
0
|
|
|
|
|
|
$self->error_data($msg); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
#-------------------------------------------------------- |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 method ( [ name ] ) |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns the name of the procedure to be called. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head3 name |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Per specification, any string is accepted as a potential JSON-RPC method name. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
has method => ( |
187
|
|
|
|
|
|
|
is => 'rw', |
188
|
|
|
|
|
|
|
default => undef, |
189
|
|
|
|
|
|
|
); |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#-------------------------------------------------------- |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 params ( [ data ] ) |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Returns the parameters to be passed into the procedure. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head3 data |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
An array or hashref. Sets the parameters. Will set an error if the params are not an array ref or hash ref. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
has params => ( |
204
|
|
|
|
|
|
|
is => 'rw', |
205
|
|
|
|
|
|
|
default => undef, |
206
|
|
|
|
|
|
|
); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
#-------------------------------------------------------- |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 id ( [ id ] ) |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Returns the id of the request. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 id |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Sets the id of the request. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
has id => ( |
222
|
|
|
|
|
|
|
is => 'rw', |
223
|
|
|
|
|
|
|
default => undef, |
224
|
|
|
|
|
|
|
); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
#-------------------------------------------------------- |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 result ( [ data ] ) |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Returns the data that will be sent back to the client. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head3 data |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Sets the data that will be sent back to the client. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
has result => ( |
239
|
|
|
|
|
|
|
is => 'rw', |
240
|
|
|
|
|
|
|
default => undef, |
241
|
|
|
|
|
|
|
); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
#-------------------------------------------------------- |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 response ( ) |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Formats the data stored in this object into the data structure expected by L<JSON::RPC::Dispatcher>, which will ultimately be returned to the client. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub response { |
252
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
253
|
0
|
|
|
|
|
|
my $error; |
254
|
0
|
0
|
|
|
|
|
if ($self->has_error_code) { |
255
|
0
|
|
|
|
|
|
$error = { |
256
|
|
|
|
|
|
|
code => $self->error_code, |
257
|
|
|
|
|
|
|
message => $self->error_message, |
258
|
|
|
|
|
|
|
data => $self->error_data, |
259
|
|
|
|
|
|
|
}; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
return { |
262
|
0
|
|
|
|
|
|
jsonrpc => '2.0', |
263
|
|
|
|
|
|
|
id => $self->id, |
264
|
|
|
|
|
|
|
result => $self->result, |
265
|
|
|
|
|
|
|
error => $error, |
266
|
|
|
|
|
|
|
}; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 LEGAL |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
JSON::RPC::Dispatcher is Copyright 2009-2010 Plain Black Corporation (L<http://www.plainblack.com/>) and is licensed under the same terms as Perl itself. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=cut |
274
|
|
|
|
|
|
|
|
275
|
3
|
|
|
3
|
|
22197
|
no Moose; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
15
|
|
276
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |