JSON::RPC2::AnyEvent::Client - Nonblocking JSON RPC2 client with method mapping.
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;
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.
The constructor supports these arguments (all as key => value pairs).
key => value
The hostname or ip address.
The tcp port number
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
agent.remote_fn
Type of RPC call, default listed.
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
method_name
remap_method_name
Set remote service name, if undef - then no service name used.
RPC listed call type will be used.
RPC named call type will be used.
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.
L<JSON::XS> L<AnyEvent::Handle>; L<JSON::RPC2::Client>;
Copyright (C) Serguei Okladnikov.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Serguei Okladnikov < oklas@cpan.org >
To install JSON::RPC2::AnyEvent::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::RPC2::AnyEvent::Client
CPAN shell
perl -MCPAN -e shell install JSON::RPC2::AnyEvent::Client
For more information on module installation, please visit the detailed CPAN module installation guide.