line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Consul::API::KV; |
2
|
|
|
|
|
|
|
$Consul::API::KV::VERSION = '0.025'; |
3
|
9
|
|
|
9
|
|
5408
|
use namespace::autoclean; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
62
|
|
4
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
787
|
use Moo::Role; |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
60
|
|
6
|
9
|
|
|
9
|
|
3466
|
use Types::Standard qw(Str); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
68
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires qw(_version_prefix _api_exec); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has _kv_endpoint => ( is => 'lazy', isa => Str ); |
11
|
|
|
|
|
|
|
sub _build__kv_endpoint { |
12
|
0
|
|
|
0
|
|
|
shift->_version_prefix . '/kv'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub kv { |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
0
|
|
|
|
|
$self = Consul->new(@_) unless ref $self; |
18
|
0
|
|
|
|
|
|
return bless \$self, "Consul::API::KV::Impl"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package |
22
|
|
|
|
|
|
|
Consul::API::KV::Impl; # hide from PAUSE |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
9
|
|
6039
|
use Moo; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
55
|
|
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
9
|
|
3506
|
use Carp qw(croak); |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
5812
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, $key, %args) = @_; |
30
|
0
|
0
|
|
|
|
|
croak 'usage: $kv->get($key, [%args])' if grep { !defined } ($key); |
|
0
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, |
32
|
|
|
|
|
|
|
_valid_cb => sub { |
33
|
0
|
0
|
|
0
|
|
|
int($_[0]/100) == 2 || int($_[0]) == 404 |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
sub { |
36
|
0
|
0
|
|
0
|
|
|
return undef unless defined $_[0]; |
37
|
0
|
|
|
|
|
|
Consul::API::KV::Response->new($_[0]->[0]); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $key, %args) = @_; |
44
|
0
|
0
|
|
|
|
|
croak 'usage: $kv->get_all($key, [%args])' if grep { !defined } ($key); |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, |
46
|
|
|
|
|
|
|
recurse => 1, |
47
|
|
|
|
|
|
|
_valid_cb => sub { |
48
|
0
|
0
|
|
0
|
|
|
int($_[0]/100) == 2 || int($_[0]) == 404 |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
sub { |
51
|
0
|
0
|
|
0
|
|
|
return [] unless defined $_[0]; |
52
|
0
|
|
|
|
|
|
[ map { Consul::API::KV::Response->new($_) } @{$_[0]} ] |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub put { |
58
|
0
|
|
|
0
|
0
|
|
my ($self, $key, $value, %args) = @_; |
59
|
0
|
0
|
0
|
|
|
|
croak 'usage: $kv->put($key, $value, [%args])' unless defined($key) && @_ >= 3; |
60
|
0
|
|
|
|
|
|
$$self->_api_exec($$self->_kv_endpoint."/".$key, 'PUT', %args, _content => $value); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub delete { |
64
|
0
|
|
|
0
|
0
|
|
my ($self, $key, %args) = @_; |
65
|
0
|
0
|
|
|
|
|
croak 'usage: $kv->delete($key, [%args])' if grep { !defined } ($key); |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$$self->_api_exec($$self->_kv_endpoint."/".$key, 'DELETE', %args); |
67
|
0
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub keys { |
71
|
0
|
|
|
0
|
0
|
|
my ($self, $key, %args) = @_; |
72
|
0
|
0
|
|
|
|
|
croak 'usage: $kv->keys($key, [%args])' if grep { !defined } ($key); |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, keys => 1); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Consul::API::KV::Response; |
77
|
|
|
|
|
|
|
$Consul::API::KV::Response::VERSION = '0.025'; |
78
|
9
|
|
|
9
|
|
77
|
use Convert::Base64 qw(decode_base64); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
485
|
|
79
|
|
|
|
|
|
|
|
80
|
9
|
|
|
9
|
|
76
|
use Moo; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
69
|
|
81
|
9
|
|
|
9
|
|
3437
|
use Types::Standard qw(Str Int Maybe); |
|
9
|
|
|
|
|
39
|
|
|
9
|
|
|
|
|
62
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
has key => ( is => 'ro', isa => Str, init_arg => 'Key', required => 1 ); |
84
|
|
|
|
|
|
|
has value => ( is => 'ro', isa => Maybe[Str], init_arg => 'Value', required => 1, |
85
|
|
|
|
|
|
|
coerce => sub { !defined $_[0] ? undef : decode_base64($_[0]) }); |
86
|
|
|
|
|
|
|
has flags => ( is => 'ro', isa => Int, init_arg => 'Flags', required => 1 ); |
87
|
|
|
|
|
|
|
has session => ( is => 'ro', isa => Str, init_arg => 'Session' ); |
88
|
|
|
|
|
|
|
has create_index => ( is => 'ro', isa => Int, init_arg => 'CreateIndex', required => 1 ); |
89
|
|
|
|
|
|
|
has modify_index => ( is => 'ro', isa => Int, init_arg => 'ModifyIndex', required => 1 ); |
90
|
|
|
|
|
|
|
has lock_index => ( is => 'ro', isa => Int, init_arg => 'LockIndex', required => 1 ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding UTF-8 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Consul::API::KV - Key/value store API |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
use Consul; |
105
|
|
|
|
|
|
|
my $kv = Consul->kv; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The KV API is used to access Consul's simple key/value store, useful for storing service configuration or other metadata. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This API is fully documented at L. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 get |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 get_all |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 put |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 delete |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 keys |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |