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