| 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::date; | ||||||||||
| 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); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 10 | XML::Pastor::Builtin::date->XmlSchemaType( bless( { | |||||||||
| 17 | 'class' => 'XML::Pastor::Builtin::date', | ||||||||||
| 18 | 'contentType' => 'simple', | ||||||||||
| 19 | 'derivedBy' => 'restriction', | ||||||||||
| 20 | 'name' => 'date|http://www.w3.org/2001/XMLSchema', | ||||||||||
| 21 | 'regex' => qr /^[-]?(\d{4,})-(\d\d)-(\d\d)(Z?|([+|-]([0-1]\d|2[0-4])\:([0-5]\d))?)$/, # 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=3 SCAR=24.8
Pod
documented
| |||||||||||
| 29 | 0 | my $self = shift; | |||||||||
| 30 | 0 | my $value = $self->__value; | |||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | unless ($value =~ /^[-]?(\d{4,})-(\d\d)-(\d\d)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | die "Pastor: Invalid date '$value'!"; | |||||||||
| 34 | } | ||||||||||
| 35 | 0 | my ($year, $month, $day) = ($1, $2, $3); | |||||||||
| 36 | 0 | ▶ | $year = -$year if ($value =~ /^[-]/); # Catch negative year. | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | require DateTime; | |||||||||
| 39 | 0 | my $dt = DateTime->new( year => $year, | |||||||||
| 40 | month => $month, | ||||||||||
| 41 | day => $day, | ||||||||||
| 42 | hour => 0, minute => 0, second => 0); | ||||||||||
| 43 | |||||||||||
| 44 | 0 | return $dt; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | #-------------------------------------------------------- | ||||||||||
| 49 | # CONSTRUCTOR. Creates a new object and sets the value from | ||||||||||
| 50 | # a DateTime object. | ||||||||||
| 51 | #-------------------------------------------------------- | ||||||||||
| 52 | 0 | ▶ | sub fromDateTime($) { | ||||||||
|
Subroutine
fromDateTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 0 | my $self = shift->new(); | |||||||||
| 54 | 0 | $self->setFromDateTime(shift); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | #-------------------------------------------------------- | ||||||||||
| 58 | # sets the value from a DateTime object. | ||||||||||
| 59 | #-------------------------------------------------------- | ||||||||||
| 60 | 0 | ▶ | sub setFromDateTime($) { | ||||||||
|
Subroutine
setFromDateTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 61 | 0 | my $self = shift; | |||||||||
| 62 | 0 | my $dt = shift; | |||||||||
| 63 | |||||||||||
| 64 | 0 | require DateTime; | |||||||||
| 65 | 0 | require DateTime::Format::W3CDTF; | |||||||||
| 66 | |||||||||||
| 67 | 0 | my $f = DateTime::Format::W3CDTF->new; | |||||||||
| 68 | 0 | $self->value($f->format_date($dt)); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | #-------------------------------------------------------- | ||||||||||
| 74 | # OVERRIDDEN from XML::Pastor::SimpleType | ||||||||||
| 75 | #-------------------------------------------------------- | ||||||||||
| 76 | 0 | ▶ | sub xml_validate_further { | ||||||||
|
Subroutine
xml_validate_further: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | my $self = shift; | |||||||||
| 78 | 0 | my $value = $self->__value; | |||||||||
| 79 | |||||||||||
| 80 | 0 | $value =~ /^[-]?(\d{4,})-(\d\d)-(\d\d)/; | |||||||||
| 81 | 0 | return validate_date($1, $2, $3); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | 10 | 1; | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||