Etcd/Lease.pm

filter: Statementstmt 57.8% 37 / 64 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.8% 10 / 17 Podpod 100% 5 / 5 totaltotal 51.4% 52 / 101 SCAR 26.3
CC
7
Cov
48%
grant
12.0
revoke
6.0
ttl
6.0
CRAP 13.9
« Etcd/Maintenance.pm ↑ Summary Etcd/KV/Txn.pm »
1 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Net::Etcd::Lease;
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 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Types::Standard qw(Str Int Bool HashRef ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 with 'Net::Etcd::Role::Actions';
14  
15 9 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Net::Etcd::Lease
20  
21 =cut
22  
23 9 our $VERSION = '0.020';
24  
25 =head1 DESCRIPTION
26  
27 LeaseGrant creates a lease which expires if the server does not receive a keepAlive within
28 a given time to live period. All keys attached to the lease will be expired and deleted if
29 the lease expires. Each expired key generates a delete event in the event history.
30  
31 =head1 ACCESSORS
32  
33 =head2 endpoint
34  
35 =cut
36  
37 9 has endpoint => (
38 is => 'rwp',
39 isa => Str,
40 );
41  
42 =head2 TTL
43  
44 TTL is the advisory time-to-live in seconds.
45  
46 =cut
47  
48 9 has TTL => (
49 is => 'ro',
50 isa => Str,
51 );
52  
53 =head2 ID
54  
55 ID is the requested ID for the lease. If ID is set to 0, the lessor chooses an ID.
56  
57 =cut
58  
59 has ID => (
60 is => 'ro',
61 0 ▶ coerce => sub { return $_[0]; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 9 );
63  
64 =head2 keys
65  
66 keys is true to query all the keys attached to this lease.
67  
68 =cut
69  
70 has keys => (
71 is => 'ro',
72 isa => Bool,
73 9 ▶ coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false }
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
74 9 );
75  
76 =head1 PUBLIC METHODS
77  
78 =head2 grant
79  
80 LeaseGrant creates a lease which expires if the server does not receive a keepAlive within
81 a given time to live period. All keys attached to the lease will be expired and deleted if
82 the lease expires. Each expired key generates a delete event in the event history.
83  
84  
85 $etcd->lease({ ID => 7587821338341002662, TTL => 20 })->grant
86  
87 =cut
88  
89 sub grant {
90 0 ▶ my $self = shift;
Subroutine grant: not called CC=3 SCAR=24.8
Pod documented
91 0 $self->{endpoint} = '/lease/grant';
92 confess 'TTL and ID are required for ' . __PACKAGE__ . '->grant'
93 0 ▶ unless ($self->{ID} && $self->{TTL});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ID"} and $self->{"TTL"} 0 0 0
Condition0%0/3
$self->{"ID"} and $self->{"TTL"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"ID"} and $self->{"TTL"}
$self->{"ID"} $self->{"TTL"}
Truth table0%0/3
A and B
A= $self->{"ID"}B= $self->{"TTL"}
ABresult
0X0
100
111
94 0 $self->request;
95 0 return $self;
96 }
97  
98 =head2 revoke
99  
100 LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted.
101  
102 $etcd->lease({{ ID => 7587821338341002662 })->revoke
103  
104 =cut
105  
106 sub revoke {
107 0 ▶ my $self = shift;
Subroutine revoke: not called CC=2 SCAR=17.9
Pod documented
108 0 $self->{endpoint} = '/kv/lease/revoke';
109 confess 'ID is required for ' . __PACKAGE__ . '->revoke'
110 0 ▶ unless $self->{ID};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ID"} 0 0 0
111 0 $self->request;
112 0 return $self;
113 }
114  
115 =head2 ttl
116  
117 LeaseTimeToLive retrieves lease information.
118  
119 $etcd->lease({{ ID => 7587821338341002662, keys => 1 })->ttl
120  
121 =cut
122  
123 sub ttl {
124 0 ▶ my $self = shift;
Subroutine ttl: not called CC=2 SCAR=17.9
Pod documented
125 0 $self->{endpoint} = '/kv/lease/timetolive';
126 confess 'ID is required for ' . __PACKAGE__ . '->ttl'
127 0 ▶ unless $self->{ID};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ID"} 0 0 0
128 0 $self->request;
129 0 return $self;
130 }
131  
132  
133 =head2 keepalive
134  
135 LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client
136 to the server and streaming keep alive responses from the server to the client."
137  
138 $etcd->lease({{ ID => 7587821338341002662 })->keepalive
139  
140 =cut
141  
142 sub keepalive {
143 0 ▶ my $self = shift;
Subroutine keepalive: not called CC=2 SCAR=17.9
Pod documented
144 0 $self->{endpoint} = '/lease/keepalive';
145 confess 'ID is required for ' . __PACKAGE__ . '->keepalive'
146 0 ▶ unless $self->{ID};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ID"} 0 0 0
147 0 $self->request;
148 0 return $self;
149 }
150  
151 =head2 leases
152 lists all existing leases.
153  
154 $etcd->lease()->leases
155  
156 =cut
157  
158 sub leases {
159 0 ▶ my $self = shift;
Subroutine leases: not called CC=1 SCAR=6.9
Pod documented
160 0 $self->{endpoint} = '/kv/lease/leases';
161 0 $self->{json_args} = '{}';
162 0 $self->request;
163 0 return $self;
164 }
165  
166 9 1;
« Etcd/Maintenance.pm ↑ Summary Etcd/KV/Txn.pm »