File Coverage

blib/lib/Consul/API/Health.pm
Criterion Covered Total %
statement 30 62 48.3
branch 0 10 0.0
condition n/a
subroutine 10 20 50.0
pod 0 5 0.0
total 40 97 41.2


line stmt bran cond sub pod time code
1             package Consul::API::Health;
2             $Consul::API::Health::VERSION = '0.026';
3 9     9   4349 use namespace::autoclean;
  9         17  
  9         48  
4              
5 9     9   649 use Moo::Role;
  9         18  
  9         48  
6 9     9   2638 use Types::Standard qw(Str);
  9         24  
  9         77  
7              
8             requires qw(_version_prefix _api_exec);
9              
10             has _health_endpoint => ( is => 'lazy', isa => Str );
11             sub _build__health_endpoint {
12 0     0     shift->_version_prefix . '/health';
13             }
14              
15             sub health {
16 0     0 0   my $self = shift;
17 0 0         $self = Consul->new(@_) unless ref $self;
18 0           return bless \$self, "Consul::API::Health::Impl";
19             }
20              
21             package
22             Consul::API::Health::Impl; # hide from PAUSE
23              
24 9     9   4726 use Moo;
  9         16  
  9         42  
25              
26 9     9   2624 use Carp qw(croak);
  9         34  
  9         4474  
27              
28             sub node {
29 0     0 0   my ($self, $node, %args) = @_;
30 0 0         croak 'usage: $health->node($node, [%args])' if grep { !defined } ($node);
  0            
31             $$self->_api_exec($$self->_health_endpoint."/node/".$node, 'GET', %args, sub {
32 0     0     [ map { Consul::API::Health::Check->new(%$_) } @{$_[0]} ]
  0            
  0            
33 0           });
34             }
35              
36             sub checks {
37 0     0 0   my ($self, $service, %args) = @_;
38 0 0         croak 'usage: $health->checks($service, [%args])' if grep { !defined } ($service);
  0            
39             $$self->_api_exec($$self->_health_endpoint."/checks/".$service, 'GET', %args, sub {
40 0     0     [ map { Consul::API::Health::Check->new(%$_) } @{$_[0]} ]
  0            
  0            
41 0           });
42             }
43              
44             sub service {
45 0     0 0   my ($self, $service, %args) = @_;
46 0 0         croak 'usage: $health->service($service, [%args])' if grep { !defined } ($service);
  0            
47             $$self->_api_exec($$self->_health_endpoint."/service/".$service, 'GET', %args, sub {
48 0     0     [ map { Consul::API::Health::Service->new(%$_) } @{$_[0]} ]
  0            
  0            
49 0           });
50             }
51              
52             sub state {
53 0     0 0   my ($self, $state, %args) = @_;
54 0 0         croak 'usage: $health->state($state, [%args])' if grep { !defined } ($state);
  0            
55             $$self->_api_exec($$self->_health_endpoint."/state/".$state, 'GET', %args, sub {
56 0     0     [ map { Consul::API::Health::Check->new(%$_) } @{$_[0]} ]
  0            
  0            
57 0           });
58             }
59              
60             package Consul::API::Health::Check;
61             $Consul::API::Health::Check::VERSION = '0.026';
62 9     9   61 use Moo;
  9         19  
  9         84  
63 9     9   2640 use Types::Standard qw(Str);
  9         13  
  9         42  
64              
65             has node => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 );
66             has id => ( is => 'ro', isa => Str, init_arg => 'CheckID', required => 1 );
67             has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 );
68             has status => ( is => 'ro', isa => Str, init_arg => 'Status', required => 1 );
69             has notes => ( is => 'ro', isa => Str, init_arg => 'Notes', required => 1 );
70             has output => ( is => 'ro', isa => Str, init_arg => 'Output', required => 1 );
71             has service_id => ( is => 'ro', isa => Str, init_arg => 'ServiceID', required => 1 );
72             has service_name => ( is => 'ro', isa => Str, init_arg => 'ServiceName', required => 1 );
73              
74             package Consul::API::Health::Service;
75             $Consul::API::Health::Service::VERSION = '0.026';
76 9     9   4889 use Moo;
  9         15  
  9         33  
77 9     9   2556 use Types::Standard qw(ArrayRef);
  9         19  
  9         52  
78 9     9   3674 use Type::Utils qw(class_type);
  9         16  
  9         44  
79              
80             has node => ( is => 'ro', isa => class_type('Consul::API::Catalog::ShortNode'), init_arg => 'Node', required => 1, coerce => sub { Consul::API::Catalog::ShortNode->new($_[0]) } );
81             has service => ( is => 'ro', isa => class_type('Consul::API::Agent::Service'), init_arg => 'Service', required => 1, coerce => sub { Consul::API::Agent::Service->new($_[0]) } );
82             has checks => ( is => 'ro', isa => ArrayRef[class_type('Consul::API::Health::Check')], init_arg => 'Checks', required => 1, coerce => sub { [ map { Consul::API::Health::Check->new($_) } @{$_[0]} ] } );
83              
84             1;
85              
86             =pod
87              
88             =encoding UTF-8
89              
90             =head1 NAME
91              
92             Consul::API::Health - Health check API
93              
94             =head1 SYNOPSIS
95              
96             use Consul;
97             my $health = Consul->health;
98              
99             =head1 DESCRIPTION
100              
101             The Health API is used to query health-related information.
102              
103             This API is fully documented at L.
104              
105             =head1 METHODS
106              
107             =head2 node
108              
109             =head2 checks
110              
111             =head2 service
112              
113             =head2 state
114              
115             =head1 SEE ALSO
116              
117             L
118              
119             =cut