NAME
XAS::Lib::Mixins::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::Net::Server'
mixin => 'XAS::Lib::Mixins::JSON::Server XAS::Lib::Mixins::Keepalive',
vars => {
PARAMS => {
-port => { optional => 1, default => 9500 },
-tcp_keepalive => { optional => 1, default => 0 }
}
}
;
sub handle_connection {
my ($self, $wheel) = @_[OBJECT, ARG0];
if (my $socket = $self->{clients}->{$wheel}->{socket}) {
if ($self->tcp_keepalive) {
$self->log->info("keepalive enabled");
$self->init_keepalive();
$self->enable_keepalive($socket);
}
}
}
sub echo {
my ($self, $params, $ctx) = @_[OBJECT, ARGO, ARG1];
my $alias = $self->alias;
my $line = $params->{line};
$poe_kernel->post($alias, 'process_response', $line, $ctx);
}
sub init {
my $class = shift;
my $self = $class->SUPER::init(@_);
my @methods = ['echo'];
$self->init_json_server(\@methods);
return $self;
}
package main;
my $echo = Echo->new();
$echo->run();
DESCRIPTION
This modules implements a simple JSON RPC v2.0 server as a mixin. It doesn't support "Notification" calls.
METHODS
init_json_server($methods)
This initializes the module.
methods
A handle to a Set::Light object that contains the methods that can be evoked.
EVENTS
process_request(OBJECT, ARG0, ARG1)
process_response(OBJECT, ARG0, ARG1)
process_errors(OBJECT, ARG0, ARG1)
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (C) 2014 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.