| 1 | 10 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 10 | ▶ | no warnings qw(uninitialized); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | |||||||||||
| 7 | #====================================================================== | ||||||||||
| 8 | package XML::Pastor::Builtin::dateTime; | ||||||||||
| 9 | |||||||||||
| 10 | 10 | ▶ | use XML::Pastor::Builtin::Scalar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 10 | our @ISA = qw(XML::Pastor::Builtin::Scalar); | |||||||||
| 13 | |||||||||||
| 14 | 10 | ▶ | use XML::Pastor::Util qw(validate_date validate_time); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 10 | XML::Pastor::Builtin::dateTime->XmlSchemaType( bless( { | |||||||||
| 17 | 'class' => 'XML::Pastor::Builtin::dateTime', | ||||||||||
| 18 | 'contentType' => 'simple', | ||||||||||
| 19 | 'derivedBy' => 'restriction', | ||||||||||
| 20 | 'name' => 'dateTime|http://www.w3.org/2001/XMLSchema', | ||||||||||
| 21 | 'regex' => qr/^[-+]?(\d{4,})-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:(?:Z)|(?:[-+]\d{2}:\d{2}))?$/, # Regex shamelessly copied from XML::Validator::Schema by Sam Tregar | ||||||||||
| 22 | }, 'XML::Pastor::Schema::SimpleType' ) ); | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | #-------------------------------------------------------- | ||||||||||
| 26 | # returns a DateTime object representing the value. | ||||||||||
| 27 | #-------------------------------------------------------- | ||||||||||
| 28 | 0 | ▶ | sub toDateTime() { | ||||||||
|
Subroutine
toDateTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | 0 | my $self = shift; | |||||||||
| 30 | |||||||||||
| 31 | 0 | require DateTime; | |||||||||
| 32 | 0 | require DateTime::Format::W3CDTF; | |||||||||
| 33 | |||||||||||
| 34 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||
| 35 | 0 | my $dt = $f->parse_datetime( $self->__value ); | |||||||||
| 36 | |||||||||||
| 37 | 0 | return $dt; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | #-------------------------------------------------------- | ||||||||||
| 42 | # CONSTRUCTOR. Creates a new object and sets the value from | ||||||||||
| 43 | # a DateTime object. | ||||||||||
| 44 | #-------------------------------------------------------- | ||||||||||
| 45 | 0 | ▶ | sub fromDateTime($) { | ||||||||
|
Subroutine
fromDateTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 0 | my $self = shift->new(); | |||||||||
| 47 | 0 | $self->setFromDateTime(shift); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | #-------------------------------------------------------- | ||||||||||
| 51 | # sets the value from a DateTime object. | ||||||||||
| 52 | #-------------------------------------------------------- | ||||||||||
| 53 | 0 | ▶ | sub setFromDateTime($) { | ||||||||
|
Subroutine
setFromDateTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | 0 | my $self = shift; | |||||||||
| 55 | 0 | my $dt = shift; | |||||||||
| 56 | |||||||||||
| 57 | 0 | require DateTime; | |||||||||
| 58 | 0 | require DateTime::Format::W3CDTF; | |||||||||
| 59 | |||||||||||
| 60 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||
| 61 | 0 | $self->__value($f->format_datetime($dt)); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | #-------------------------------------------------------- | ||||||||||
| 66 | # OVERRIDDEN from XML::Pastor::SimpleType | ||||||||||
| 67 | #-------------------------------------------------------- | ||||||||||
| 68 | 0 | ▶ | sub xml_validate_further { | ||||||||
|
Subroutine
xml_validate_further: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 69 | 0 | my $self = shift; | |||||||||
| 70 | 0 | my $value = $self->__value; | |||||||||
| 71 | |||||||||||
| 72 | # validate the date portion | ||||||||||
| 73 | 0 | $value =~ /^[-]?(\d{4,})-(\d\d)-(\d\d)/; | |||||||||
| 74 | 0 | ▶ | return 0 unless validate_date($1, $2, $3); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | # validate the time portion | ||||||||||
| 77 | 0 | ▶ | if ( $value =~ /T(\d{2}):(\d{2}):(\d{2})/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | return validate_time($1, $2, $3); | |||||||||
| 79 | } | ||||||||||
| 80 | 0 | return 1; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 10 | 1; | |||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||