-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add txn and full test support. (#15)
Add Net::Etcd::KV::Op and Net::Etcd::KV::Compare classes. Fixes #13
- Loading branch information
Showing
10 changed files
with
430 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Net::Etcd; | ||
use Data::Dumper; | ||
my ($host, $port); | ||
|
||
if ( $ENV{ETCD_TEST_HOST} and $ENV{ETCD_TEST_PORT}) { | ||
$host = $ENV{ETCD_TEST_HOST}; | ||
$port = $ENV{ETCD_TEST_PORT}; | ||
} | ||
|
||
my ($watch,$key); | ||
my $etcd = Net::Etcd->new( { host => $host, port => $port } ); | ||
|
||
# create watch with callback and store events | ||
$watch = $etcd->watch( { key => 'foo'}, sub { | ||
my ($result) = @_; | ||
print STDERR Dumper($result); | ||
})->create; | ||
|
||
$etcd->put({ key => 'foo', value => 'bar' }); | ||
|
||
$etcd->range({ key => 'foo' }); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use utf8; | ||
package Net::Etcd::KV::Compare; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Moo; | ||
use Types::Standard qw(Str Int Bool HashRef ArrayRef); | ||
use MIME::Base64; | ||
use Data::Dumper; | ||
use JSON; | ||
|
||
with 'Net::Etcd::Role::Actions'; | ||
|
||
use namespace::clean; | ||
|
||
=head1 NAME | ||
Net::Etcd::KV::Compare | ||
=cut | ||
|
||
our $VERSION = '0.010'; | ||
|
||
=head1 DESCRIPTION | ||
Op | ||
=head1 ACCESSORS | ||
=head2 result | ||
result is logical comparison operation for this comparison. | ||
=cut | ||
|
||
has result => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 target | ||
target is the key-value field to inspect for the comparison. | ||
=cut | ||
|
||
has target => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 key | ||
key is the subject key for the comparison operation. | ||
=cut | ||
|
||
has key => ( | ||
is => 'ro', | ||
coerce => sub { return encode_base64( $_[0], '' ) if $_[0] }, | ||
); | ||
|
||
|
||
=head2 version | ||
version is the version of the given key | ||
=cut | ||
|
||
has version => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 create_revision | ||
create_revision is the creation revision of the given key | ||
=cut | ||
|
||
has create_revision => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 mod_revision | ||
mod_revision is the last modified revision of the given key. | ||
=cut | ||
|
||
has mod_revision => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 value | ||
value is the value of the given key, in bytes. | ||
=cut | ||
|
||
has value => ( | ||
is => 'ro', | ||
coerce => sub { return encode_base64( $_[0], '' ) if $_[0] }, | ||
); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use utf8; | ||
package Net::Etcd::KV::Op; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Moo; | ||
use Types::Standard qw(InstanceOf Str Int Bool HashRef ArrayRef); | ||
use MIME::Base64; | ||
use Data::Dumper; | ||
use JSON; | ||
|
||
with 'Net::Etcd::Role::Actions'; | ||
|
||
use namespace::clean; | ||
|
||
=head1 NAME | ||
Net::Etcd::KV::Op | ||
=cut | ||
|
||
our $VERSION = '0.010'; | ||
|
||
=head1 DESCRIPTION | ||
Op | ||
=head1 ACCESSORS | ||
=head2 request_range | ||
=cut | ||
|
||
has request_range => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 request_put | ||
=cut | ||
|
||
has request_put => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 request_delete_range | ||
=cut | ||
|
||
has request_delete_range => ( | ||
is => 'ro', | ||
); | ||
|
||
=head2 create | ||
create op | ||
=cut | ||
|
||
#TODO this dirty hack should be a perl data object and then make json. | ||
|
||
sub create { | ||
my $self = shift; | ||
my @op; | ||
my $put = $self->request_put; | ||
my $range = $self->request_range; | ||
my $delete_range = $self->request_delete_range; | ||
push @op, '{"requestPut":' . $put->json_args . '}' if defined $put; | ||
push @op, '{"requestRange":' . $range->json_args . '}' if defined $range; | ||
push @op, '{"requestDeleteRange":' . $delete_range->json_args . '}' if defined $delete_range; | ||
return @op; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.