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.002';
3 4     4   15 use namespace::sweep;
  4         7  
  4         18  
4              
5 4     4   172 use Moo;
  4         5  
  4         19  
6 4     4   1024 use Type::Tiny;
  4         6  
  4         98  
7 4     4   18 use Types::Standard qw(Int Str Bool ArrayRef);
  4         6  
  4         28  
8 4     4   2680 use Type::Utils qw(class_type);
  4         5  
  4         17  
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 );
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__