Etcd/Watch.pm

filter: Statementstmt 78.5% 44 / 56 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 100% 2 / 2 totaltotal 72.1% 57 / 79 SCAR 11.5
CC
3
Cov
73%
__ANON__
2.5
__ANON__
2.5
__ANON__
2.0
CRAP 3.2
« Etcd/KV/Op.pm ↑ Summary Etcd/KV/Compare.pm »
1 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Net::Etcd::Watch;
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 MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Data::Dumper;
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::Watch
20  
21 =cut
22  
23 9 our $VERSION = '0.021';
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 9 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 0 ▶ coerce => sub { return encode_base64( $_[0], '' ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 9 );
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 0 ▶ coerce => sub { return encode_base64( $_[0], '' ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 9 );
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 9 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 ▶ 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
97 9 );
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 9 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 ▶ 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
124 9 );
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 9 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 ▶ my $self = shift;
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my $self = shift;
Subroutine cancel: not called CC=1 SCAR=6.9
Pod documented
162 0 $self->{json_args} = '{"cancel_request": '. $self->json_args . '}';
163 0 $self->request;
164 0 return $self;
165 }
166  
167 9 1;
« Etcd/KV/Op.pm ↑ Summary Etcd/KV/Compare.pm »