File Coverage

blib/lib/WebService/SlimTimer/Types.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             # ABSTRACT: Defines Moose types used by WebService::SlimTimer.
2              
3             package WebService::SlimTimer::Types;
4              
5 4     4   3391 use DateTime::Format::RFC3339;
  4         184377  
  4         139  
6 4     4   44 use Moose::Util::TypeConstraints;
  4         30  
  4         62  
7              
8 4     4   8162 use MooseX::Types -declare => [qw(TimeStamp OptionalTimeStamp)];
  4         7  
  4         53  
9 4     4   25763 use MooseX::Types::Moose qw(Str Maybe);
  4         10  
  4         48  
10              
11             sub _DateTime_from_YAML
12             {
13             # For some reason we have we get spaces between the date and time parts as
14             # well as before the time zone in the data returned by SlimTimer and we
15             # need to get rid of them before parsing as otherwise it fails.
16 15     15   53 s/ /T/; s/ //; DateTime::Format::RFC3339->parse_datetime($_)
  15         44  
  15         161  
17             }
18              
19             class_type TimeStamp, { class => 'DateTime' };
20             coerce TimeStamp,
21             from Str,
22             via { _DateTime_from_YAML($_) };
23              
24             subtype OptionalTimeStamp, as Maybe[TimeStamp];
25             coerce OptionalTimeStamp,
26             from Str,
27             via { defined $_ ? _DateTime_from_YAML($_) : undef };
28              
29              
30             __END__
31             =pod
32              
33             =head1 NAME
34              
35             WebService::SlimTimer::Types - Defines Moose types used by WebService::SlimTimer.
36              
37             =head1 VERSION
38              
39             version 0.005
40              
41             =head1 AUTHOR
42              
43             Vadim Zeitlin <vz-cpan@zeitlins.org>
44              
45             =head1 COPYRIGHT AND LICENSE
46              
47             This software is copyright (c) 2011 by Vadim Zeitlin.
48              
49             This is free software; you can redistribute it and/or modify it under
50             the same terms as the Perl 5 programming language system itself.
51              
52             =cut
53