| POE-Component-Client-CouchDB documentation | Contained in the POE-Component-Client-CouchDB distribution. |
POE::Component::Client::CouchDB - Asynchronous CouchDB server interaction
Version 0.05
This class makes use of POE::Component::Client::REST::JSON to provide an asynchronous interface to the CouchDB REST API. All methods use call to make the request, and follow its calling convention.
use POE qw(Component::Client::CouchDB);
my $alias = 'Huzzah!';
POE::Session->create(inline_states => {
_start => sub {
$poe_kernel->alias_set($alias);
my $couch = POE::Component::Client::CouchDB->new;
$couch->create_db('foobar', callback => [$alias, 'db_created']);
},
db_created => sub {
my ($data, $response) = @_[ARG0..ARG1];
use YAML;
print Dump($data);
$poe_kernel->alias_remove($alias);
},
});
$poe_kernel->run();
You can optionally supply a configured POE::Component::Client::REST::JSON
object to be used, but by default one will be created (you can also get this one to pass to another DB object... ->new(rest => $old->rest))
The hostname of the CouchDB server. Defaults to localhost.
The port of the CouchDB server. Defaults to 5984.
Note that all of these methods take a callback keyword argument (CODE or [session, state]) as their last argument except where otherwise noted.
This is POE::Component::Client::REST::JSON's call with the url part partially filled in - use a path instead (such as "_all_dbs"). You shouldn't need to use this directly, so don't.
These all do what you would expect according to the CouchDB documentation. See http://wiki.apache.org/couchdb/HttpDatabaseApi.
Returns a new POE::Component::Client::CouchDB::Database representing the database with the specified name. This method does not follow the REST calling conventions, cause it's not a REST call!
Equivalent to $obj->rest->shutdown();
Paul Driver, <frodwith at cpan.org>
Probably.
Copyright 2008 Paul Driver
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| POE-Component-Client-CouchDB documentation | Contained in the POE-Component-Client-CouchDB distribution. |
package POE::Component::Client::CouchDB; 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)], default => sub { POE::Component::Client::REST::JSON->new(Alias => "$_[0]-REST") }, ); has host => ( is => 'ro', isa => 'Str', default => 'localhost' ); has port => ( is => 'ro', isa => 'Int', default => 5984, ); sub call { my ($self, $method, $path, @rest) = @_; my ($host, $port) = ($self->host, $self->port); $self->rest->call($method, "http://$host:$port/$path", @rest); } sub all_dbs { my ($self, @opt) = @_; $self->call(GET => _all_dbs => @opt); } sub create_db { my ($self, $name, @opt) = @_; $self->call(PUT => $name, @opt); } sub delete_db { my ($self, $name, @opt) = @_; $self->call(DELETE => $name, @opt); } sub db_info { my ($self, $name, @opt) = @_; $self->call(GET => $name, @opt); } sub database { my ($self, $name) = @_; require POE::Component::Client::CouchDB::Database; return POE::Component::Client::CouchDB::Database->new( couch => $self, name => $name, ); } __PACKAGE__->meta->add_method(db => \&database); 1; __END__