PRANG/XMLSchema/Types.pm

filter: Statementstmt 61.2% 49 / 80 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 19.3% 6 / 31 Podpod n/a totaltotal 39.2% 55 / 140 CC 14 SCAR 18.8
CC
14
Cov
46%
__ANON__
30.0
__ANON__
6.0
__ANON__
6.0
CRAP 6.6
« PRANG/Util.pm ↑ Summary PRANG/Graph/Quantity.pm »
1  
2 package PRANG::XMLSchema::Types;
3 8 $PRANG::XMLSchema::Types::VERSION = '0.21';
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 subtype "PRANG::XMLSchema::normalizedString"
9 => as "Str"
10 0 ▶ => where { !m{[\n\r\t]} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12 subtype "PRANG::XMLSchema::token"
13 => as "Str"
14 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 !m{[\t\r\n]|^\s|\s$|\s\s};
16 8 };
17  
18 # automatically trim tokens if passed them.
19 coerce "PRANG::XMLSchema::token"
20 => from "Str",
21 0 ▶ => via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my ($x) = m/\A\s*(.*?)\s*\Z/;
23 0 $x =~ s{\s+}{ }g;
24 0 $x;
25 },
26 8 ;
27  
28 # See https://rt.cpan.org/Ticket/Display.html?id=52309
29 # use Regexp::Common qw/URI/;
30 subtype "PRANG::XMLSchema::anyURI"
31 => as "Str"
32 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 m{^\w+:\S+$}; # validate using this instead
34 8 };
35  
36 8 ▶use I18N::LangTags qw(is_language_tag);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 subtype "PRANG::XMLSchema::language"
38 => as "Str"
39 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 is_language_tag($_);
41 8 };
42  
43 subtype "PRANG::XMLSchema::dateTime"
44 => as "Str"
45 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46  
47 # from the XMLSchema spec... it'll do for now ;)
48 # how on earth is one supposed to encode Pacific/Guam
49 # or Pacific/Saipan dates before 1845 with this regex?
50 0 m{
51 ^
52 -?([1-9][0-9]{3,}|0[0-9]{3})
53 -(0[1-9]|1[0-2])
54 -(0[1-9]|[12][0-9]|3[01])
55 T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))
56 (?:Z|(?:\+|-)(?:(?:0[0-9]|1[0-3]):[0-5][0-9]|14:00))?
57 $
58 }x;
59 8 };
60  
61 subtype "PRANG::XMLSchema::time"
62 => as "Str"
63 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
64  
65 # from the XMLSchema spec... it'll do for now ;)
66 0 m{
67 ^
68 (([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))
69 (?:Z|(?:\+|-)(?:(?:0[0-9]|1[0-3]):[0-5][0-9]|14:00))?
70 $
71 }x;
72 8 };
73  
74 subtype "PRANG::XMLSchema::date"
75 => as "Str"
76 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
77  
78 # from the XMLSchema spec... it'll do for now ;)
79 # XXX: Note, since the XML Spec bizarrely has Timezones on Dates,
80 # we have chosen to ignore it (since it is optional anyway)
81 0 m{
82 ^
83 -?([1-9][0-9]{3,}|0[0-9]{3})
84 -(0[1-9]|1[0-2])
85 -(0[1-9]|[12][0-9]|3[01])
86 $
87 }x;
88 8 };
89  
90 subtype "PRANG::XMLSchema::duration"
91 => as "Str"
92 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 m{^\s* (?: [pP]? \s* )?
94 (?: C \s* \d+)?
95 (?: Y \s* \d+)?
96 (?: M \s* \d+)?
97 (?: D \s* \d+)?
98 (?: h \s* \d+)?
99 (?: m \s* \d+)?
100 (?: s \s* \d+(?:\.\d+) )? \s* $}x;
101 8 };
102  
103 # other built-in primitive datatypes.
104 8 subtype "PRANG::XMLSchema::string"
105 => as "Str";
106 subtype "PRANG::XMLSchema::boolean"
107 => as "Str"
108 6 ▶ => where {
Subroutine __ANON__: called CC=1 SCAR=0.0
109 6 m/^(?:0|1|true|false)$/;
110 8 };
111 coerce "Bool"
112 => from 'PRANG::XMLSchema::boolean'
113 0 ▶ => via { m{1|true} ? 1 : 0 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
/1|true/ ? : 0 0 0
114 8 subtype "PRANG::XMLSchema::decimal"
115 => as "Num";
116  
117 # floating point stuff...
118 subtype "PRANG::XMLSchema::float"
119 => as "Str"
120 4 ▶ => where {
Subroutine __ANON__: called CC=1 SCAR=0.0
121 4 m{^(?:[\-+]?(?:\d+(?:\.\d*)?(?:e[\-+]?(\d+))?|inf)|NaN)$}i;
122 8 };
123 8 our $inf = exp(~0 >> 1);
124 8 our $nan = $inf / $inf;
125 8 our $neg_inf = -$inf;
126 coerce "Num"
127 => from 'PRANG::XMLSchema::float'
128 0 ▶ => via {
Subroutine __ANON__: not called CC=5 SCAR=34.0
129 0 m{^(?:([\-+])?inf|(nan)|(.))};
130 0 ▶ return eval $_ if defined $3;
Branch: 1 branch
BranchTrueFalseTotal
if defined $3 0 0 0
131 0 ▶ return $nan if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 0 0 0
132 0 ▶ return $neg_inf if $1 and $1 eq "-";
Branch: 1 branch
BranchTrueFalseTotal
if $1 and $1 eq "-" 0 0 0
Condition0%0/3
$1 and $1 eq "-"
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and $1 eq "-"
$1 $1 eq "-"
Truth table0%0/3
A and B
A= $1B= $1 eq "-"
ABresult
0X0
100
111
133 0 return $inf;
134 8 };
135  
136 8 if ( 0.1 == 0.100000000000000006 ) {
137 8 subtype "PRANG::XMLSchema::double"
138 => as "PRANG::XMLSchema::float";
139 }
140 else {
141 subtype "PRANG::XMLSchema::double"
142 => as "PRANG::XMLSchema::float"
143 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 0 unpack('d',pack('d',$_))==$_;
145 };
146  
147 coerce "PRANG::XMLSchema::double"
148 => from "PRANG::XMLSchema::float"
149 0 ▶ => via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 0 unpack('d',pack('d',$_));
151 };
152 }
153  
154 # built-in derived types.
155 # this sub-typing might seem unnecessarily deep, but that's what the
156 # spec says... see http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#built-in-derived
157 8 subtype "PRANG::XMLSchema::integer"
158 => as "Int";
159 subtype "PRANG::XMLSchema::nonPositiveInteger"
160 => as "PRANG::XMLSchema::integer"
161 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
162 0 $_ <= 0;
163 8 };
164 subtype "PRANG::XMLSchema::negativeInteger"
165 => as "PRANG::XMLSchema::nonPositiveInteger"
166 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
167 0 $_ <= -1;
168 8 };
169 subtype "PRANG::XMLSchema::nonNegativeInteger"
170 => as "PRANG::XMLSchema::integer"
171 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 0 $_ >= 0;
173 8 };
174 subtype "PRANG::XMLSchema::positiveInteger"
175 => as "PRANG::XMLSchema::nonNegativeInteger"
176 0 ▶ => where {
Subroutine __ANON__: not called CC=1 SCAR=6.9
177 0 $_ >= 1;
178 8 };
179 subtype "PRANG::XMLSchema::long"
180 => as "PRANG::XMLSchema::integer"
181 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
182 0 ▶ $_ >= -9223372036854775808 and $_ <= 9223372036854775807;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= '-9223372036854775808' and $_ <= '9223372036854775807' 0 0 0
183 8 };
184 subtype "PRANG::XMLSchema::int"
185 => as "PRANG::XMLSchema::long"
186 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
187 0 ▶ $_ >= -2147483648 and $_ <= 2147483647;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= '-2147483648' and $_ <= 2147483647 0 0 0
188 8 };
189 subtype "PRANG::XMLSchema::short"
190 => as "PRANG::XMLSchema::int"
191 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
192 0 ▶ $_ >= -32768 and $_ <= 32767;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= -32768 and $_ <= 32767 0 0 0
193 8 };
194 subtype "PRANG::XMLSchema::byte"
195 => as "PRANG::XMLSchema::short"
196 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
197 0 ▶ $_ >= -128 and $_ <= 127;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= -128 and $_ <= 127 0 0 0
198 8 };
199 subtype "PRANG::XMLSchema::unsignedLong"
200 => as "PRANG::XMLSchema::nonNegativeInteger"
201 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
202 0 ▶ $_ >= 0 and $_ < 18446744073709551615;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ < '18446744073709551615' 0 0 0
203 8 };
204 subtype "PRANG::XMLSchema::unsignedInt"
205 => as "PRANG::XMLSchema::unsignedLong"
206 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
207 0 ▶ $_ >= 0 and $_ < 2147483647;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ < 2147483647 0 0 0
208 8 };
209 subtype "PRANG::XMLSchema::unsignedShort"
210 => as "PRANG::XMLSchema::unsignedInt"
211 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
212 0 ▶ $_ >= 0 and $_ < 65536;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ < 65536 0 0 0
213 8 };
214 subtype "PRANG::XMLSchema::unsignedByte"
215 => as "PRANG::XMLSchema::unsignedShort"
216 0 ▶ => where {
Subroutine __ANON__: not called CC=2 SCAR=17.9
217 0 ▶ $_ >= 0 and $_ < 256;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ < 256 0 0 0
218 8 };
219  
220 8 1;
221  
222 =head1 NAME
223  
224 PRANG::XMLSchema::Types - type registry for XML Schema-related types
225  
226 =head1 SYNOPSIS
227  
228 package My::Class;
229 use Moose;
230 use PRANG::Graph;
231 use PRANG::XMLSchema::Types;
232  
233 has_attr 'foo' =>
234 is => "ro",
235 isa => "PRANG::XMLSchema::unsignedShort",
236 ;
237  
238 =head1 DESCRIPTION
239  
240 This module is a collection of types which make working with XML
241 Schema specifications easier. See the source for the complete list.
242  
243 These might be moved into a separate namespace, but if you include
244 this module you will get aliases for wherever these XML Schema types
245 end up.
246  
247 =head1 SEE ALSO
248  
249 L<PRANG>, L<PRANG::Graph::Meta::Attr>, L<PRANG::Graph::Meta::Element>
250  
251 =head1 AUTHOR AND LICENCE
252  
253 Development commissioned by NZ Registry Services, and carried out by
254 Catalyst IT - L<http://www.catalyst.net.nz/>
255  
256 Copyright 2009, 2010, NZ Registry Services. This module is licensed
257 under the Artistic License v2.0, which permits relicensing under other
258 Free Software licenses.
259  
260 =cut
261  
« PRANG/Util.pm ↑ Summary PRANG/Graph/Quantity.pm »