File Coverage

blib/lib/Consul/Service.pm
Criterion Covered Total %
statement 15 23 65.2
branch 0 16 0.0
condition 0 21 0.0
subroutine 5 8 62.5
pod 0 2 0.0
total 20 70 28.5


line stmt bran cond sub pod time code
1             package Consul::Service;
2             $Consul::Service::VERSION = '0.027';
3 9     9   58 use namespace::autoclean;
  9         14  
  9         67  
4              
5 9     9   785 use Moo;
  9         16  
  9         47  
6 9     9   2799 use Types::Standard qw(Str Int Bool ArrayRef);
  9         34  
  9         87  
7 9     9   7727 use Carp qw(croak);
  9         17  
  9         468  
8 9     9   63 use JSON::MaybeXS;
  9         29  
  9         3990  
9              
10             has name => ( is => 'ro', isa => Str, required => 1 );
11             has id => ( is => 'ro', isa => Str );
12             has address => ( is => 'ro', isa => Str );
13             has port => ( is => 'ro', isa => Int );
14             has tags => ( is => 'ro', isa => ArrayRef[Str], default => sub { [] } );
15             has script => ( is => 'ro', isa => Str );
16             has interval => ( is => 'ro', isa => Str );
17             has ttl => ( is => 'ro', isa => Str );
18             has enable_tag_override => ( is => 'ro', isa => Bool, default => sub { 0 } );
19              
20             sub BUILD {
21 0     0 0   my ($self) = @_;
22              
23 0           my $A = defined $self->script;
24 0           my $B = defined $self->interval;
25 0           my $C = defined $self->ttl;
26              
27 0 0 0       croak "Invalid check arguments, required: script, interval OR ttl"
      0        
      0        
      0        
      0        
      0        
      0        
28             unless (!$A && !$B && !$C) || ($A && $B && !$C) || (!$A && !$B && $C)
29             }
30              
31 0     0 0   sub to_json { shift->_json }
32             has _json => ( is => 'lazy', isa => Str );
33             sub _build__json {
34 0     0     my ($self) = @_;
35 0 0         encode_json({
    0          
    0          
    0          
    0          
    0          
    0          
36             Name => $self->name,
37             defined $self->id ? ( ID => $self->id ) : (),
38             defined $self->port ? ( Port => $self->port ) : (),
39             defined $self->address ? ( Address => $self->address ) : (),
40             Tags => $self->tags,
41             defined $self->script ? ( Script => $self->script ) : (),
42             defined $self->interval ? ( Interval => $self->interval ) : (),
43             defined $self->ttl ? ( TTL => $self->ttl ) : (),
44             EnableTagOverride => ($self->enable_tag_override ? \1 : \0),
45             });
46             }
47              
48             1;