AnyEvent::JSONRPC::Client - Base class for JSON-RPC clients
use AnyEvent::JSONRPC::XXX::Client; my $client = AnyEvent::JSONRPC::XXX::Client->new( ... ); # blocking interface my $res = $client->call( echo => 'foo bar' )->recv; # => 'foo bar'; # non-blocking interface $client->call( echo => 'foo bar' )->cb(sub { my $res = $_[0]->recv; # => 'foo bar'; });
This is the base class for clients in the AnyEvent::JSONRPC suite of modules. Current implementations includes a TCP client and a HTTP client. See these for arguments to the constructors.
The main thing you have to remember is that all the data retrieval methods return an AnyEvent condvar, $cv. If you want the actual data from the request, there are a few things you can do.
$cv
Create new client object and return it.
my $client = AnyEvent::JSONRPC::TCP::Client->new( %options, );
Available options are specific to each implementation.
Call remote method named $method with parameters @params. And return condvar object for response.
$method
@params
my $cv = $client->call( echo => 'Hello!' ); my $res = $cv->recv;
If server returns an error, $cv->recv causes croak by using $cv->croak. So you can handle this like following:
$cv->recv
$cv->croak
my $res; eval { $res = $cv->recv }; if (my $error = $@) { # ... }
Same as call method, but not handle response. This method just notify to server.
$client->notify( echo => 'Hello' );
Daisuke Murase <typester@cpan.org>
Copyright (c) 2009 by KAYAC Inc.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install AnyEvent::JSONRPC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::JSONRPC
CPAN shell
perl -MCPAN -e shell install AnyEvent::JSONRPC
For more information on module installation, please visit the detailed CPAN module installation guide.