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.003';
3 4     4   16 use namespace::sweep;
  4         6  
  4         19  
4              
5 4     4   1403 use Etcd::Node;
  4         8  
  4         139  
6              
7 4     4   1795 use JSON qw(decode_json);
  4         26425  
  4         21  
8              
9 4     4   614 use Moo;
  4         7  
  4         22  
10 4     4   988 use Type::Utils qw(class_type);
  4         7  
  4         23  
11 4     4   1059 use Types::Standard qw(Str Int);
  4         4  
  4         22  
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         41 my $data = decode_json($res->{content});
25 5         7 my %headers;
26 5         9 @headers{qw(etcd_index raft_index raft_term)} = @{$res->{headers}}{qw(x-etcd-index x-raft-index x-raft-term)};
  5         20  
27 5         61 $class->new(%$data, %headers);
28             }
29              
30             1;
31              
32             __END__