Consul/API/Catalog.pm

filter: Statementstmt 62.7% 54 / 86 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 12 / 27 Podpod 0.0% 0 / 8 totaltotal 51.1% 66 / 129 CC 5 SCAR 9.0
CC
5
Cov
57%
catalog
6.0
service
6.0
node
6.0
CRAP 2.4
« Consul.pm ↑ Summary Consul/API/Status.pm »
1 package Consul::API::Catalog;
2 9 $Consul::API::Catalog::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 _catalog_endpoint => ( is => 'lazy', isa => Str );
11 0 ▶sub _build__catalog_endpoint {
Subroutine _build__catalog_endpoint: not called CC=1 SCAR=6.9
12 0 shift->_version_prefix . '/catalog';
13 }
14  
15 0 ▶sub catalog {
Subroutine catalog: 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
BranchTrueFalseTotal
unless ref $self 0 0 0
18 0 return bless \$self, "Consul::API::Catalog::Impl";
19 }
20  
21 package
22 Consul::API::Catalog::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 datacenters {
Subroutine datacenters: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my ($self, %args) = @_;
30 0 $$self->_api_exec($$self->_catalog_endpoint."/datacenters", 'GET', %args);
31 }
32  
33 0 ▶sub nodes {
Subroutine nodes: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my ($self, %args) = @_;
35 0 ▶ $$self->_api_exec($$self->_catalog_endpoint."/nodes", 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 [ map { Consul::API::Catalog::ShortNode->new(%$_) } @{$_[0]} ]
37 0 });
38 }
39  
40 0 ▶sub services {
Subroutine services: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my ($self, %args) = @_;
42 0 $$self->_api_exec($$self->_catalog_endpoint."/services", 'GET', %args);
43 }
44  
45 0 ▶sub service {
Subroutine service: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my ($self, $service, %args) = @_;
47 0 ▶ croak 'usage: $catalog->service($service, [%args])' if grep { !defined } ($service);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $service 0 0 0
48 0 ▶ $$self->_api_exec($$self->_catalog_endpoint."/service/".$service, 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 [ map { Consul::API::Catalog::Service->new(%$_) } @{$_[0]} ]
50 0 });
51 }
52  
53 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
54 # register
55 0 croak "not yet implemented";
56 }
57  
58 0 ▶sub deregister {
Subroutine deregister: not called CC=1 SCAR=6.9
Pod undocumented
59 # deregister
60 0 croak "not yet implemented";
61 }
62  
63 0 ▶sub node {
Subroutine node: not called CC=2 SCAR=17.9
Pod undocumented
64 0 my ($self, $node, %args) = @_;
65 0 ▶ croak 'usage: $catalog->node($node, [%args])' if grep { !defined } ($node);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $node 0 0 0
66 0 ▶ $$self->_api_exec($$self->_catalog_endpoint."/node/".$node, 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 Consul::API::Catalog::Node->new($_[0])
68 0 });
69 }
70  
71 package Consul::API::Catalog::ShortNode;
72 9 $Consul::API::Catalog::ShortNode::VERSION = '0.027';
73 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 9 ▶use Types::Standard qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 9 has name => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 );
77 9 has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 );
78  
79 package Consul::API::Catalog::Service;
80 9 $Consul::API::Catalog::Service::VERSION = '0.027';
81 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 9 ▶use Types::Standard qw(Str Int ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 9 has name => ( is => 'ro', isa => Str, init_arg => 'ServiceName', required => 1 );
85 9 has id => ( is => 'ro', isa => Str, init_arg => 'ServiceID', required => 1 );
86 9 has service_address => ( is => 'ro', isa => Str, init_arg => 'ServiceAddress', required => 1 );
87 9 has port => ( is => 'ro', isa => Int, init_arg => 'ServicePort', required => 1 );
88 9 has node => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 );
89 9 has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 );
90 0 ▶has tags => ( is => 'ro', isa => ArrayRef[Str], init_arg => 'ServiceTags', required => 1, coerce => sub { $_[0] || [] } );
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or [] 0 0 0
91  
92 package Consul::API::Catalog::Node;
93 9 $Consul::API::Catalog::Node::VERSION = '0.027';
94 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 9 ▶use Types::Standard qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
96 9 ▶use Type::Utils qw(class_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 0 ▶has node => ( is => 'ro', isa => class_type('Consul::API::Catalog::ShortNode'), init_arg => 'Node', required => 1, coerce => sub { Consul::API::Catalog::ShortNode->new($_[0]) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
99 0 ▶has services => ( is => 'ro', isa => HashRef[class_type('Consul::API::Agent::Service')], init_arg => 'Services', required => 1, coerce => sub { +{ map { $_ => Consul::API::Agent::Service->new($_[0]->{$_}) } keys %{$_[0]} } } );
Subroutine __ANON__: not called CC=1 SCAR=3.5
100  
101 9 1;
102  
103 =pod
104  
105 =encoding UTF-8
106  
107 =head1 NAME
108  
109 Consul::API::Catalog - Catalog (nodes and services) API
110  
111 =head1 SYNOPSIS
112  
113 use Consul;
114 my $catalog = Consul->catalog;
115 say for map { $_->name} @{$catalog->nodes};
116  
117 =head1 DESCRIPTION
118  
119 The catalog API is used to register and deregister nodes, services and checks.
120 It also provides query endpoints.
121  
122 This API is fully documented at L<https://www.consul.io/docs/agent/http/catalog.html>.
123  
124 =head1 METHODS
125  
126 =head2 datacenters
127  
128 =head2 nodes
129  
130 =head2 services
131  
132 =head2 service
133  
134 =head2 register
135  
136 =head2 deregister
137  
138 =head2 node
139  
140 =head1 SEE ALSO
141  
142 L<Consul>
143  
144 =cut
« Consul.pm ↑ Summary Consul/API/Status.pm »