AnyEvent-KVStore-Etcd

 view release on metacpan or  search on metacpan

lib/AnyEvent/KVStore/Etcd.pm  view on Meta::CPAN

package AnyEvent::KVStore::Etcd;

use 5.010;
use strict;
use warnings;
use Net::Etcd;
use Types::Standard qw(Str Int Bool);
use Moo;
use JSON 'decode_json';
use MIME::Base64 'decode_base64';
with 'AnyEvent::KVStore::Driver';

=head1 NAME

AnyEvent::KVStore::Etcd - An Etcd driver for AnyEvent::KVStore

=head1 VERSION

Version 0.1.0

=cut

our $VERSION = '0.1.0';


=head1 SYNOPSIS

   use AnyEvent::KVStore;
   $config = { host => $host, port => $port };
   my $store = AnyEvent::KVStore->new(module => 'etcd', config => $config);

=head1 DESCRIPTION

AnyEvent::KVStore::Etcd is a driver for L<AnyEvent::KVStore> which uses the
Etcd distributed key-value store as its backend.  We use the Net::Etcd driver
for this, though there are some important limitations.

The primary documentation for this module is in the L<AnyEvent::KVStore> module
but there are some important limitations discussed here.

This module can also be used directly for simplified access to an Etcd database.

=head2 AnyEvent Loops, Callbacks, and KVStore Operations

Net::Etcd uses L<AnyEvent::HTTP> for its transport layer.  It further blocks in
an L<AnyEvent> loop to wait for the response.  For obvious reasons, this does
not work.  So, the main key/value operations cannot be done from inside an
event loop.  This leads to a number of possible solutions including forking and
running the request in another process.

One option, though it does incur significant startup cost, is to use L<Coro>
and move the callback from a C<sub {}> call to an C<unblock_sub {}> call.  This
is probably the simplest approach and it works.  In general you get sequential
ordering but this is not a hard guarantee.  Another approach might be to move
processing into worker threads.

=head1 ATTRIBUTES/ACCESSORS

If accessing the module directly, the following accessors are available.  These
are not generally needed and are mostly used internally for managing the
connection to the etcd server.

These are also keys for the config hash.

All attributes are optional.

=head2 host Str

This is the hostname for the etcd connection.  It defaults to localhost.

=cut

has host => (is => 'ro', isa => Str, default => sub { 'localhost' });

=head2 port Int

Port for connection.  It defaults to 2379.

=cut

has port => (is => 'ro', isa => Int, default => sub { 2379 } );

=head2 ssl Bool default false

whether to use SSL or not.  The default is no.

=cut

has ssl => (is => 'ro', isa => Bool, default => 0);

=head2 user Str

Username for authentication.  Does not authenticate if not set.

=cut

has user => (is => 'ro', isa => Str);

=head2 password Str

Password for authentication.

=cut


has password => (is => 'ro', isa => Str);

=head2 cnx Net::Etcd

This is the active connection to the etcd database.

=cut

# $self->_slice returns a hashref with the properties requested.
# This relies on the fact that Moo(se) objects are blessed hashrefs.



( run in 0.873 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )