blib/lib/InterMine/Model/Types.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 64 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package InterMine::Model::Types;
2  
3  
4 # Declare Our Own Types
5 use MooseX::Types -declare => [
6 qw(
7 ISO8601DateStamp
8  
9 JoinedPathString PathString PathList PathHash
10  
11 Model
12  
13 ClassDescriptor ClassDescriptorList MaybeClassDescriptor
14  
15 Field FieldList MaybeField FieldHash
16  
17 BigInt
18 )
19 ];
20  
21 use MooseX::Types::Moose qw/Str Bool Object ArrayRef HashRef Maybe/;
22 use Math::BigInt;
23  
24 # FOR INTERNAL USE
25  
26 subtype ISO8601DateStamp, as Str,
27 where {/
28 \d{4} - (0[1-9]|1[012]) - (1[1-9]|2[0-9]|3[0-1])
29 T
30 ([01][0-9]|2[0-4]) : [0-5][0-9] : [0-5][0-9]
31 /x},
32 message {"Value provided ('$_') was not in the ISO8601 time stamp format"};
33  
34 coerce Bool, from Object, via {$$_};
35  
36 # MODEL
37  
38 class_type Model, { class => 'InterMine::Model', };
39 coerce Model, from Str, via {
40 require InterMine::Model;
41 InterMine::Model->new( string => $_ );
42 };
43  
44 # CLASSES
45  
46 class_type ClassDescriptor,
47 { class => 'InterMine::Model::ClassDescriptor', };
48 subtype MaybeClassDescriptor, as Maybe [ClassDescriptor];
49 subtype ClassDescriptorList, as ArrayRef [ClassDescriptor];
50  
51 # FIELDS
52  
53 role_type Field, { role => 'InterMine::Model::Role::Field', };
54 subtype MaybeField, as Maybe[Field];
55 subtype FieldList, as ArrayRef[Field];
56 subtype FieldHash, as HashRef[Field];
57  
58 # PATH
59  
60 my $path_re = qr/([[:alnum:]_]+\.)*[[:alnum:]_]+/;
61 subtype JoinedPathString, as Str, where { /^ ( $path_re (,?\s*|\s+) )+ $path_re $/x };
62 subtype PathString,
63 as Str, where { /^$path_re$/ },
64 message {
65 (defined)
66 ? "PathString can only contain 'A-Z', '0-9', '_' and '.', not '$_'"
67 : "PathString must be defined";
68 };
69 subtype PathList, as ArrayRef [PathString];
70 subtype PathHash, as HashRef [PathString];
71 coerce PathList, from JoinedPathString, via { [ split /[,\s]+/ ] };
72 coerce PathString, from JoinedPathString,
73 via { ( split /[\s]+/ )[0] };
74 coerce PathString, from ClassDescriptor, via { "$_" };
75  
76 # Attribute values
77  
78 class_type BigInt, {class => "Math::BigInt"};
79  
80 coerce BigInt, from Str, via {
81 my $coerced = Math::BigInt->new($_);
82 if ($coerced->is_nan) {
83 return $_; # We almost certainly failed here...
84 } else {
85 return $coerced;
86 }
87 };
88  
89 1;
90  
91 =head1 NAME
92  
93 InterMine::Model::Types - types used by InterMine::Model or its subclasses.
94  
95 =head1 SYNOPSIS
96  
97 use Moose;
98 use InterMine::Model::Types qw(ISO8601DateStamp);
99  
100 has time_stamp => (
101 isa => ISO8601DateStamp,
102 is => 'rw',
103 );
104
105 ...
106  
107 =head1 DESCRIPTION
108  
109 A MooseX::Types type library. Not for direct external use.
110  
111 =head1 AUTHOR
112  
113 FlyMine C<< <support@flymine.org> >>
114  
115 =head1 BUGS
116  
117 Please report any bugs or feature requests to C<support@flymine.org>.
118  
119 =head1 SUPPORT
120  
121 You can find documentation for this module with the perldoc command.
122  
123 perldoc InterMine::Model::Types
124  
125 You can also look for information at:
126  
127 =over 4
128  
129 =item * FlyMine
130  
131 L<http://www.flymine.org>
132  
133 =back
134  
135 =head1 COPYRIGHT & LICENSE
136  
137 Copyright 2006,2007,2008,2009 FlyMine, all rights reserved.
138  
139 This program is free software; you can redistribute it and/or modify it
140 under the same terms as Perl itself.
141