XAS::Lib::RPC::JSON::Server - A mixin for a simple JSON RPC server
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();
This modules implements a simple JSON RPC v2.0 server. It doesn't support "Notification" calls.
This module inherits from XAS::Lib::Net::Server and accepts the same parameters.
A handle to a Set::Light object that contains the methods that can be evoked.
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.
The JSON RPC packet.
Network context for the request.
This method will process output and convert it into a JSON RPC response.
The output from the called handler.
Network context for the response.
This method will process errors, it will be converted into a JSON RPC error response.
The errors that were generated.
Kevin L. Esteb, <kevin@kesteb.us>
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.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.