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