| 1 | package Yahoo::Marketing::DateTimeAccessor; | ||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2009 Yahoo! Inc. All rights reserved. | ||||||||||||||||||||||||||||
| 3 | # The copyrights to the contents of this file are licensed under the Perl Artistic License (ver. 15 Aug 1997) | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 165 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 165 | ▶ | use base qw/ Class::Accessor::Chained /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 165 | ▶ | use DateTime::Format::W3CDTF; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 165 | ▶ | use DateTime::Format::ISO8601; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 39 | ▶ | sub _force_datetime_object { | ||||||||||||||||||||||||||
|
Subroutine
_force_datetime_object: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 12 | 39 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 39 | ▶ | if( defined $value ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 39 | ▶ | unless( ref $value ){ # not a date time object | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 39 | $value = DateTime::Format::ISO8601->new->parse_datetime( $value ); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | # let's hope it looks like a duck... er, DateTime object | ||||||||||||||||||||||||||||
| 19 | 39 | $value->set_formatter( DateTime::Format::W3CDTF->new ); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 39 | return $value; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 619 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 619 | my ( $self, $key, @values ) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 619 | ▶ | if ( $key =~ /Date$/ || $key =~ /Timestamp$/ ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key =~ /Date$/ or $key =~ /Timestamp$/
MC/DC100%2/2
$key =~ /Date$/ or $key =~ /Timestamp$/
$key =~ /Date$/
$key =~ /Timestamp$/
Truth table100%3/3
A or B
A= $key =~ /Date$/B= $key =~ /Timestamp$/
| |||||||||||||||||||||||||||||
| 29 | 39 | @values = map { $self->_force_datetime_object( $_ ) } @values; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 619 | $self->SUPER::set( $key, @values ); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 165 | 1; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||||||||||