line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
9
|
|
|
9
|
|
45
|
use utf8; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
38
|
|
2
|
|
|
|
|
|
|
package Net::Etcd::Watch; |
3
|
|
|
|
|
|
|
|
4
|
9
|
|
|
9
|
|
251
|
use strict; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
134
|
|
5
|
9
|
|
|
9
|
|
30
|
use warnings; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
146
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
30
|
use Moo; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
33
|
|
8
|
9
|
|
|
9
|
|
2170
|
use Types::Standard qw(Str Int Bool HashRef ArrayRef); |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
47
|
|
9
|
9
|
|
|
9
|
|
6658
|
use MIME::Base64; |
|
9
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
338
|
|
10
|
9
|
|
|
9
|
|
56
|
use Data::Dumper; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
335
|
|
11
|
9
|
|
|
9
|
|
42
|
use JSON; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
39
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Net::Etcd::Role::Actions'; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
9
|
|
877
|
use namespace::clean; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
42
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Net::Etcd::Watch |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.022'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Watch watches for events happening or that have happened. Both input and output are streams; |
28
|
|
|
|
|
|
|
the input stream is for creating and canceling watchers and the output stream sends events. |
29
|
|
|
|
|
|
|
One watch RPC can watch on multiple key ranges, streaming events for several watches at once. |
30
|
|
|
|
|
|
|
The entire event history can be watched starting from the last compaction revision. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 ACCESSORS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 endpoint |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has endpoint => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => Str, |
41
|
|
|
|
|
|
|
default => '/watch' |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 key |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
key is the first key for the range. If range_end is not given, the request only looks up key. |
47
|
|
|
|
|
|
|
the key is encoded with base64. type bytes |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has key => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
isa => Str, |
54
|
|
|
|
|
|
|
required => 1, |
55
|
|
|
|
|
|
|
coerce => sub { return encode_base64( $_[0], '' ) } |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 range_end |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
range_end is the end of the range [key, range_end) to watch. If range_end is not given, only |
61
|
|
|
|
|
|
|
the key argument is watched. If range_end is equal to '\0', all keys greater than or equal to |
62
|
|
|
|
|
|
|
the key argument are watched. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has range_end => ( |
67
|
|
|
|
|
|
|
is => 'ro', |
68
|
|
|
|
|
|
|
isa => Str, |
69
|
|
|
|
|
|
|
coerce => sub { return encode_base64( $_[0], '' ) } |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 start_revision |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
start_revision is an optional revision to watch from (inclusive). No start_revision is "now". |
75
|
|
|
|
|
|
|
int64 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has start_revision => ( |
80
|
|
|
|
|
|
|
is => 'ro', |
81
|
|
|
|
|
|
|
isa => Int, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 progress_notify |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
progress_notify is set so that the etcd server will periodically send a WatchResponse with no |
87
|
|
|
|
|
|
|
events to the new watcher if there are no recent events. It is useful when clients wish to recover |
88
|
|
|
|
|
|
|
a disconnected watcher starting from a recent known revision. The etcd server may decide how often |
89
|
|
|
|
|
|
|
it will send notifications based on current load. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has progress_notify => ( |
94
|
|
|
|
|
|
|
is => 'ro', |
95
|
|
|
|
|
|
|
isa => Bool, |
96
|
9
|
|
|
9
|
|
4107
|
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false } |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
797
|
|
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 filters |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
filter out put event. filter out delete event. filters filter the events at server side before it sends back to the watcher. |
102
|
|
|
|
|
|
|
Options: |
103
|
|
|
|
|
|
|
- NOPUT: filter out put event. (default) |
104
|
|
|
|
|
|
|
- NODELETE: filter out delete event. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
has filters => ( |
109
|
|
|
|
|
|
|
is => 'ro', |
110
|
|
|
|
|
|
|
isa => Str, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 prev_key |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
If prev_kv is set, created watcher gets the previous KV before the event happens. If the previous |
116
|
|
|
|
|
|
|
KV is already compacted, nothing will be returned. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
has prev_key => ( |
121
|
|
|
|
|
|
|
is => 'ro', |
122
|
|
|
|
|
|
|
isa => Bool, |
123
|
9
|
|
|
9
|
|
47
|
coerce => sub { no strict 'refs'; return $_[0] ? JSON::true : JSON::false } |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
1372
|
|
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 watch_id |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
watch_id is the watcher id to cancel so that no more events are transmitted. This is only used for a |
129
|
|
|
|
|
|
|
cancel request. |
130
|
|
|
|
|
|
|
int64 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
has watch_id => ( |
135
|
|
|
|
|
|
|
is => 'ro', |
136
|
|
|
|
|
|
|
isa => Int, |
137
|
|
|
|
|
|
|
); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 create |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
create watch |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub create { |
148
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
$self->{json_args} = '{"create_request": '. $self->json_args . '}'; |
150
|
0
|
|
|
|
|
|
$self->request; |
151
|
0
|
|
|
|
|
|
return $self; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 cancel |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
cancel watch |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub cancel { |
161
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
$self->{json_args} = '{"cancel_request": '. $self->json_args . '}'; |
163
|
0
|
|
|
|
|
|
$self->request; |
164
|
0
|
|
|
|
|
|
return $self; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |