File Coverage

blib/lib/Etcd/Node.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Etcd::Node;
2             $Etcd::Node::VERSION = '0.004';
3 5     5   15584 use namespace::autoclean;
  5         14216  
  5         27  
4              
5 5     5   840 use Moo;
  5         7545  
  5         26  
6 5     5   2696 use Type::Tiny;
  5         15635  
  5         127  
7 5     5   710 use Types::Standard qw(Int Str Bool ArrayRef);
  5         38453  
  5         38  
8 5     5   4256 use Type::Utils qw(class_type);
  5         4054  
  5         42  
9              
10             # http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
11             my $ISO8601 = do {
12             my $iso8601_re = qr{^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$};
13             Type::Tiny->new(
14             name => "ISO8601",
15             constraint => sub { m/$iso8601_re/ },
16             inlined => sub { "$_[1] =~ m/$iso8601_re/" },
17             );
18             };
19              
20             has key => ( is => 'ro', isa => Str, required => 1 );
21             has value => ( is => 'ro', isa => Str );
22             has created_index => ( is => 'ro', isa => Int, init_arg => 'createdIndex' );
23             has modified_index => ( is => 'ro', isa => Int, init_arg => 'modifiedIndex' );
24             has ttl => ( is => 'ro', isa => Int );
25             has expiration => ( is => 'ro', isa => $ISO8601 );
26             has dir => ( is => 'ro', isa => Bool, coerce => sub { !! $_[0] } );
27              
28             has nodes => (
29             is => 'ro',
30             isa => ArrayRef[class_type('Etcd::Node')],
31             coerce => sub { ref $_[0] eq "ARRAY" ? [ map { Etcd::Node->new(%$_) } @{$_[0]} ] : $_[0] }
32             );
33              
34             1;
35              
36             __END__