/bin/env perl
package IO::Multiplex::Intermediary;
our $VERSION = "0.06";
use MooseX::POE;
use JSON;
use List::MoreUtils qw(any);
use Scalar::Util qw(reftype);
use POE qw(
Wheel::SocketFactory
my $json = eval { from_json($input) };
{
if ($@ || !$json) {
warn "JSON error: $@";
}
elsif (!exists $json->{param}) {
warn "Invalid JSON struct
last unless $json->{data}->{id};
last unless reftype($self->rw_set);
last unless $self->rw_set->{ $json->{data}->{id} };
if ($json->{param} eq 'output')
use namespace::autoclean;
use IO::Socket;
use IO::Select;
use Time::HiRes qw(gettimeofday);
use JSON;
local $| = 1;
has socket => (
is => 'rw',
isa => 'IO::Socket::INET',
@inputs = grep { $_ } split /\e/m, $input;
for (@inputs) {
my $output = $self->parse_json($_);
$self->socket->send("$output\n\e");
}
};
sub build_response {
my $self
ift;
my $data = shift;
return to_json({param => 'null'});
}
sub input_hook {
my $self = shift;
my $data = shift;
return to_json(
{
param => 'output',