lib/XML/Schema/Type/Builtin.pm

filter: Statementstmt 97.3% 440 / 452 Branchbran 85.3% 70 / 82 Conditioncond 100% 48 / 48 MC/DCmcdc 100% 25 / 25 Subroutinesub 93.1% 109 / 117 Podpod n/a totaltotal 95.5% 692 / 724 CC 60 SCAR 14.0
CC
60
Cov
96%
prepare
16.0
prepare
14.0
prepare
4.0
CRAP 4.1
« lib/XML/Schema/Factory.pm ↑ Summary lib/XML/Schema/Handler/Simple.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Type::Builtin
4 #
5 # DESCRIPTION
6 # Definitions of the various simple types built in to XML Schema.
7 #
8 # AUTHOR
9 # Andy Wardley <abw@kfs.org>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
13 # All Rights Reserved.
14 #
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
17 #
18 # REVISION
19 # $Id: Builtin.pm,v 1.2 2001/12/20 13:26:27 abw Exp $
20 #
21 # TODO
22 # Not yet implemented
23 # * uriReference - consult RFC 2396 and RFC 2732
24 # * ID - should access document instance to store ID usage
25 # * IDREF - should access document instance to check ID exists
26 # * IDREFS - as above, and requires list functionality
27 # * ENTITY - should access document instance to check ENTITY declared
28 # * ENTITIES - as above, and requires list functionality
29 # * NMTOKENS - requires list
30 # * NOTATION - need document instance to check NOTATION defined
31 #
32 # Incomplete:
33 # * float/double - need validation of mantissa length
34 # * long/unsignedLong - can't validate numbers which exceed bounds
35 # * QName - needs namespace resolution against prefix
36 #
37 #========================================================================
38  
39 package XML::Schema::Type::Builtin;
40  
41 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 28 ▶use XML::Schema::Type::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 28 ▶use vars qw( $VERSION $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 28 $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
46 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Type::Builtin::DEBUG 28 0 28
47  
48  
49 #========================================================================
50 # Primitive datatypes
51 #
52 # Based on XML Schema Part 2: Datatypes, W3C Candidate Recommendation,
53 # 24 October 2000, section 3.2.
54 #========================================================================
55  
56 #------------------------------------------------------------------------
57 # string
58 #------------------------------------------------------------------------
59  
60 package XML::Schema::Type::string;
61 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
62 28 ▶use vars qw( $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64  
65 #------------------------------------------------------------------------
66 # boolean
67 #------------------------------------------------------------------------
68  
69 package XML::Schema::Type::boolean;
70 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
71 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 28 @FACETS = (
74 whiteSpace => 'collapse',
75 enumeration => {
76 value => [ 'true', 'false' ],
77 errmsg => 'value is not boolean (true/false)',
78 },
79 );
80  
81  
82 #------------------------------------------------------------------------
83 # double
84 # IEEE double precision 64-bit floating point number.
85 #------------------------------------------------------------------------
86  
87 package XML::Schema::Type::double;
88 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
89 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 28 @FACETS = (
92 whiteSpace => 'collapse',
93 \&prepare,
94 );
95  
96 27 ▶sub prepare {
Subroutine prepare: called CC=14 SCAR=26.4
97 27 my ($instance, $type) = @_;
98 27 my $value = $instance->{ value };
99  
100 27 ▶ return $type->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 3 24 27
101 unless length $value;
102  
103 24 ▶ return $type->error("value is not a valid $type->{ name }")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([+-])? # sign ($1) (?: (INF) # infinity ($2) | (NaN) # not a number ($3) | (\d+(?:\.\d+)?) # mantissa ($4) (?:[eE] # exponent ([+-])? # sign ($5) (\d+) # value ($6) )? ) $ /x 5 19 24
104 unless $value =~ /
105 ^
106 ([+-])? # sign ($1)
107 (?:
108 (INF) # infinity ($2)
109 | (NaN) # not a number ($3)
110 | (\d+(?:\.\d+)?) # mantissa ($4)
111 (?:[eE] # exponent
112 ([+-])? # sign ($5)
113 (\d+) # value ($6)
114 )?
115 )
116 $
117 /x;
118  
119 19 ▶ $instance->{ sign } = $1 || '';
Condition100%2/2
$1 || ''
l!l
415
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
120 19 ▶ $instance->{ infinity } = $2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 2 17 19
121 19 ▶ $instance->{ nan } = $3 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 2 17 19
122 19 ▶ $instance->{ mantissa } = $4 || '';
Condition100%2/2
$4 || ''
l!l
154
MC/DC100%1/1
$4 || ''
$4
Truth table100%2/2
A
A= $4
Aresult
11
00
123 19 ▶ $instance->{ exp_sign } = $5 || '';
Condition100%2/2
$5 || ''
l!l
613
MC/DC100%1/1
$5 || ''
$5
Truth table100%2/2
A
A= $5
Aresult
11
00
124 19 ▶ $instance->{ exp_value } = $6 || '';
Condition100%2/2
$6 || ''
l!l
127
MC/DC100%1/1
$6 || ''
$6
Truth table100%2/2
A
A= $6
Aresult
11
00
125 19 ▶ $instance->{ exponent } = ($5 || '') . ($6 || '');
Condition100%4/4
$5 || ''
l!l
613
$6 || ''
l!l
127
MC/DC100%1/1
$5 || ''
$5
MC/DC100%1/1
$6 || ''
$6
Truth table100%2/2
A
A= $5
Aresult
11
00
Truth table100%2/2
A
A= $6
Aresult
11
00
126  
127 # TODO: need to test bounds of mantissa ( < 2^53 )
128  
129 19 my $exp = $instance->{ exponent };
130 19 ▶ return $type->error('double exponent is not valid (-1075 <= e <= 970)')
Branch: 1 branch
BranchTrueFalseTotal
if $exp and $exp < -1075 || $exp > 970 2 17 19
Condition100%6/6
$exp and $exp < -1075 || $exp > 970
!ll&&!rl&&r
7102
$exp < -1075 or $exp > 970
l!l&&r!l&&!r
1110
MC/DC100%3/3
$exp and $exp < -1075 || $exp > 970
$exp $exp < -1075 $exp > 970
Truth table100%4/4
A and B or C
A= $expB= $exp < -1075C= $exp > 970
ABCresult
0XX0
1000
11X1
1011
131 if $exp && ($exp < -1075 || $exp > 970);
132
133 17 return 1;
134 }
135  
136  
137 #------------------------------------------------------------------------
138 # float
139 # IEEE single precision 32-bit floating point number. Derived from
140 # double with an additional constraint check on the bounds of the
141 # mantissa and exponent.
142 #------------------------------------------------------------------------
143  
144 package XML::Schema::Type::float;
145 28 ▶use base qw( XML::Schema::Type::double );
Subroutine BEGIN: called CC=1 SCAR=0.0
146 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
147  
148 28 @FACETS = (
149 \&prepare,
150 );
151  
152 11 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=13.9
153 11 my ($instance, $type) = @_;
154  
155 # TODO: need to test bounds of mantissa ( < 2^24 )
156  
157 11 my $exp = $instance->{ exponent };
158  
159 11 ▶ return $type->error('float exponent is not valid (-149 <= e <= 104)')
Branch: 1 branch
BranchTrueFalseTotal
if $exp and $exp < -149 || $exp > 104 2 9 11
Condition100%6/6
$exp and $exp < -149 || $exp > 104
!ll&&!rl&&r
542
$exp < -149 or $exp > 104
l!l&&r!l&&!r
114
MC/DC100%3/3
$exp and $exp < -149 || $exp > 104
$exp $exp < -149 $exp > 104
Truth table100%4/4
A and B or C
A= $expB= $exp < -149C= $exp > 104
ABCresult
0XX0
1000
11X1
1011
160 if $exp && ($exp < -149 || $exp > 104);
161  
162 9 return 1;
163 }
164  
165  
166 #------------------------------------------------------------------------
167 # decimal
168 # Arbitrary precision decimal number.
169 #------------------------------------------------------------------------
170  
171 package XML::Schema::Type::decimal;
172 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
173 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
174  
175 28 @FACETS = (
176 whiteSpace => 'collapse',
177 \&prepare,
178 );
179  
180 145 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
181 145 my ($instance, $type) = @_;
182 145 my $value = $instance->{ value };
183  
184 145 ▶ return $type->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 5 140 145
185 unless length $value;
186  
187 140 ▶ return $type->error("value is not a decimal")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([+-])? # sign ($1) 0*(\d+) # integer ($2) (?:\.(\d+)0*)? # fraction ($3) $ /x 11 129 140
188 unless $value =~ /
189 ^
190 ([+-])? # sign ($1)
191 0*(\d+) # integer ($2)
192 (?:\.(\d+)0*)? # fraction ($3)
193 $
194 /x;
195  
196 129 @$instance{ qw( sign integer fraction ) } = ($1, $2, $3);
197 129 $instance->{ scale } = length $3;
198 129 $instance->{ precision } = $instance->{ scale } + length $2;
199  
200 129 return 1;
201 }
202  
203  
204 #------------------------------------------------------------------------
205 # timeDuration
206 # A duration of time as in the extended format as defined in [ISO 8601
207 # Date and Time Formats]. e.g. P7Y1M4DT7H3M12.8S: 7 years, 1 month, 4
208 # days, 7 hours, 3 minutes and 12.8 seconds.
209 #------------------------------------------------------------------------
210  
211 package XML::Schema::Type::timeDuration;
212 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
213 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
214  
215 28 @FACETS = (
216 whiteSpace => 'collapse',
217 \&prepare, # install direct call to subroutine
218 );
219  
220 62 ▶sub prepare {
Subroutine prepare: called CC=16 SCAR=27.7
221 62 my ($instance, $type) = @_;
222 62 my $value = $instance->{ value };
223  
224 62 ▶ return $type->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 1 61 62
225 unless length $value;
226  
227 61 ▶ return $type->error("value is not a valid timeDuration")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ (-)? # sign ($1) P([^T]*) # date ($2) (?:T(.+))? # time ($3) $ /x 6 55 61
228 unless $value =~ /
229 ^
230 (-)? # sign ($1)
231 P([^T]*) # date ($2)
232 (?:T(.+))? # time ($3)
233 $
234 /x;
235  
236 55 ▶ return $type->error("value must specify at least one date/time item")
Branch: 1 branch
BranchTrueFalseTotal
unless length $2 or $3 1 54 55
Condition100%3/3
length $2 or $3
l!l&&r!l&&!r
4771
MC/DC100%2/2
length $2 or $3
length $2 $3
Truth table100%3/3
A or B
A= length $2B= $3
ABresult
1X1
011
000
237 unless length $2 or $3;
238  
239 54 $instance->{ sign } = $1;
240 54 ▶ $instance->{ date } = $2 || '';
Condition100%2/2
$2 || ''
l!l
477
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
241 54 ▶ $instance->{ time } = $3 || '';
Condition100%2/2
$3 || ''
l!l
1044
MC/DC100%1/1
$3 || ''
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
242  
243 return $type->error("value contains an invalid date element")
244 54 ▶ unless $instance->{ date } =~ /
Branch: 1 branch
BranchTrueFalseTotal
unless $instance->{"date"} =~ / ^ (?:(\d+)Y)? # years ($1) (?:(\d+)M)? # months ($2) (?:(\d+)D)? # days ($3) $ /x 0 54 54
245 ^
246 (?:(\d+)Y)? # years ($1)
247 (?:(\d+)M)? # months ($2)
248 (?:(\d+)D)? # days ($3)
249 $
250 /x;
251 54 @$instance{ qw( years months days ) } = ($1, $2, $3);
252 54 ▶ $instance->{ zero_date } = ($1 || $2 || $3) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$1 || $2 || $3 ? : 30 24 54
Condition100%6/6
$1 or $2 or $3
l!l&&r!l&&!r
171324
$1 or $2
l!l&&r!l&&!r
9837
MC/DC100%3/3
$1 or $2 or $3
$1 $2 $3
Truth table100%4/4
A or B or C
A= $1B= $2C= $3
ABCresult
1XX1
01X1
0011
0000
253  
254 return $type->error("value contains an invalid time element")
255 54 ▶ unless $instance->{ time } =~ /
Branch: 1 branch
BranchTrueFalseTotal
unless $instance->{"time"} =~ / ^ (?:(\d+)H)? # hours ($1) (?:(\d+)M)? # minutes ($2) (?:(\d(?:\.\d+)?)S)? # seconds ($3) $ /x 0 54 54
256 ^
257 (?:(\d+)H)? # hours ($1)
258 (?:(\d+)M)? # minutes ($2)
259 (?:(\d(?:\.\d+)?)S)? # seconds ($3)
260 $
261 /x;
262 54 @$instance{ qw( hours minutes seconds ) } = ($1, $2, $3);
263 54 ▶ $instance->{ zero_time } = ($1 || $2 || $3) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$1 || $2 || $3 ? : 10 44 54
Condition100%6/6
$1 or $2 or $3
l!l&&r!l&&!r
8244
$1 or $2
l!l&&r!l&&!r
5346
MC/DC100%3/3
$1 or $2 or $3
$1 $2 $3
Truth table100%4/4
A or B or C
A= $1B= $2C= $3
ABCresult
1XX1
01X1
0011
0000
264  
265 $instance->{ zero } = $instance->{ zero_date }
266 54 ▶ && $instance->{ zero_time };
Condition100%3/3
$instance->{'zero_date'} && $instance->{'zero_time'}
!ll&&!rl&&r
30717
MC/DC100%2/2
$instance->{'zero_date'} && $instance->{'zero_time'}
$instance->{'zero_date'} $instance->{'zero_time'}
Truth table100%3/3
A && B
A= $instance->{'zero_date'}B= $instance->{'zero_time'}
ABresult
0X0
100
111
267  
268 54 return 1;
269 }
270  
271
272 #------------------------------------------------------------------------
273 # recurringDuration
274 # Note that period and duration do not affect the parser implemented in
275 # the prepare() method. Derived types that specify an alternate or
276 # truncated lexical format should implement their own prepare()
277 # method.
278 #------------------------------------------------------------------------
279  
280 package XML::Schema::Type::recurringDuration;
281 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
282 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
283  
284 @FACETS = (
285 whiteSpace => 'collapse',
286 70 ▶ sub { $_[1]->prepare($_[0]) }, # install hook to call object method
Subroutine __ANON__: called CC=1 SCAR=0.0
287 28 );
288  
289 21 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
290 21 my $self = shift;
291 return undef
292 21 ▶ unless $self->SUPER::init(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::init(@_) 1 20 21
293 20 ▶ return $self->error('duration not defined')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->facet("duration") 2 18 20
294 unless $self->facet('duration');
295 18 ▶ return $self->error('period not defined')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->facet("period") 1 17 18
296 unless $self->facet('period');
297 17 return $self;
298 }
299  
300 10 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=14.0
301 10 my ($self, $instance) = @_;
302 10 my $value = $instance->{ value };
303  
304 10 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 10 10
305 unless length $value;
306  
307 10 ▶ return $self->error("value is not a valid recurringDuration")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([+-])? # sign ($1) (\d{2,}) # century ($2) (\d{2}) - # year ($3) (\d{2}) - # month ($4) (\d{2}) T # day ($5) (\d{2}) : # hour ($6) (\d{2}) : # minute ($7) (\d{2}(?:.\d+)?) # second ($8) (?: # optional time zone (Z) # UTC ($9) | ([-+]) # sign ($10) (\d{2}) : # hours ($11) (\d{2}) # minutes ($12) )? $ /x 0 10 10
308 unless $value =~ /
309 ^
310 ([+-])? # sign ($1)
311 (\d{2,}) # century ($2)
312 (\d{2}) - # year ($3)
313 (\d{2}) - # month ($4)
314 (\d{2}) T # day ($5)
315 (\d{2}) : # hour ($6)
316 (\d{2}) : # minute ($7)
317 (\d{2}(?:.\d+)?) # second ($8)
318 (?: # optional time zone
319 (Z) # UTC ($9)
320 | ([-+]) # sign ($10)
321 (\d{2}) : # hours ($11)
322 (\d{2}) # minutes ($12)
323 )?
324 $
325 /x;
326  
327 10 @$instance{ qw( sign century year month day hour minute second ) }
328 = ($1, $2, $3, $4, $5, $6, $7, $8 );
329 10 ▶ $instance->{ UTC } = $9 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$9 ? : 3 7 10
330 10 my $zone = $instance->{ zone } = { };
331 10 @$zone{ qw( sign hour minute ) } = ($10, $11, $12);
332  
333 10 return 1;
334 }
335  
336  
337 #------------------------------------------------------------------------
338 # binary
339 # Arbitrary binary data. Must be derived to specify encoding.
340 #------------------------------------------------------------------------
341  
342 package XML::Schema::Type::binary;
343 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
344 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
345  
346 28 @FACETS = (
347 whiteSpace => 'collapse',
348 );
349  
350 3 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
351 3 my $self = shift;
352 return undef
353 3 ▶ unless $self->SUPER::init(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::init(@_) 1 2 3
354 2 ▶ return $self->error('encoding not defined')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->facet("encoding") 1 1 2
355 unless $self->facet('encoding');
356 1 return $self;
357 }
358  
359  
360 #------------------------------------------------------------------------
361 # uriReference
362 # Uniform Resource Identifier as defined in Section 4 of [RFC 2396] and
363 # amended by [RFC 2732].
364 #------------------------------------------------------------------------
365  
366 package XML::Schema::Type::uriReference;
367 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
368 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
369  
370 @FACETS = (
371 whiteSpace => 'collapse',
372 0 ▶ sub { die "uriReference not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
373 28 );
374  
375  
376 #------------------------------------------------------------------------
377 # ENTITY
378 #------------------------------------------------------------------------
379  
380 package XML::Schema::Type::ENTITY;
381 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
382 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
383  
384 @FACETS = (
385 whiteSpace => 'collapse',
386 0 ▶ sub { die "ENTITY not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
387 28 );
388  
389  
390 #------------------------------------------------------------------------
391 # QName
392 #------------------------------------------------------------------------
393  
394 package XML::Schema::Type::QName;
395 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
396 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
397  
398 28 @FACETS = (
399 whiteSpace => 'collapse',
400 \&prepare,
401 );
402  
403 5 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=13.9
404 5 my ($instance, $type) = @_;
405 5 my $value = $instance->{ value };
406  
407 5 ▶ return $type->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 1 4 5
408 unless length $value;
409  
410 4 ▶ return $type->error("value is not a valid QName")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ (?: ([a-zA-Z_][\w\-.]*?) # prefix ($1) : )? ([a-zA-Z_][\w\-.]*?) # local ($2) $ /x 1 3 4
411 unless $value =~ /
412 ^
413 (?:
414 ([a-zA-Z_][\w\-.]*?) # prefix ($1)
415 :
416 )?
417 ([a-zA-Z_][\w\-.]*?) # local ($2)
418 $
419 /x;
420  
421 3 ▶ $instance->{ prefix } = $1 || '';
Condition100%2/2
$1 || ''
l!l
21
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
422 3 $instance->{ local } = $2;
423  
424 # TODO: need to validate prefix to a namespace
425 3 $instance->{ namespace } = '???';
426  
427 3 return 1;
428 }
429  
430  
431  
432  
433 #========================================================================
434 # Derived datatypes
435 #
436 # Based on XML Schema Part 2: Datatypes, W3C Candidate Recommendation,
437 # 24 October 2000, section 3.3.
438 #========================================================================
439  
440 #------------------------------------------------------------------------
441 # CDATA
442 # As per string but with newlines, carriage returns and tabs converted
443 # to spaces.
444 #------------------------------------------------------------------------
445  
446 package XML::Schema::Type::CDATA;
447 28 ▶use base qw( XML::Schema::Type::string );
Subroutine BEGIN: called CC=1 SCAR=0.0
448 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
449  
450 28 @FACETS = (
451 whiteSpace => 'replace'
452 );
453  
454  
455 #------------------------------------------------------------------------
456 # token
457 # As per CDATA but with adjacent spaces collapsed to a single space
458 # and leading and trailing spaces removed. Note derivation from
459 # string rather than CDATA.
460 #------------------------------------------------------------------------
461  
462 package XML::Schema::Type::token;
463 28 ▶use base qw( XML::Schema::Type::string );
Subroutine BEGIN: called CC=1 SCAR=0.0
464 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
465  
466 28 @FACETS = (
467 whiteSpace => 'collapse'
468 );
469  
470  
471 #------------------------------------------------------------------------
472 # language
473 # Derived from token, with a pattern constraint to represent natural
474 # language identifiers as defined by RFC 1766.
475 #------------------------------------------------------------------------
476  
477 package XML::Schema::Type::language;
478 28 ▶use base qw( XML::Schema::Type::token );
Subroutine BEGIN: called CC=1 SCAR=0.0
479 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
480  
481 28 @FACETS = (
482 pattern => {
483 value => '^([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*$',
484 errmsg => 'value is not a language',
485 }
486 );
487  
488  
489 #------------------------------------------------------------------------
490 # IDREFS
491 #------------------------------------------------------------------------
492  
493 package XML::Schema::Type::IDREFS;
494 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
495 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
496  
497 @FACETS = (
498 0 ▶ sub { die "IDREFS not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
499 28 );
500  
501  
502 #------------------------------------------------------------------------
503 # ENTITIES
504 #------------------------------------------------------------------------
505  
506 package XML::Schema::Type::ENTITIES;
507 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
508 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
509  
510 @FACETS = (
511 0 ▶ sub { die "ENTITIES not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
512 28 );
513  
514  
515 #------------------------------------------------------------------------
516 # NMTOKEN
517 # String matching the NMTOKEN attribute type from [XML 1.0
518 # Recommendation (Second Edition)].
519 #------------------------------------------------------------------------
520  
521 package XML::Schema::Type::NMTOKEN;
522 28 ▶use base qw( XML::Schema::Type::token );
Subroutine BEGIN: called CC=1 SCAR=0.0
523 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
524  
525 28 @FACETS = (
526 pattern => {
527 value => '^[\w\-_.:]+$',
528 errmsg => 'value is not a valid NMTOKEN',
529 }
530 );
531  
532  
533 #------------------------------------------------------------------------
534 # NMTOKENS
535 #------------------------------------------------------------------------
536  
537 package XML::Schema::Type::NMTOKENS;
538 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
539 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
540  
541 @FACETS = (
542 0 ▶ sub { die "NMTOKENS not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
543 28 );
544  
545  
546 #------------------------------------------------------------------------
547 # Name
548 # String matching the 'Name' production of [XML 1.0 Recommendation
549 # (Second Edition)].
550 #------------------------------------------------------------------------
551  
552 package XML::Schema::Type::Name;
553 28 ▶use base qw( XML::Schema::Type::token );
Subroutine BEGIN: called CC=1 SCAR=0.0
554 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
555  
556 28 @FACETS = (
557 pattern => {
558 value => '^[a-zA-Z_:][\w\-_.:]*$',
559 errmsg => 'value is not a valid Name',
560 }
561 );
562  
563  
564 #------------------------------------------------------------------------
565 # NCName
566 # Non-colonized name, a string matching the 'NCName' production of
567 # [Namespaces in XML].
568 #------------------------------------------------------------------------
569  
570 package XML::Schema::Type::NCName;
571 28 ▶use base qw( XML::Schema::Type::token );
Subroutine BEGIN: called CC=1 SCAR=0.0
572 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
573  
574 28 @FACETS = (
575 pattern => {
576 value => '^[a-zA-Z_][\w\-.]*$',
577 errmsg => 'value is not a valid NCName',
578 }
579 );
580  
581 #------------------------------------------------------------------------
582 # ID
583 # String matching the ID attribute type from [XML 1.0 Recommendation
584 # (Second Edition)].
585 #------------------------------------------------------------------------
586  
587 package XML::Schema::Type::ID;
588 28 ▶use base qw( XML::Schema::Type::Name );
Subroutine BEGIN: called CC=1 SCAR=0.0
589 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
590  
591 28 @FACETS = (
592 \&prepare,
593 );
594  
595 0 ▶sub prepare {
Subroutine prepare: not called CC=1 SCAR=6.9
596 0 my ($instance, $type) = @_;
597 0 $instance->{ magic } = [ ID => $instance->{ value } ];
598 0 return 1;
599 }
600  
601  
602 #------------------------------------------------------------------------
603 # IDREF
604 #------------------------------------------------------------------------
605  
606 package XML::Schema::Type::IDREF;
607 28 ▶use base qw( XML::Schema::Type::Name );
Subroutine BEGIN: called CC=1 SCAR=0.0
608 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
609  
610 28 @FACETS = (
611 \&prepare,
612 );
613  
614 0 ▶sub prepare {
Subroutine prepare: not called CC=1 SCAR=6.9
615 0 my ($instance, $type) = @_;
616 0 $instance->{ magic } = [ IDREF => $instance->{ value } ];
617 0 return 1;
618 }
619  
620  
621 #------------------------------------------------------------------------
622 # NOTATION
623 #------------------------------------------------------------------------
624  
625 package XML::Schema::Type::NOTATION;
626 28 ▶use base qw( XML::Schema::Type::Simple );
Subroutine BEGIN: called CC=1 SCAR=0.0
627 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
628  
629 @FACETS = (
630 0 ▶ sub { die "NOTATION not yet implemented\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
631 28 );
632  
633  
634 #------------------------------------------------------------------------
635 # integer
636 #------------------------------------------------------------------------
637  
638 package XML::Schema::Type::integer;
639 28 ▶use base qw( XML::Schema::Type::decimal );
Subroutine BEGIN: called CC=1 SCAR=0.0
640 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
641  
642 28 @FACETS = (
643 scale => {
644 value => 0,
645 fixed => 1,
646 errmsg => 'value is not an integer',
647 },
648 );
649  
650  
651 #------------------------------------------------------------------------
652 # nonPositiveInteger
653 # An integer value less than or equal to 0
654 #------------------------------------------------------------------------
655  
656 package XML::Schema::Type::nonPositiveInteger;
657 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
658 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
659  
660 28 @FACETS = (
661 maxInclusive => {
662 value => 0,
663 errmsg => 'value is positive',
664 },
665 );
666  
667  
668 #------------------------------------------------------------------------
669 # negativeInteger
670 # An integer value less than 0
671 #------------------------------------------------------------------------
672  
673 package XML::Schema::Type::negativeInteger;
674 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
675 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
676  
677 28 @FACETS = (
678 maxInclusive => {
679 value => -1,
680 errmsg => 'value is not negative'
681 },
682 );
683  
684  
685 #------------------------------------------------------------------------
686 # long
687 # An integer in the range -9223372036854775808 to 9223372036854775807.
688 # See comments in docs/nonconform relating to failure to correctly
689 # validate long numbers.
690 #------------------------------------------------------------------------
691  
692 package XML::Schema::Type::long;
693 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
694 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
695  
696 28 @FACETS = (
697 minInclusive => -9223372036854775808,
698 maxInclusive => 9223372036854775807,
699 );
700  
701  
702 #------------------------------------------------------------------------
703 # int
704 # An integer value in the range -2147483648 to 2147483647. Note that
705 # we derive directly from integer rather than long.
706 #------------------------------------------------------------------------
707  
708 package XML::Schema::Type::int;
709 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
710 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
711  
712 28 @FACETS = (
713 minInclusive => -2147483648,
714 maxInclusive => 2147483647,
715 );
716  
717  
718 #------------------------------------------------------------------------
719 # short
720 # An integer value in the range -32768 to 32767. Note that
721 # we derive directly from integer rather than int.
722 #------------------------------------------------------------------------
723  
724 package XML::Schema::Type::short;
725 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
726 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
727  
728 28 @FACETS = (
729 minInclusive => -32768,
730 maxInclusive => 32767,
731 );
732  
733  
734 #------------------------------------------------------------------------
735 # byte
736 # An integer in the range -128 to 127. Again, this is derived
737 # directly from integer rather than via short.
738 #------------------------------------------------------------------------
739  
740 package XML::Schema::Type::byte;
741 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
742 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
743  
744 28 @FACETS = (
745 minInclusive => -128,
746 maxInclusive => 127,
747 );
748  
749  
750 #------------------------------------------------------------------------
751 # nonNegativeInteger
752 # An integer value greater than or equal to 0
753 #------------------------------------------------------------------------
754  
755 package XML::Schema::Type::nonNegativeInteger;
756 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
757 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
758  
759 28 @FACETS = (
760 minInclusive => {
761 value => 0,
762 errmsg => 'value is negative',
763 },
764 );
765  
766  
767 #------------------------------------------------------------------------
768 # unsignedLong
769 # An integer in the range 0 to 18446744073709551615
770 # See comments in docs/nonconform relating to failure to correctly
771 # validate long numbers.
772 #------------------------------------------------------------------------
773  
774 package XML::Schema::Type::unsignedLong;
775 28 ▶use base qw( XML::Schema::Type::nonNegativeInteger );
Subroutine BEGIN: called CC=1 SCAR=0.0
776 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
777  
778 28 @FACETS = (
779 maxInclusive => 18446744073709551615,
780 );
781  
782  
783 #------------------------------------------------------------------------
784 # unsignedInt
785 # An integer in the range 0 to 4294967295. This is derived directly
786 # from nonNegativeInteger rather than via unsignedLong.
787 #------------------------------------------------------------------------
788  
789 package XML::Schema::Type::unsignedInt;
790 28 ▶use base qw( XML::Schema::Type::nonNegativeInteger );
Subroutine BEGIN: called CC=1 SCAR=0.0
791 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
792  
793 28 @FACETS = (
794 maxInclusive => 4294967295,
795 );
796  
797  
798 #------------------------------------------------------------------------
799 # unsignedShort
800 # An integer in the range 0 to 65535. This is derived directly
801 # from nonNegativeInteger rather than via unsignedInt.
802 #------------------------------------------------------------------------
803  
804 package XML::Schema::Type::unsignedShort;
805 28 ▶use base qw( XML::Schema::Type::nonNegativeInteger );
Subroutine BEGIN: called CC=1 SCAR=0.0
806 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
807  
808 28 @FACETS = (
809 maxInclusive => 65535,
810 );
811  
812  
813 #------------------------------------------------------------------------
814 # unsignedByte
815 # An unsigned byte in the range 0 to 255. Again, this is derived
816 # directly from nonNegativeInteger rather than via unsignedShort.
817 #------------------------------------------------------------------------
818  
819 package XML::Schema::Type::unsignedByte;
820 28 ▶use base qw( XML::Schema::Type::nonNegativeInteger );
Subroutine BEGIN: called CC=1 SCAR=0.0
821 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
822  
823 28 @FACETS = (
824 maxInclusive => 255,
825 );
826  
827  
828 #------------------------------------------------------------------------
829 # positiveInteger
830 # An integer value greater than 0
831 #------------------------------------------------------------------------
832  
833 package XML::Schema::Type::positiveInteger;
834 28 ▶use base qw( XML::Schema::Type::integer );
Subroutine BEGIN: called CC=1 SCAR=0.0
835 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
836  
837 28 @FACETS = (
838 minInclusive => {
839 value => 1,
840 errmsg => 'value is not positive',
841 },
842 );
843  
844  
845 #------------------------------------------------------------------------
846 # timeInstant
847 #------------------------------------------------------------------------
848  
849 package XML::Schema::Type::timeInstant;
850 28 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
851 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
852  
853 28 @FACETS = (
854 period => { value => 'P0Y', fixed => 1 },
855 duration => { value => 'P0Y', fixed => 1 },
856 );
857  
858  
859 #------------------------------------------------------------------------
860 # time
861 #------------------------------------------------------------------------
862  
863 package XML::Schema::Type::time;
864 28 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
865 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
866  
867 28 @FACETS = (
868 period => { value => 'P1D', fixed => 1 },
869 duration => { value => 'P0Y', fixed => 1 },
870 );
871  
872 28 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=13.9
873 28 my ($self, $instance) = @_;
874 28 my $value = $instance->{ value };
875  
876 28 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 1 27 28
877 unless length $value;
878  
879 27 ▶ return $self->error("value is not a valid date")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ (\d{2}) : # hour ($1) (\d{2}) : # minute ($2) (\d{2}(?:.\d+)?) # second ($3) (?: # optional time zone (Z) # UTC ($4) | ([-+]) # sign ($5) (\d{2}) : # hours ($6) (\d{2}) # minutes ($7) )? $ /x 3 24 27
880 unless $value =~ /
881 ^
882 (\d{2}) : # hour ($1)
883 (\d{2}) : # minute ($2)
884 (\d{2}(?:.\d+)?) # second ($3)
885 (?: # optional time zone
886 (Z) # UTC ($4)
887 | ([-+]) # sign ($5)
888 (\d{2}) : # hours ($6)
889 (\d{2}) # minutes ($7)
890 )?
891 $
892 /x;
893  
894 24 @$instance{ qw( hour minute second ) } = ($1, $2, $3);
895 24 ▶ $instance->{ UTC } = $4 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$4 ? : 2 22 24
896 24 my $zone = $instance->{ zone } = { };
897 24 @$zone{ qw( sign hour minute ) } = ($5, $6, $7);
898  
899 24 return 1;
900 }
901  
902  
903 #------------------------------------------------------------------------
904 # timePeriod
905 #------------------------------------------------------------------------
906  
907 package XML::Schema::Type::timePeriod;
908 28 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
909 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
910  
911 28 @FACETS = (
912 period => { value => 'P0Y', fixed => 1 },
913 );
914  
915  
916 #------------------------------------------------------------------------
917 # date
918 #------------------------------------------------------------------------
919  
920 package XML::Schema::Type::date;
921 28 ▶use base qw( XML::Schema::Type::timePeriod );
Subroutine BEGIN: called CC=1 SCAR=0.0
922 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
923  
924 28 @FACETS = (
925 duration => { value => 'P1D', fixed => 1 },
926 );
927  
928 5 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
929 5 my ($self, $instance) = @_;
930 5 my $value = $instance->{ value };
931  
932 5 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 5 5
933 unless length $value;
934  
935 5 ▶ return $self->error("value is not a valid date")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([-+]?) # sign ($1) (\d{2,}) # century ($2) (\d{2}) - # year ($3) (\d{2}) - # month ($4) (\d{2}) # day ($5) $ /x 1 4 5
936 unless $value =~ /
937 ^
938 ([-+]?) # sign ($1)
939 (\d{2,}) # century ($2)
940 (\d{2}) - # year ($3)
941 (\d{2}) - # month ($4)
942 (\d{2}) # day ($5)
943 $
944 /x;
945  
946 4 @$instance{ qw( sign century year month day ) } = ( $1, $2, $3, $4, $5 );
947  
948 4 return 1;
949 }
950  
951  
952 #------------------------------------------------------------------------
953 # month
954 #------------------------------------------------------------------------
955  
956 package XML::Schema::Type::month;
957 28 ▶use base qw( XML::Schema::Type::timePeriod );
Subroutine BEGIN: called CC=1 SCAR=0.0
958 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
959  
960 28 @FACETS = (
961 duration => { value => 'P1M', fixed => 1 },
962 );
963  
964 6 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
965 6 my ($self, $instance) = @_;
966 6 my $value = $instance->{ value };
967  
968 6 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 6 6
969 unless length $value;
970  
971 6 ▶ return $self->error("value is not a valid month")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([-+]?) # sign ($1) (\d{2,}) # century ($2) (\d{2}) - # year ($3) (\d{2}) # month ($4) $ /x 2 4 6
972 unless $value =~ /
973 ^
974 ([-+]?) # sign ($1)
975 (\d{2,}) # century ($2)
976 (\d{2}) - # year ($3)
977 (\d{2}) # month ($4)
978 $
979 /x;
980  
981 4 @$instance{ qw( sign century year month ) } = ( $1, $2, $3, $4 );
982  
983 4 return 1;
984 }
985  
986  
987 #------------------------------------------------------------------------
988 # year
989 #------------------------------------------------------------------------
990  
991 package XML::Schema::Type::year;
992 28 ▶use base qw( XML::Schema::Type::timePeriod );
Subroutine BEGIN: called CC=1 SCAR=0.0
993 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
994  
995 28 @FACETS = (
996 duration => { value => 'P1Y', fixed => 1 },
997 );
998  
999 7 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
1000 7 my ($self, $instance) = @_;
1001 7 my $value = $instance->{ value };
1002  
1003 7 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 7 7
1004 unless length $value;
1005  
1006 7 ▶ return $self->error("value is not a valid year")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([-+]?) # sign ($1) (\d{2,}) # century ($2) (\d{2}) # year ($3) $ /x 2 5 7
1007 unless $value =~ /
1008 ^
1009 ([-+]?) # sign ($1)
1010 (\d{2,}) # century ($2)
1011 (\d{2}) # year ($3)
1012 $
1013 /x;
1014  
1015 5 @$instance{ qw( sign century year ) } = ( $1, $2, $3 );
1016  
1017 5 return 1;
1018 }
1019  
1020  
1021 #------------------------------------------------------------------------
1022 # century
1023 #------------------------------------------------------------------------
1024  
1025 package XML::Schema::Type::century;
1026 28 ▶use base qw( XML::Schema::Type::timePeriod );
Subroutine BEGIN: called CC=1 SCAR=0.0
1027 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
1028  
1029 28 @FACETS = (
1030 duration => { value => 'P100Y', fixed => 1 },
1031 );
1032  
1033 7 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
1034 7 my ($self, $instance) = @_;
1035 7 my $value = $instance->{ value };
1036  
1037 7 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 7 7
1038 unless length $value;
1039  
1040 7 ▶ return $self->error("value is not a valid century")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ ([-+]?) # sign ($1) (\d{2,}) # century ($2) $ /x 2 5 7
1041 unless $value =~ /
1042 ^
1043 ([-+]?) # sign ($1)
1044 (\d{2,}) # century ($2)
1045 $
1046 /x;
1047  
1048 5 @$instance{ qw( sign century ) } = ( $1, $2 );
1049  
1050 5 return 1;
1051 }
1052  
1053  
1054 #------------------------------------------------------------------------
1055 # recurringDate
1056 #------------------------------------------------------------------------
1057  
1058 package XML::Schema::Type::recurringDate;
1059 28 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
1060 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
1061  
1062 28 @FACETS = (
1063 duration => { value => 'P1D', fixed => 1 },
1064 period => { value => 'P1Y', fixed => 1 },
1065 );
1066  
1067 5 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
1068 5 my ($self, $instance) = @_;
1069 5 my $value = $instance->{ value };
1070  
1071 5 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 5 5
1072 unless length $value;
1073  
1074 5 ▶ return $self->error("value is not a valid recurringDate")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ -- (\d{2}) - # month ($1) (\d{2}) # day ($2) $ /x 2 3 5
1075 unless $value =~ /
1076 ^
1077 --
1078 (\d{2}) - # month ($1)
1079 (\d{2}) # day ($2)
1080 $
1081 /x;
1082  
1083 3 @$instance{ qw( month day ) } = ( $1, $2 );
1084  
1085 3 return 1;
1086 }
1087  
1088  
1089 #------------------------------------------------------------------------
1090 # recurringDay
1091 #------------------------------------------------------------------------
1092  
1093 package XML::Schema::Type::recurringDay;
1094 28 ▶use base qw( XML::Schema::Type::recurringDuration );
Subroutine BEGIN: called CC=1 SCAR=0.0
1095 28 ▶use vars qw( $ERROR @FACETS );
Subroutine BEGIN: called CC=1 SCAR=0.0
1096  
1097 28 @FACETS = (
1098 duration => { value => 'P1D', fixed => 1 },
1099 period => { value => 'P1M', fixed => 1 },
1100 );
1101  
1102 2 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.2
1103 2 my ($self, $instance) = @_;
1104 2 my $value = $instance->{ value };
1105  
1106 2 ▶ return $self->error('value is empty')
Branch: 1 branch
BranchTrueFalseTotal
unless length $value 0 2 2
1107 unless length $value;
1108  
1109 2 ▶ return $self->error("value is not a valid recurringDay")
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ / ^ --- (\d{2}) # day ($1) $ /x 0 2 2
1110 unless $value =~ /
1111 ^
1112 ---
1113 (\d{2}) # day ($1)
1114 $
1115 /x;
1116  
1117 2 $instance->{ day } = $1;
1118  
1119 2 return 1;
1120 }
1121  
1122 28 1;
1123  
1124 __END__
« lib/XML/Schema/Factory.pm ↑ Summary lib/XML/Schema/Handler/Simple.pm »