Exobrain/Types.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Exobrain::Types;
2 use 5.010;
3 use strict;
4 use warnings;
5  
6 use JSON::Any;
7  
8 # ABSTRACT: Type system for Exobrain
9 our $VERSION = '1.08'; # VERSION
10  
11  
12 my $json = JSON::Any->new( allow_blessed => 1 );
13  
14 use MooseX::Types -declare => [qw(
15 JSON
16 POI
17 SmsStr
18 PhoneNum
19 Exobrain
20 PosNum
21 PosInt
22 TimeOut
23 )];
24  
25 use MooseX::Types::Moose qw(
26 HashRef
27 Ref
28 Str
29 Num
30 Int
31 );
32  
33 subtype JSON,
34 as Str,
35 where { $json->decode($_) }
36 ;
37  
38 coerce JSON,
39 from Ref,
40 via { $json->encode($_) }
41 ;
42  
43 subtype SmsStr,
44 as Str,
45 where { length($_) <= 160 }
46 ;
47  
48 # TODO: Properly define phone numbers
49 subtype PhoneNum,
50 as Str,
51 where { 1 },
52 ;
53  
54 subtype PosNum,
55 as Num,
56 where { $_ > 0 }
57 ;
58  
59 subtype PosInt,
60 as Int,
61 where { $_ > 0 }
62 ;
63  
64 subtype TimeOut,
65 as PosNum,
66 where { 1 },
67 ;
68  
69 class_type Exobrain, { class => 'Exobrain' } ;
70  
71 class_type POI,
72 { class => 'Exobrain::Measurement::Geo::POI' }
73 ;
74  
75 coerce POI,
76 from HashRef,
77 via { Exobrain::Measurement::Geo::POI->new(%$_) }
78 ;
79  
80 1;
81  
82 __END__