diff options
author | Robin Edwards <robin.ge@gmail.com> | 2011-04-20 14:38:43 +0100 |
---|---|---|
committer | Robin Edwards <robin.ge@gmail.com> | 2011-04-20 14:38:43 +0100 |
commit | 79bea382fd2c0753ca9ace79a11bb74c9a1d722b (patch) | |
tree | bde42a47792a27e0a863ee527b88c8c24258f7e9 /lib/Net/Riak/Role/PBC.pm | |
parent | Merge remote branch 'simon/fix_link_encoding' (diff) | |
download | net-riak-79bea382fd2c0753ca9ace79a11bb74c9a1d722b.tar.gz |
merged pbc branch to master
Diffstat (limited to '')
-rw-r--r-- | lib/Net/Riak/Role/PBC.pm | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/Net/Riak/Role/PBC.pm b/lib/Net/Riak/Role/PBC.pm new file mode 100644 index 0000000..605f032 --- /dev/null +++ b/lib/Net/Riak/Role/PBC.pm @@ -0,0 +1,78 @@ +package Net::Riak::Role::PBC; + +use Moose::Role; +use MooseX::Types::Moose qw/Str Int/; + +with qw( + Net::Riak::Role::PBC::Message + Net::Riak::Role::PBC::Bucket + Net::Riak::Role::PBC::MapReduce + Net::Riak::Role::PBC::Link + Net::Riak::Role::PBC::Object); + +use Net::Riak::Types 'Socket'; +use IO::Socket::INET; + +has [qw/r w dw/] => ( + is => 'rw', + isa => Int, + default => 2 +); + +has host => ( + is => 'ro', + isa => Str, + required => 1, +); + +has port => ( + is => 'ro', + isa => Int, + required => 1, +); + +has socket => ( + is => 'rw', + isa => Socket, + predicate => 'has_socket', +); + +sub is_alive { + my $self = shift; + return $self->send_message('PingReq'); +} + +sub connected { + my $self = shift; + return $self->has_socket && $self->socket->connected ? 1 : 0; +} + +sub connect { + my $self = shift; + return if $self->has_socket && $self->connected; + + $self->socket( + IO::Socket::INET->new( + PeerAddr => $self->host, + PeerPort => $self->port, + Proto => 'tcp', + Timeout => 30, + ) + ); +} + +sub all_buckets { + my $self = shift; + my $resp = $self->send_message('ListBucketsReq'); + return ref ($resp->buckets) eq 'ARRAY' ? @{$resp->buckets} : (); +} + +sub server_info { + my $self = shift; + my $resp = $self->send_message('GetServerInfoReq'); + return $resp; +} + +sub stats { die "->stats is only avaliable through the REST interface" } + +1; |