package POE::Component::Client::REST::JSON;
use JSON;
use Moose;
our $VERSION = '0.05';
extends q(POE::Component::Client::REST);
sub cook_request {
my $request = $_[0];
if(my $content = $reques
t->content) {
$content = encode_json($content);
$request->content_type('application/json');
$request->content($content);
$request->header('Content-Encoding' => 'UTF-8');
};
return
e_json($response->content), $response);
};
has '+response_cooker' => (default => sub { \&cook_response });
1;
__END__
=head1 NAME
POE::Component::Client::REST::JSON - Low-level interface for JSON
package POE::Component::Client::CouchDB::Database;
use Moose;
use JSON;
our $VERSION = 0.05;
has couch => (
is => 'ro',
isa => 'POE::Component::Client::CouchDB',
required => 1,
);
);
}
sub get_revinfo {
my ($self, $id, @opt) = @_;
$self->call(GET => $id, query => {revs => JSON::true}, @opt);
}
sub create {
my ($self, $doc, @opt) = @_;
$self->call(POST => q(), content
hDB docs.
=over 4
=item call I<method, path, ...>
This is L<call|POE::Component::Client::REST::JSON/METHODS> with the url and
database parts filled in - use a path such as "_all_docs" instead. You
;
use POE qw(Component::Client::REST::JSON);
use Moose;
our $VERSION = '0.05';
has rest => (
is => 'ro',
isa => 'POE::Component::Client::REST::JSON',
handles => [qw(shutdown)],
defa
ult => sub {
POE::Component::Client::REST::JSON->new(Alias => "$_[0]-REST")
},
);
has host => (
is => 'ro',
isa => 'Str',
default => 'localhost'
);
has port => (
is
1 VERSION
Version 0.05
=head1 SYNOPSIS
This class makes use of L<POE::Component::Client::REST::JSON> to provide an
asynchronous interface to the CouchDB REST API. All methods use
L<call|/METHODS>
e of the nastier details of talking to a REST
service.
use POE qw(Component::Client::REST::JSON);
# simple CouchDB example
POE::Session->create(inline_states => {
_start => sub
poe_kernel->alias_set('foo');
my $rest = $_[HEAP]->{rest} = POE::Component::Client::REST::JSON->new;
$rest->call(GET => 'http://localhost:5984/_all_dbs', callback =>
[$_[SESS
w
one (or the same one, modified). Undefined by default, but see
L<POE::Component::Client::REST::JSON>.
=item response_cooker
Similar to the above, but returns a list of things to be passed to the