NAME
XAS::Lib::RPC::JSON::Server - A mixin for a simple JSON RPC server
SYNOPSIS
package Echo;
use POE;
use XAS::Class
debug => 0,
version => '0.01',
base => 'XAS::Lib::RPC::JSON::Server'
;
sub session_initialize {
my $self = shift;
my $alias = $self->alias;
$self->log->debug("$alias: entering session_initialize()");
# define our events.
$poe_kernel->state('echo', $self, '_echo');
# define the RPC methods, these are linked to the above events
$self->methods->insert('echo');
# walk the chain
$self->SUPER::session_initialize();
$self->log->debug("$alias: leaving session_initialize()");
}
sub _echo {
my ($self, $params, $ctx) = @_[OBJECT, ARGO, ARG1];
my $alias = $self->alias;
my $line = $params->{'line'};
$self->process_response($line, $ctx);
}
package main;
my $echo = Echo->new();
$echo->run();
DESCRIPTION
This modules implements a simple JSON RPC v2.0 server. It doesn't support "Notification" calls.
METHODS
new
This module inherits from XAS::Lib::Net::Server and accepts the same parameters.
methods
A handle to a Set::Light object that contains the methods that can be evoked.
process_request($input, $ctx)
This method accepts a JSON RPC packet and dispatches to the appropiate handler. If a handler is not present, it signals an error and returns that to the client.
process_response($output, $ctx)
This method will process output and convert it into a JSON RPC response.
process_error($error, $ctx)
This method will process errors, it will be converted into a JSON RPC error response.
SEE ALSO
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (c) 2012-2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.