line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Consul; |
2
|
|
|
|
|
|
|
$AnyEvent::Consul::VERSION = '0.003'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Make async calls to Consul via AnyEvent |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
237871
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
123
|
|
6
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
68
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2152
|
use Consul; |
|
3
|
|
|
|
|
833035
|
|
|
3
|
|
|
|
|
125
|
|
9
|
3
|
|
|
3
|
|
3203
|
use AnyEvent::HTTP qw(http_request); |
|
3
|
|
|
|
|
90067
|
|
|
3
|
|
|
|
|
274
|
|
10
|
3
|
|
|
3
|
|
34
|
use Hash::MultiValue; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1234
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
shift; |
14
|
|
|
|
|
|
|
Consul->new(@_, request_cb => sub { |
15
|
0
|
|
|
0
|
|
|
my ($self, $method, $url, $headers, $content, $cb) = @_; |
16
|
|
|
|
|
|
|
http_request($method, $url, |
17
|
|
|
|
|
|
|
body => $content, |
18
|
|
|
|
|
|
|
headers => $headers->as_hashref, |
19
|
|
|
|
|
|
|
timeout => $self->timeout, |
20
|
|
|
|
|
|
|
sub { |
21
|
0
|
|
|
|
|
|
my ($rdata, $rheaders) = @_; |
22
|
0
|
|
|
|
|
|
my $rstatus = $rheaders->{Status}; |
23
|
0
|
|
|
|
|
|
my $rreason = $rheaders->{Reason}; |
24
|
0
|
|
|
|
|
|
delete $rheaders->{$_} for grep { m/^[A-Z]/ } keys %$rheaders; |
|
0
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$cb->($rstatus, $rreason, Hash::MultiValue->from_mixed($rheaders), $rdata); |
26
|
|
|
|
|
|
|
}, |
27
|
0
|
|
|
|
|
|
); |
28
|
0
|
|
|
|
|
|
return; |
29
|
0
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
0
|
|
sub acl { shift->new(@_)->acl } |
33
|
0
|
|
|
0
|
0
|
|
sub agent { shift->new(@_)->agent } |
34
|
0
|
|
|
0
|
0
|
|
sub catalog { shift->new(@_)->catalog } |
35
|
0
|
|
|
0
|
0
|
|
sub event { shift->new(@_)->event } |
36
|
0
|
|
|
0
|
0
|
|
sub health { shift->new(@_)->health } |
37
|
0
|
|
|
0
|
0
|
|
sub kv { shift->new(@_)->kv } |
38
|
0
|
|
|
0
|
0
|
|
sub session { shift->new(@_)->session } |
39
|
0
|
|
|
0
|
0
|
|
sub status { shift->new(@_)->status } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=encoding UTF-8 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
AnyEvent::Consul - Make async calls to Consul via AnyEvent |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use AnyEvent; |
54
|
|
|
|
|
|
|
use AnyEvent::Consul; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $cv = AE::cv; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $kv = AnyEvent::Consul->kv; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# do some blocking op to discover the current index |
61
|
|
|
|
|
|
|
$kv->get("mykey", cb => sub { |
62
|
|
|
|
|
|
|
my ($v, $meta) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# now set up a long-poll to watch a key we're interested in |
65
|
|
|
|
|
|
|
$kv->get("mykey", index => $meta->index, cb => sub { |
66
|
|
|
|
|
|
|
my ($v, $meta) = @_; |
67
|
|
|
|
|
|
|
say "mykey changed to ".$v->value; |
68
|
|
|
|
|
|
|
$cv->send; |
69
|
|
|
|
|
|
|
}); |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# make the change |
73
|
|
|
|
|
|
|
$kv->put("mykey" => "newval"); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$cv->recv; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
AnyEvent::Consul is a thin wrapper around L to connect it to |
80
|
|
|
|
|
|
|
L for asynchronous operation. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
It takes the same arguments and methods as L itself, so see the |
83
|
|
|
|
|
|
|
documentation for that module for details. The important difference is that you |
84
|
|
|
|
|
|
|
must pass the C option to the endpoint methods to enable their asynchronous |
85
|
|
|
|
|
|
|
mode. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SUPPORT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 Bugs / Feature Requests |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Please report any bugs or feature requests through the issue tracker |
92
|
|
|
|
|
|
|
at L. |
93
|
|
|
|
|
|
|
You will be notified automatically of any progress on your issue. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 Source Code |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This is open source software. The code repository is available for |
98
|
|
|
|
|
|
|
public review and contribution under the terms of the license. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
git clone https://github.com/robn/AnyEvent-Consul.git |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHORS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Robert Norris |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Robert Norris. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |