AnyEvent-RPC
view release on metacpan or search on metacpan
lib/AnyEvent/RPC.pm view on Meta::CPAN
package AnyEvent::RPC;
use 5.006000;
use common::sense 2;
m{
use strict;
use warnings;
}; # Until cpants will know it make strict
use Carp;
=head1 NAME
AnyEvent::RPC - Abstract framework for Asyncronous RPC clients
=cut
our $VERSION = '0.05';
=head1 SYNOPSIS
use AnyEvent::RPC;
my $rpc = AnyEvent::RPC->new(
host => 'your.api.host',
port => 8080,
base => '/api/rest/',
type => 'REST', # or type => '+AnyEvent::RPC::Enc::REST',
)
$rpc->req( # will be called as GET http://your.api.host:8080/api/rest/method/path/args?query=param
call => [ method => qw(path args)],
query => { query => 'param' },
cb => sub { # ( response, code, error )
if (my $response = shift) {
#
} else {
my ($code,$err) = @_;
}
},
);
=cut
sub ua { shift->{ua} }
sub encoder { shift->{encoder} }
sub new {
my $pkg = shift;
my $self = bless {}, $pkg;
$self->init(@_);
$self->components;
$self;
}
sub init {
my $self = shift;
local $SIG{__WARN__} = sub { local $_ = shift; s{\n$}{};carp $_ };
my %args = (
base => '/',
@_
);
@$self{keys %args} = values %args;
$self->{$_} or croak "$_ not defined" for qw(host);
$self->{useragent} ||= 'AnyEvent::RPC/'.$AnyEvent::RPC::VERSION;
return;
}
sub components {
my $self = shift;
my $package = ref $self;
unless ( ref $self->{encoder} ) {
$self->{encoder} = $self->_load(
( run in 1.640 second using v1.01-cache-2.11-cpan-df04353d9ac )