line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
28
|
use utf8; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
27
|
|
2
|
|
|
|
|
|
|
package Etcd3::Lease; |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
166
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
82
|
|
5
|
5
|
|
|
5
|
|
19
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
101
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
18
|
use Moo; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
23
|
|
8
|
5
|
|
|
5
|
|
1434
|
use Types::Standard qw(Str Int Bool HashRef ArrayRef); |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
36
|
|
9
|
5
|
|
|
5
|
|
4635
|
use Data::Dumper; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
210
|
|
10
|
5
|
|
|
5
|
|
25
|
use Carp; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
226
|
|
11
|
5
|
|
|
5
|
|
23
|
use JSON; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
27
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Etcd3::Role::Actions'; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
471
|
use namespace::clean; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
32
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Etcd3::Lease |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
coerce => sub { return $_[0]; }, |
62
|
|
|
|
|
|
|
); |
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
|
5
|
|
|
5
|
|
2249
|
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false } |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1191
|
|
74
|
|
|
|
|
|
|
); |
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({ name =>'foo' password => 'bar' })->grant |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub grant { |
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
$self->{endpoint} = '/lease/grant'; |
92
|
|
|
|
|
|
|
confess 'TTL and ID are required for ' . __PACKAGE__ . '->grant' |
93
|
0
|
0
|
0
|
|
|
|
unless ($self->{ID} && $self->{TTL}); |
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
|
|
|
0
|
1
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
$self->{endpoint} = '/kv/lease/revoke'; |
109
|
|
|
|
|
|
|
confess 'ID is required for ' . __PACKAGE__ . '->revoke' |
110
|
0
|
0
|
|
|
|
|
unless $self->{ID}; |
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
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
$self->{endpoint} = '/kv/lease/timetolive'; |
126
|
|
|
|
|
|
|
confess 'ID is required for ' . __PACKAGE__ . '->ttl' |
127
|
0
|
0
|
|
|
|
|
unless $self->{ID}; |
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
|
|
|
0
|
1
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
$self->{endpoint} = '/lease/keepalive'; |
145
|
|
|
|
|
|
|
confess 'ID is required for ' . __PACKAGE__ . '->keepalive' |
146
|
0
|
0
|
|
|
|
|
unless $self->{ID}; |
147
|
0
|
|
|
|
|
|
$self->request; |
148
|
0
|
|
|
|
|
|
return $self; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |