| 1 | package Consul::API::KV; | ||||||||||||||||||||||||||||
| 2 | 9 | $Consul::API::KV::VERSION = '0.027'; | |||||||||||||||||||||||||||
| 3 | 9 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Types::Standard qw(Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | requires qw(_version_prefix _api_exec); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 9 | has _kv_endpoint => ( is => 'lazy', isa => Str ); | |||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub _build__kv_endpoint { | ||||||||||||||||||||||||||
|
Subroutine
_build__kv_endpoint: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 12 | 0 | shift->_version_prefix . '/kv'; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub kv { | ||||||||||||||||||||||||||
|
Subroutine
kv: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | $self = Consul->new(@_) unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | return bless \$self, "Consul::API::KV::Impl"; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package | ||||||||||||||||||||||||||||
| 22 | Consul::API::KV::Impl; # hide from PAUSE | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $key, %args) = @_; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | croak 'usage: $kv->get($key, [%args])' if grep { !defined } ($key); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | $$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | _valid_cb => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | int($_[0]/100) == 2 || int($_[0]) == 404 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | Consul::API::KV::Response->new($_[0]->[0]); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | ); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub get_all { | ||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self, $key, %args) = @_; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | croak 'usage: $kv->get_all($key, [%args])' if grep { !defined } ($key); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | $$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, | ||||||||||||||||||||||||||||
| 46 | recurse => 1, | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | _valid_cb => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | int($_[0]/100) == 2 || int($_[0]) == 404 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return [] unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | [ map { Consul::API::KV::Response->new($_) } @{$_[0]} ] | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub put { | ||||||||||||||||||||||||||
|
Subroutine
put: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | my ($self, $key, $value, %args) = @_; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | croak 'usage: $kv->put($key, $value, [%args])' unless defined($key) && @_ >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and @_ >= 3
MC/DC0%0/2
defined $key and @_ >= 3
defined $key
@_ >= 3
Truth table0%0/3
A and B
A= defined $keyB= @_ >= 3
| |||||||||||||||||||||||||||||
| 60 | 0 | $$self->_api_exec($$self->_kv_endpoint."/".$key, 'PUT', %args, _content => $value); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self, $key, %args) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | croak 'usage: $kv->delete($key, [%args])' if grep { !defined } ($key); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $$self->_api_exec($$self->_kv_endpoint."/".$key, 'DELETE', %args); | |||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub keys { | ||||||||||||||||||||||||||
|
Subroutine
keys: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | my ($self, $key, %args) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | croak 'usage: $kv->keys($key, [%args])' if grep { !defined } ($key); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $$self->_api_exec($$self->_kv_endpoint."/".$key, 'GET', %args, keys => 1); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | package Consul::API::KV::Response; | ||||||||||||||||||||||||||||
| 77 | 9 | $Consul::API::KV::Response::VERSION = '0.027'; | |||||||||||||||||||||||||||
| 78 | 9 | ▶ | use Convert::Base64 qw(decode_base64); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 9 | ▶ | use Types::Standard qw(Str Int Maybe); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 9 | 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 | 0 | ▶ | coerce => sub { !defined $_[0] ? undef : decode_base64($_[0]) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 9 | has flags => ( is => 'ro', isa => Int, init_arg => 'Flags', required => 1 ); | |||||||||||||||||||||||||||
| 87 | 9 | has session => ( is => 'ro', isa => Str, init_arg => 'Session' ); | |||||||||||||||||||||||||||
| 88 | 9 | has create_index => ( is => 'ro', isa => Int, init_arg => 'CreateIndex', required => 1 ); | |||||||||||||||||||||||||||
| 89 | 9 | has modify_index => ( is => 'ro', isa => Int, init_arg => 'ModifyIndex', required => 1 ); | |||||||||||||||||||||||||||
| 90 | 9 | has lock_index => ( is => 'ro', isa => Int, init_arg => 'LockIndex', required => 1 ); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 9 | 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<https://www.consul.io/docs/agent/http/kv.html>. | ||||||||||||||||||||||||||||
| 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<Consul> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||||||||