Author image Daisuke (yet another) Maki
and 1 contributors


JSON::RPC2::AnyEvent::Server::Handle - dispatch JSON-RPC requests comming from file-handle to JSON::RPC2::AnyEvent::Server


    use AnyEvent::Socket;
    use JSON::RPC2::AnyEvent::Server::Handle;  # Add `dispatch_fh' method in JSON::RPC2::AnyEvent::Server
    my $srv = JSON::RPC2::AnyEvent::Server->(
        echo => sub{
            my ($cv, $args) = @_;
    my $w = tcp_server undef, 8080, sub {
        my ($fh, $host, $port) = @_;
        my $hdl = $srv->dispatch_fh($fh);  # equivalent to JSON::RPC2::AnyEvent::Server::Handle->new($srv, $fh)
            my $h = shift;  # JSON::RPC2::AnyEvent::Server::Handle
            # underlying fh is already closed here
            undef $hdl;
            my ($h, $fatal, $message) = @_;
            warn $message;
            $h->destroy  if $fatal;
            undef $hdl;


JSON::RPC2::AnyEvent::Server::Handle is AnyEvent::Handle adapter for JSON::RPC2::AnyEvent::Server.


CLASS->new($srv, $fh) -> $handle

$srv->dispatch_fh($fh) -> $handle

Connect $fh to $srv and returns a JSON::RPC2::AnyEvent::Handle object. The object dispatches coming requests to $srv and sends back returned response to $fh.

This module adds dispatch_fh method in JSON::RPC2::AnyEvent::Server, which can be used as a shortcut of new.

$srv: JSON::RPC2::AnyEvent::Server

JSON::RPC2::AnyEvent::Server object to connect.

$fh: AnyEvent::Handle or file-handle

File handle to be connected.

$handle: JSON::RPC2::AnyEvent::Server::Handle

New JSON::RPC2::AnyEvent::Server::Handle object.

$self->on_end(sub{ my($self) = @_; ... })

Registers callback called when the underlying file handle successfully reaches EOF.

$self->on_error(sub{ my($self, $fatal, $message) = @_; ... })

Registers callback called when an error occurs during comminication.


Manually destroys this object.


Copyright (C) Daisuke (yet another) Maki.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Daisuke (yet another) Maki <>