line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package W3C::SOAP::XSD::Types; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2012-05-26 23:08:42 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
11
|
1
|
|
|
1
|
|
5
|
use version; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
12
|
1
|
|
|
1
|
|
89
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
1
|
|
|
1
|
|
15
|
$W3C::SOAP::XSD::Types::AUTHORITY = 'cpan:IVANWILLS'; |
15
|
|
|
|
|
|
|
} |
16
|
1
|
|
|
1
|
|
4
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
17
|
1
|
|
|
1
|
|
4
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
18
|
1
|
|
|
1
|
|
1058
|
use DateTime::Format::Strptime; |
|
1
|
|
|
|
|
6152
|
|
|
1
|
|
|
|
|
73
|
|
19
|
1
|
|
|
|
|
10
|
use MooseX::Types -declare |
20
|
|
|
|
|
|
|
=> [qw/ |
21
|
|
|
|
|
|
|
xsd:duration |
22
|
|
|
|
|
|
|
xsd:dateTime |
23
|
|
|
|
|
|
|
xsd:time |
24
|
|
|
|
|
|
|
xsd:date |
25
|
|
|
|
|
|
|
xsd:gYearMonth |
26
|
|
|
|
|
|
|
xsd:gYear |
27
|
|
|
|
|
|
|
xsd:gMonthDay |
28
|
|
|
|
|
|
|
xsd:gDay |
29
|
|
|
|
|
|
|
xsd:gMonth |
30
|
1
|
|
|
1
|
|
7
|
/]; |
|
1
|
|
|
|
|
2
|
|
31
|
1
|
|
|
1
|
|
6268
|
use DateTime; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
32
|
1
|
|
|
1
|
|
5
|
use DateTime::Format::Strptime qw/strptime/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
33
|
1
|
|
|
1
|
|
4
|
use Math::BigFloat; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = version->new('0.11'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub {}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
class_type 'DateTime'; |
40
|
|
|
|
|
|
|
class_type 'XML::LibXML::Node'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
subtype 'xsd:boolean', |
43
|
|
|
|
|
|
|
as 'xs:boolean'; |
44
|
|
|
|
|
|
|
coerce 'xsd:boolean', |
45
|
|
|
|
|
|
|
from 'Str' |
46
|
|
|
|
|
|
|
=> via { |
47
|
|
|
|
|
|
|
$_ eq 'true' ? 1 |
48
|
|
|
|
|
|
|
: $_ eq 'false' ? undef |
49
|
|
|
|
|
|
|
: confess "'$_' isn't a xs:boolean!"; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
subtype 'xsd:double', |
53
|
|
|
|
|
|
|
as 'xs:double'; |
54
|
|
|
|
|
|
|
coerce 'xsd:double', |
55
|
|
|
|
|
|
|
# from 'Num' |
56
|
|
|
|
|
|
|
# => via { Params::Coerce::coerce('xs:double', $_) }, |
57
|
|
|
|
|
|
|
from 'Str' |
58
|
|
|
|
|
|
|
=> via { Math::BigFloat->new($_) }; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
subtype 'xsd:decimal', |
61
|
|
|
|
|
|
|
as 'xs:decimal'; |
62
|
|
|
|
|
|
|
coerce 'xsd:decimal', |
63
|
|
|
|
|
|
|
# from 'Num' |
64
|
|
|
|
|
|
|
# => via { Params::Coerce::coerce('xs:decimal', $_) }, |
65
|
|
|
|
|
|
|
from 'Str' |
66
|
|
|
|
|
|
|
=> via { Math::BigFloat->new($_) }; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
subtype 'xsd:long', |
69
|
|
|
|
|
|
|
as 'xs:long'; |
70
|
|
|
|
|
|
|
coerce 'xsd:long', |
71
|
|
|
|
|
|
|
# from 'Num' |
72
|
|
|
|
|
|
|
# => via { Params::Coerce::coerce('xs:long', $_) }, |
73
|
|
|
|
|
|
|
from 'Str' |
74
|
|
|
|
|
|
|
=> via { Math::BigInt->new($_) }; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#subtype 'xsd:duration', |
77
|
|
|
|
|
|
|
# as 'DateTime'; |
78
|
|
|
|
|
|
|
#coerce 'xsd:duration', |
79
|
|
|
|
|
|
|
# from 'Str', |
80
|
|
|
|
|
|
|
# via { |
81
|
|
|
|
|
|
|
# DateTime::Format::Strptime("", $_) |
82
|
|
|
|
|
|
|
# }; |
83
|
|
|
|
|
|
|
# |
84
|
|
|
|
|
|
|
subtype 'xsd:dateTime', |
85
|
|
|
|
|
|
|
as 'DateTime'; |
86
|
|
|
|
|
|
|
coerce 'xsd:dateTime', |
87
|
|
|
|
|
|
|
from 'XML::LibXML::Node' => |
88
|
|
|
|
|
|
|
=> via { $_->textContent }, |
89
|
|
|
|
|
|
|
from 'Str', |
90
|
|
|
|
|
|
|
=> via { |
91
|
|
|
|
|
|
|
return strptime("%FT%T", $_) if /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/xms; |
92
|
|
|
|
|
|
|
# DateTime expects timezones as [+-]hhmm XMLSchema expects them as [+-]hh:mm |
93
|
|
|
|
|
|
|
# also remove any milli seconds |
94
|
|
|
|
|
|
|
my $subseconds = /([.]\d+)/; |
95
|
|
|
|
|
|
|
s/(?:[.]\d+)? (?: ([+-]\d{2}) : (\d{2}) ) $/$1$2/xms; |
96
|
|
|
|
|
|
|
# Dates with timezones are meant to track the begging of the day |
97
|
|
|
|
|
|
|
my $dt = /[+-]\d{4}$/xms ? strptime("%FT%T%z", $_) : strptime("%FT%T", $_); |
98
|
|
|
|
|
|
|
$dt->set_nanosecond( $subseconds * 1_000_000_000 ) if $subseconds; |
99
|
|
|
|
|
|
|
return $dt; |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#subtype 'xsd:time', |
103
|
|
|
|
|
|
|
# as 'DateTime'; |
104
|
|
|
|
|
|
|
#coerce 'xsd:time', |
105
|
|
|
|
|
|
|
# from 'Str', |
106
|
|
|
|
|
|
|
# via { |
107
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
108
|
|
|
|
|
|
|
# }; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
subtype 'xsd:date', |
111
|
|
|
|
|
|
|
as 'DateTime'; |
112
|
|
|
|
|
|
|
coerce 'xsd:date', |
113
|
|
|
|
|
|
|
from 'XML::LibXML::Node' => |
114
|
|
|
|
|
|
|
=> via { $_->textContent }, |
115
|
|
|
|
|
|
|
from 'Str', |
116
|
|
|
|
|
|
|
=> via { |
117
|
|
|
|
|
|
|
return strptime("%F", $_) if /^\d{4}-\d{2}-\d{2}$/xms; |
118
|
|
|
|
|
|
|
# DateTime expects timezones as [+-]hhmm XMLSchema expects them as [+-]hh:mm |
119
|
|
|
|
|
|
|
s/([+-]\d{2}):(\d{2})$/$1$2/xms; |
120
|
|
|
|
|
|
|
# Dates with timezones are meant to track the begging of the day |
121
|
|
|
|
|
|
|
return strptime("%TT%F%z", "00:00:00T$_"); |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#subtype 'xsd:gYearMonth', |
125
|
|
|
|
|
|
|
# as 'DateTime'; |
126
|
|
|
|
|
|
|
#coerce 'xsd:gYearMonth', |
127
|
|
|
|
|
|
|
# from 'Str', |
128
|
|
|
|
|
|
|
# via { |
129
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
130
|
|
|
|
|
|
|
# }; |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
#subtype 'xsd:gYear', |
133
|
|
|
|
|
|
|
# as 'DateTime'; |
134
|
|
|
|
|
|
|
#coerce 'xsd:gYear', |
135
|
|
|
|
|
|
|
# from 'Str', |
136
|
|
|
|
|
|
|
# via { |
137
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
138
|
|
|
|
|
|
|
# }; |
139
|
|
|
|
|
|
|
# |
140
|
|
|
|
|
|
|
#subtype 'xsd:gMonthDay', |
141
|
|
|
|
|
|
|
# as 'DateTime'; |
142
|
|
|
|
|
|
|
#coerce 'xsd:gMonthDay', |
143
|
|
|
|
|
|
|
# from 'Str', |
144
|
|
|
|
|
|
|
# via { |
145
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
146
|
|
|
|
|
|
|
# }; |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
#subtype 'xsd:gDay', |
149
|
|
|
|
|
|
|
# as 'DateTime'; |
150
|
|
|
|
|
|
|
#coerce 'xsd:gDay', |
151
|
|
|
|
|
|
|
# from 'Str', |
152
|
|
|
|
|
|
|
# via { |
153
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
154
|
|
|
|
|
|
|
# }; |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
#subtype 'xsd:gMonth', |
157
|
|
|
|
|
|
|
# as 'DateTime'; |
158
|
|
|
|
|
|
|
#coerce 'xsd:gMonth', |
159
|
|
|
|
|
|
|
# from 'Str', |
160
|
|
|
|
|
|
|
# via { |
161
|
|
|
|
|
|
|
# DateTime::Format::Striptime("", $_) |
162
|
|
|
|
|
|
|
# }; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 NAME |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
W3C::SOAP::XSD::Types - Moose types to support W3C::SOAP::XSD objects |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 VERSION |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This documentation refers to W3C::SOAP::XSD::Types version 0.11. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use W3C::SOAP::XSD::Types; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# Brief but working code example(s) here showing the most common usage(s) |
182
|
|
|
|
|
|
|
# This section will be as far as many users bother reading, so make it as |
183
|
|
|
|
|
|
|
# educational and exemplary as possible. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 DESCRIPTION |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Defines the type library (extended from L<MosseX::Types::XMLSchema>) this |
189
|
|
|
|
|
|
|
adds extra coercions and in the case of Date/Time objects changes the base |
190
|
|
|
|
|
|
|
type to L<DateTime> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 Types |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=over 4 |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item C<xsd:boolean> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item C<xsd:double> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item C<xsd:dateTime> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item C<xsd:date> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
There are no known bugs in this module. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Patches are welcome. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
231
|
|
|
|
|
|
|
All rights reserved. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
234
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
235
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
236
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
237
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |