File Coverage

blib/lib/Etcd/Response.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package Etcd::Response;
2             $Etcd::Response::VERSION = '0.004';
3 4     4   19 use namespace::autoclean;
  4         5  
  4         20  
4              
5 4     4   1688 use Etcd::Node;
  4         13  
  4         148  
6              
7 4     4   2230 use JSON qw(decode_json);
  4         33700  
  4         20  
8              
9 4     4   632 use Moo;
  4         8  
  4         23  
10 4     4   1178 use Type::Utils qw(class_type);
  4         5  
  4         30  
11 4     4   1374 use Types::Standard qw(Str Int);
  4         8  
  4         26  
12              
13             has action => ( is => 'ro', isa => Str, required => 1 );
14             has etcd_index => ( is => 'ro', isa => Int, required => 1 );
15             has raft_index => ( is => 'ro', isa => Int, required => 1 );
16             has raft_term => ( is => 'ro', isa => Int, required => 1 );
17              
18             my $node_coercion = sub { ref $_[0] eq 'HASH' ? Etcd::Node->new(%{$_[0]}) : $_[0] };
19             has node => ( is => 'ro', isa => class_type('Etcd::Node'), coerce => $node_coercion, required => 1 );
20             has prev_node => ( is => 'ro', isa => class_type('Etcd::Node'), coerce => $node_coercion, init_arg => 'prevNode' );
21              
22             sub new_from_http {
23 5     5 0 8 my ($class, $res) = @_;
24 5         60 my $data = decode_json($res->{content});
25 5         7 my %headers;
26 5         11 @headers{qw(etcd_index raft_index raft_term)} = @{$res->{headers}}{qw(x-etcd-index x-raft-index x-raft-term)};
  5         25  
27 5         66 $class->new(%$data, %headers);
28             }
29              
30             1;
31              
32             __END__