package JSON::RPC::Dispatcher;
$JSON::RPC::Dispatcher::VERSION = '0.0508';
=head1 NAME
JSON::RPC::Dispatcher - A JSON-RPC 2.0 server.
=head1 VERSION
version 0.0508
=head1 SYNOPSIS
In F<app.psgi>:
use JSON::RPC::Dispatcher;
my $rpc = JSON::RPC::Dispatcher->new;
sub add_em {
my @params = @_;
my $sum = 0;
$sum += $_ for @params;
return $sum;
}
$rpc->register( 'sum', \&add
thod=sum;params=[2,3,5];id=1
Or by posting JSON to it like this:
{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}
And you'd get back:
{"jsonrpc":"2.0","result":10,"id":"1"}
=head1 DE
package JSON::RPC::Dispatcher::App;
$JSON::RPC::Dispatcher::App::VERSION = '0.0508';
use Moose;
use JSON::RPC::Dispatcher;
=head1 NAME
JSON::RPC::Dispatcher::App - A base class for creating object o
ION
version 0.0508
=head1 SYNOPSIS
Create your module:
package MyApp;
use Moose;
extends 'JSON::RPC::Dispatcher::App';
sub sum {
my ($self, @params) = @_;
my $sum = 0;
$sum += $_
ented JSON-RPC applications. This is a huge benefit when writing a larger app or suite of applications rather than just exposing a procedure or two. If you build out classes of methods using JSON::RPC
package JSON::RPC::Dispatcher::Procedure;
$JSON::RPC::Dispatcher::Procedure::VERSION = '0.0508';
=head1 NAME
JSON::RPC::Dispatcher::Procedure - The data holder between RPC requests and responses.
=h
ead1 VERSION
version 0.0508
=head1 SYNOPSIS
use JSON::RPC::Dispatcher::Procedure;
my $proc = JSON::RPC::Dispatcher::Procedure->new;
$proc->error_code(300);
my $method = $proc->method;
=head
----------
=head2 invalid_request ( [ data ] )
Sets an Invalid Request error as defined by the JSON-RPC 2.0 spec.
=head3 data
Optionally set some error data for the error.
=cut
sub invalid_req