The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

JSON::RPC2::AnyEvent::Client - Nonblocking JSON RPC2 client with method mapping.

SYNOPSIS

    use JSON::RPC2::AnyEvent::Client;

    # create connection
    my $rpc = JSON::RPC2::AnyEvent::Client->new(
        host    => "127.0.0.1",
        port    => 5555,
    );

    # call
    $rpc->rpcfn( 1, 'two', 3, sub{
        my ( $failed, $result, $error ) = @_;
        print Dumper $result if ! $failed && ! $error;
    })

    # call remote function with some configure
    $rpc->service('agent')->listed()->remote_function( 'param1', 'param2', sub{
        my ( $failed, $result, $error ) = @_;
    })

    # more arguments desctibed below
    my $rpc = JSON::RPC2::AnyEvent::Client->new(
        host    => "127.0.0.1",
        port    => 5555,
        service => 'agent',
        call    => 'listed' || 'named',
        service => '_service',  # rename any this module methods
    );

    # destroy rpc connection when done
    $rpc->destroy;

DESCRIPTION

JSON::RPC2::AnyEvent::Client is JSON RPC2 client, currently with tcp transport, handled by AnyEvent::Handle, and remote functions mapping to local client functions, and based on JSON RPC2 implementation JSON::RPC2::Client.

METHODS

$rpc = new JSON::RPC2::AnyEvent::Client host=>'example.com', ...

The constructor supports these arguments (all as key => value pairs).

host => 'example.com'

The hostname or ip address.

port => 5555

The tcp port number

service => 'agent'

Set the service name, it will be prefix before remote function name with dot as separator. So if service is 'agent' then call like $rpc->remote_fn(), then agent.remote_fn will be called

call => 'listed' || 'named'

Type of RPC call, default listed.

any_method_name => 'remap_method_name'

If remote server have method with same name as in this module, it is possible to rename this module method_name to another name remap_method_name

service ( "service_name" )

Set remote service name, if undef - then no service name used.

listed

RPC listed call type will be used.

named

RPC named call type will be used.

any other name ( $param1, $param2, ..., $cb )

Any method name will called via RPC on remote server. Last param must be event handler cb(). There is params of cb ( $failed, $result, $error ); Where $result is server responce, valid only when there is no fail or error.

DEPENDENCIES

 L<JSON::XS>
 L<AnyEvent::Handle>;
 L<JSON::RPC2::Client>;

LICENSE

Copyright (C) Serguei Okladnikov.

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

AUTHOR

Serguei Okladnikov < oklas@cpan.org >