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

NAME

AnyEvent::JSONRPC::Client - Base class for JSON-RPC clients

SYNOPSIS

    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';
    });

DESCRIPTION

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.

AnyEvent condvars

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.

METHODS

new (%options)

Create new client object and return it.

    my $client = AnyEvent::JSONRPC::TCP::Client->new(
        %options,
    );

Available options are specific to each implementation.

call ($method, @params)

Call remote method named $method with parameters @params. And return condvar object for response.

    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:

    my $res;
    eval { $res = $cv->recv };
    
    if (my $error = $@) {
        # ...
    }

notify ($method, @params)

Same as call method, but not handle response. This method just notify to server.

    $client->notify( echo => 'Hello' );

AUTHOR

Daisuke Murase <typester@cpan.org>

COPYRIGHT AND LICENSE

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.