File Coverage

blib/lib/Etcd3/Range.pm
Criterion Covered Total %
statement 33 43 76.7
branch 0 2 0.0
condition n/a
subroutine 11 13 84.6
pod 1 1 100.0
total 45 59 76.2


line stmt bran cond sub pod time code
1 4     4   14 use utf8;
  4         3  
  4         15  
2             package Etcd3::Range;
3              
4 4     4   119 use strict;
  4         3  
  4         60  
5 4     4   11 use warnings;
  4         8  
  4         86  
6              
7 4     4   11 use Moo;
  4         5  
  4         13  
8 4     4   710 use Types::Standard qw(Str Int Bool HashRef ArrayRef);
  4         4  
  4         18  
9 4     4   2072 use MIME::Base64;
  4         4  
  4         158  
10 4     4   13 use JSON;
  4         4  
  4         14  
11              
12             with 'Etcd3::Role::Actions';
13              
14 4     4   333 use namespace::clean;
  4         4  
  4         20  
15              
16             =head1 NAME
17              
18             Etcd3::Range
19              
20             =cut
21              
22             our $VERSION = '0.005';
23              
24             =head1 DESCRIPTION
25              
26             Range gets the keys in the range from the key-value store.
27              
28             =head2 endpoint
29              
30             =cut
31              
32             has endpoint => (
33             is => 'ro',
34             isa => Str,
35             default => '/kv/range'
36             );
37              
38             =head2 key
39              
40             key is the first key for the range. If range_end is not given, the request only looks up key.
41             the key is encoded with base64. type bytes
42              
43             =cut
44              
45             has key => (
46             is => 'ro',
47             isa => Str,
48             required => 1,
49             coerce => sub { return encode_base64( $_[0], '' ) }
50             );
51              
52             =head2 range_end
53              
54             range_end is the upper bound on the requested range [key, range_end). If range_end is '\0',
55             the range is all keys >= key. If the range_end is one bit larger than the given key, then
56             the range requests get the all keys with the prefix (the given key). If both key and
57             range_end are '\0', then range requests returns all keys. the key is encoded with base64.
58             type bytes. NOTE: If range_end is not given, the request only looks up key.
59              
60             =cut
61              
62             has range_end => (
63             is => 'ro',
64             isa => Str,
65             coerce => sub { return encode_base64( $_[0], '' ) }
66             );
67              
68             =head2 limit
69              
70             limit is a limit on the number of keys returned for the request. type int64
71              
72             =cut
73              
74             has limit => (
75             is => 'ro',
76             isa => Int,
77             );
78              
79             =head2 revision
80              
81             revision is the point-in-time of the key-value store to use for
82             the range. If revision is less or equal to zero, the range is over
83             the newest key-value store. If the revision has been compacted,
84             ErrCompaction is returned as a response. type int64
85              
86             =cut
87              
88             has revision => (
89             is => 'ro',
90             isa => Int,
91             );
92              
93             =head2 sort_order
94              
95             sort_order is the order for returned sorted results.
96              
97             =cut
98              
99             has sort_order => (
100             is => 'ro',
101             isa => Int,
102             );
103              
104             =head2 sort_target
105              
106             sort_target is the key-value field to use for sorting.
107              
108             =cut
109              
110             has sort_target => (
111             is => 'ro',
112             isa => Str,
113             );
114              
115             =head2 serializable
116              
117             serializable sets the range request to use serializable member-local reads.
118             Range requests are linearizable by default; linearizable requests have higher
119             latency and lower throughput than serializable requests but reflect the current
120             consensus of the cluster. For better performance, in exchange for possible stale
121             reads, a serializable range request is served locally without needing to reach
122             consensus with other nodes in the cluster.
123              
124             =cut
125              
126             has serializable => (
127             is => 'ro',
128             isa => Bool,
129 4     4   1629 coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
  4         4  
  4         255  
130             );
131              
132             =head2 keys_only
133              
134             keys_only when set returns only the keys and not the values.
135              
136             =cut
137              
138             has keys_only => (
139             is => 'ro',
140             isa => Bool,
141 4     4   15 coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
  4         4  
  4         204  
142             );
143              
144             =head2 count_only
145              
146             count_only when set returns only the count of the keys in the range.
147              
148             =cut
149              
150             has count_only => (
151             is => 'ro',
152             isa => Bool,
153 4     4   12 coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
  4         4  
  4         866  
154             );
155              
156             =head2 min_mod_revision
157              
158             min_mod_revision is the lower bound for returned key mod revisions;
159             all keys with lesser mod revisions will be filtered away.
160              
161             =cut
162              
163             has min_mod_revision => (
164             is => 'ro',
165             isa => Int,
166             );
167              
168             =head2 max_mod_revision
169              
170             max_mod_revision is the upper bound for returned key mod revisions;
171             all keys with greater mod revisions will be filtered away.
172              
173             =cut
174              
175             has max_mod_revision => (
176             is => 'ro',
177             isa => Int,
178             );
179              
180             =head2 min_create_revision
181              
182             min_create_revision is the lower bound for returned key create revisions;
183             all keys with lesser create revisions will be filtered away.
184              
185             =cut
186              
187             has min_create_revision => (
188             is => 'ro',
189             isa => Int,
190             );
191              
192             =head2 max_create_revision
193              
194             max_create_revision is the upper bound for returned key create revisions;
195             all keys with greater create revisions will be filtered away.
196              
197             =cut
198              
199             has max_create_revision => (
200             is => 'ro',
201             isa => Int,
202             );
203              
204             =head2 json_args
205              
206             arguments that will be sent to the api
207              
208             =cut
209              
210             has json_args => ( is => 'lazy', );
211              
212             sub _build_json_args {
213 0     0     my ($self) = @_;
214 0           my $args;
215 0           for my $key ( keys %{$self} ) {
  0            
216 0 0         unless ( $key =~ /(?:_client|args|endpoint)$/ ) {
217 0           $args->{$key} = $self->{$key};
218             }
219             }
220 0           return to_json($args);
221             }
222              
223             =head2 init
224              
225             =cut
226              
227             sub init {
228 0     0 1   my ($self) = @_;
229 0           $self->json_args;
230 0           return $self;
231             }
232             1;