AnyEvent-KVStore-Etcd

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Net::Etcd" : "0",
            "Type::Tiny" : "0",
            "Types::Standard" : "0",
            "perl" : "5.006"
         }
      },
      "test" : {
         "requires" : {
            "AnyEvent" : "0",
            "Capture::Tiny" : "0",
            "Data::Dumper" : "0",
            "MIME::Base64" : "0",
            "Test::More" : "0"
         }
      }
   },
   "release_status" : "stable",
   "version" : "v0.1.0",
   "x_serialization_backend" : "JSON::PP version 4.16"
}

META.yml  view on Meta::CPAN

---
abstract: 'An Etcd driver for AnyEvent::KVStore'
author:
  - 'Chris Travers <chris.travers@gmail.com>'
build_requires:
  AnyEvent: '0'
  Capture::Tiny: '0'
  Data::Dumper: '0'
  ExtUtils::MakeMaker: '0'
  MIME::Base64: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010'
license: bsd
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

Makefile.PL  view on Meta::CPAN

    ABSTRACT_FROM    => 'lib/AnyEvent/KVStore/Etcd.pm',
    LICENSE          => 'bsd',
    MIN_PERL_VERSION => '5.006',
    CONFIGURE_REQUIRES => {
        'ExtUtils::MakeMaker' => '0',
    },
    TEST_REQUIRES => {
        'MIME::Base64'  => 0,
        'Test::More'    => 0,
        'Capture::Tiny' => 0,
        'Data::Dumper'  => 0,
        'AnyEvent'      => 0,
    },
    PREREQ_PM => {
        'AnyEvent::KVStore' => 0,
        'Net::Etcd'         => 0,
        'JSON'              => 0,
        'Type::Tiny'        => 0,
        'Types::Standard'   => 0,
    },
    dist  => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },

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

This sets up a "watch" where notifications of changed keys are passed to the
script.  This can only really be handled inside an AnyEvent loop because the
changes can come from outside the program.

The callback takes the arguments of C<($key, $value)> of the new values.

=cut

sub _portability_wrapper {
    my ($sub, $result) = @_;
    use Data::Dumper;
    for my $e (@{decode_json($result)->{result}->{events}}){
        $e = $e->{kv};
        &$sub(decode_base64($e->{key}), decode_base64($e->{value}));
   }
}

sub watch($$$) {
    my ($self, $pfx, $subroutine ) = @_;
    return $self->cnx->watch({key => $pfx, range_end => _add_one($pfx)},
        sub { my ($result)  = @_; _portability_wrapper($subroutine, $result) })->create;

t/02-readwrite.t  view on Meta::CPAN

use lib 't';
use Test::Etcdkv;
use Test::More tests => 9;
use AnyEvent::KVStore;
use Data::Dumper;

my $guard = Test::Etcdkv->guard;
my $config = Test::Etcdkv->config;
ok(my $store = AnyEvent::KVStore->new(module => 'etcd', config => $config), 'Initiated the store');
ok((not $store->exists('/test/foo')), '/test/foo does not exist yet');
ok($store->write('/test/foo', 'bar'), 'Wrote bar to /test/foo');
ok($store->exists('/test/foo'), 'test/foo now exists');
is($store->read('/test/foo'), 'bar', 'got bar back from /test/foo');
ok($store->write('/test/fo2', 'bar'), 'Wrote bar to /test/fo2');
is_deeply([sort { $a cmp $b } $store->list('/test/fo')], ['/test/fo2', '/test/foo'], 'got keys for prefix /test/fo') || diag(Dumper($store->list('/test/fo'))) ;

t/03-watch.t  view on Meta::CPAN

use lib 't';
use Test::Etcdkv;
use Test::More tests => 10;
use AnyEvent::KVStore;
use Data::Dumper;
use AnyEvent;

my $cb = sub { my ($k, $v) = @_; ok(1, "Got $k: $v"); };
my $cv = AnyEvent->condvar;

my $guard = Test::Etcdkv->guard;
my $config = Test::Etcdkv->config;

ok(my $store = AnyEvent::KVStore->new(module => 'etcd', config => $config), 'Initiated the store');



( run in 0.315 second using v1.01-cache-2.11-cpan-4d50c553e7e )