| 1 | package Consul::API::Event; | ||||||||||
| 2 | 9 | $Consul::API::Event::VERSION = '0.027'; | |||||||||
| 3 | 9 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 9 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use Types::Standard qw(Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 9 | requires qw(_version_prefix _api_exec); | |||||||||
| 9 | |||||||||||
| 10 | 9 | has _event_endpoint => ( is => 'lazy', isa => Str ); | |||||||||
| 11 | 0 | ▶ | sub _build__event_endpoint { | ||||||||
|
Subroutine
_build__event_endpoint: not called CC=1 SCAR=6.9
| |||||||||||
| 12 | 0 | shift->_version_prefix . '/event'; | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub event { | ||||||||
|
Subroutine
event: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 16 | 0 | my $self = shift; | |||||||||
| 17 | 0 | ▶ | $self = Consul->new(@_) unless ref $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 0 | return bless \$self, "Consul::API::Event::Impl"; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | package | ||||||||||
| 22 | Consul::API::Event::Impl; # hide from PAUSE | ||||||||||
| 23 | |||||||||||
| 24 | 9 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 9 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub fire { | ||||||||
|
Subroutine
fire: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 29 | 0 | my ($self, $name, %args) = @_; | |||||||||
| 30 | 0 | ▶ | croak 'usage: $event->fire($name, [%args])' if grep { !defined } ($name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | my $payload = delete $args{payload}; | |||||||||
| 32 | 0 | ▶ | $$self->_api_exec($$self->_event_endpoint."/fire/".$name, 'PUT', %args, ($payload ? (_content => $payload) : ()), sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | Consul::API::Event::Event->new($_[0]) | |||||||||
| 34 | 0 | ▶ | }); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub list { | ||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 38 | 0 | my ($self, %args) = @_; | |||||||||
| 39 | 0 | ▶ | $$self->_api_exec($$self->_event_endpoint."/list", 'GET', %args, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 40 | 0 | [ map { Consul::API::Event::Event->new(%$_) } @{$_[0]} ] | |||||||||
| 41 | 0 | }); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | package Consul::API::Event::Event; | ||||||||||
| 45 | 9 | $Consul::API::Event::Event::VERSION = '0.027'; | |||||||||
| 46 | 9 | ▶ | use Convert::Base64 qw(decode_base64); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | |||||||||||
| 48 | 9 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 9 | ▶ | use Types::Standard qw(Str Int Maybe); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | |||||||||||
| 51 | 9 | has id => ( is => 'ro', isa => Str, init_arg => 'ID', required => 1 ); | |||||||||
| 52 | 9 | has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 ); | |||||||||
| 53 | 0 | ▶ | has payload => ( is => 'ro', isa => Maybe[Str], init_arg => 'Payload', required => 1, coerce => sub { defined $_[0] ? decode_base64($_[0]) : undef}); | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||
| 54 | 9 | has node_filter => ( is => 'ro', isa => Str, init_arg => 'NodeFilter', required => 1 ); | |||||||||
| 55 | 9 | has service_filter => ( is => 'ro', isa => Str, init_arg => 'ServiceFilter', required => 1 ); | |||||||||
| 56 | 9 | has tag_filter => ( is => 'ro', isa => Str, init_arg => 'TagFilter', required => 1 ); | |||||||||
| 57 | 9 | has version => ( is => 'ro', isa => Int, init_arg => 'Version', required => 1 ); | |||||||||
| 58 | 9 | has l_time => ( is => 'ro', isa => Int, init_arg => 'LTime', required => 1 ); | |||||||||
| 59 | |||||||||||
| 60 | 9 | 1; | |||||||||
| 61 | |||||||||||
| 62 | =pod | ||||||||||
| 63 | |||||||||||
| 64 | =encoding UTF-8 | ||||||||||
| 65 | |||||||||||
| 66 | =head1 NAME | ||||||||||
| 67 | |||||||||||
| 68 | Consul::API::Event - User event API | ||||||||||
| 69 | |||||||||||
| 70 | =head1 SYNOPSIS | ||||||||||
| 71 | |||||||||||
| 72 | use Consul; | ||||||||||
| 73 | my $event = Consul->event; | ||||||||||
| 74 | |||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||
| 76 | |||||||||||
| 77 | The Event API is used to fire new events and to query the available events. | ||||||||||
| 78 | |||||||||||
| 79 | This API is fully documented at L<https://www.consul.io/docs/agent/http/event.html>. | ||||||||||
| 80 | |||||||||||
| 81 | =head1 METHODS | ||||||||||
| 82 | |||||||||||
| 83 | =head2 fire | ||||||||||
| 84 | |||||||||||
| 85 | =head2 list | ||||||||||
| 86 | |||||||||||
| 87 | =head1 SEE ALSO | ||||||||||
| 88 | |||||||||||
| 89 | L<Consul> | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||