| 1 | 9 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | package Net::Etcd::KV; | ||||||||||
| 3 | |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =encoding utf8 | ||||||||||
| 8 | |||||||||||
| 9 | =cut | ||||||||||
| 10 | 9 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 9 | ▶ | use Types::Standard qw(Str Int Bool HashRef ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 9 | ▶ | use Net::Etcd::KV::Put; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 9 | ▶ | use Net::Etcd::KV::Range; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 9 | ▶ | use Net::Etcd::KV::DeleteRange; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 9 | ▶ | use Net::Etcd::KV::Txn; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 9 | ▶ | use Net::Etcd::KV::Op; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 9 | ▶ | use Net::Etcd::KV::Compare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 9 | with 'Net::Etcd::Role::Actions'; | |||||||||
| 20 | 9 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | =head1 NAME | ||||||||||
| 23 | |||||||||||
| 24 | Net::Etcd::KV | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | 9 | our $VERSION = '0.021'; | |||||||||
| 29 | |||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||
| 31 | |||||||||||
| 32 | Key Value role providing easy access to Put and Range classes | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | =head1 PUBLIC METHODS | ||||||||||
| 37 | |||||||||||
| 38 | =head2 range | ||||||||||
| 39 | |||||||||||
| 40 | Range gets the keys in the range from the key-value store. | ||||||||||
| 41 | |||||||||||
| 42 | # get range | ||||||||||
| 43 | $etcd->range({key =>'test0', range_end => 'test100'}) | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | sub range { | ||||||||||
| 48 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
range: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 49 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | my $range = Net::Etcd::KV::Range->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | endpoint => '/kv/range', | ||||||||||
| 52 | etcd => $self, | ||||||||||
| 53 | cb => $cb, | ||||||||||
| 54 | ( $options ? %$options : () ), | ||||||||||
| 55 | ); | ||||||||||
| 56 | 0 | ▶ | $range->request unless $range->hold; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | return $range | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | =head2 deleterange | ||||||||||
| 61 | |||||||||||
| 62 | DeleteRange deletes the given range from the key-value store. A delete | ||||||||||
| 63 | request increments the revision of the key-value store and generates a | ||||||||||
| 64 | delete event in the event history for every deleted key. | ||||||||||
| 65 | |||||||||||
| 66 | $etcd->deleterange({key => 'test0'}) | ||||||||||
| 67 | |||||||||||
| 68 | =cut | ||||||||||
| 69 | |||||||||||
| 70 | sub deleterange { | ||||||||||
| 71 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
deleterange: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 72 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | ▶ | my $delete_range = Net::Etcd::KV::DeleteRange->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | endpoint => '/kv/deleterange', | ||||||||||
| 75 | etcd => $self, | ||||||||||
| 76 | cb => $cb, | ||||||||||
| 77 | ( $options ? %$options : () ), | ||||||||||
| 78 | ); | ||||||||||
| 79 | 0 | ▶ | $delete_range->request unless $delete_range->hold; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | return $delete_range; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | =head2 put | ||||||||||
| 84 | |||||||||||
| 85 | Put puts the given key into the key-value store. A put request increments | ||||||||||
| 86 | the revision of the key-value store and generates one event in the event | ||||||||||
| 87 | history. | ||||||||||
| 88 | |||||||||||
| 89 | $etcd->put({key =>'test0', value=> 'bar'}) | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | sub put { | ||||||||||
| 94 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
put: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 95 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | ▶ | my $put = Net::Etcd::KV::Put->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | endpoint => '/kv/put', | ||||||||||
| 98 | etcd => $self, | ||||||||||
| 99 | cb => $cb, | ||||||||||
| 100 | ( $options ? %$options : () ), | ||||||||||
| 101 | ); | ||||||||||
| 102 | 0 | ▶ | $put->request unless $put->hold; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | return $put; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | =head2 txn | ||||||||||
| 107 | |||||||||||
| 108 | Txn processes multiple requests in a single transaction. A txn request increments | ||||||||||
| 109 | the revision of the key-value store and generates events with the same revision for | ||||||||||
| 110 | every completed request. It is not allowed to modify the same key several times | ||||||||||
| 111 | within one txn. | ||||||||||
| 112 | |||||||||||
| 113 | =cut | ||||||||||
| 114 | |||||||||||
| 115 | sub txn { | ||||||||||
| 116 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
txn: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 117 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | ▶ | my $txn = Net::Etcd::KV::Txn->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | %$self, | ||||||||||
| 120 | endpoint => '/kv/txn', | ||||||||||
| 121 | etcd => $self, | ||||||||||
| 122 | cb => $cb, | ||||||||||
| 123 | ( $options ? %$options : () ), | ||||||||||
| 124 | ); | ||||||||||
| 125 | 0 | return $txn->create; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | =head2 op | ||||||||||
| 129 | |||||||||||
| 130 | =cut | ||||||||||
| 131 | |||||||||||
| 132 | sub op { | ||||||||||
| 133 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
op: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 134 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | 0 | ▶ | my $op = Net::Etcd::KV::Op->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | %$self, | ||||||||||
| 137 | ( $options ? %$options : () ), | ||||||||||
| 138 | ); | ||||||||||
| 139 | 0 | return $op->create; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | =head2 compare | ||||||||||
| 143 | |||||||||||
| 144 | =cut | ||||||||||
| 145 | |||||||||||
| 146 | sub compare { | ||||||||||
| 147 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||
|
Subroutine
compare: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 148 | 0 | ▶ | my $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | ▶ | my $cmp = Net::Etcd::KV::Compare->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | %$self, | ||||||||||
| 151 | ( $options ? %$options : () ), | ||||||||||
| 152 | ); | ||||||||||
| 153 | 0 | return $cmp->json_args; | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | 9 | 1; | |||||||||