From: Bryan Beeley Date: Mon, 1 Feb 2010 22:42:14 +0000 (+0000) Subject: - Add _post_inflate_datetime and _pre_deflate_datetime to InflateColumn::DateTime... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f856fe014648742bda7017b504e743803404efcb;p=dbsrgits%2FDBIx-Class-Historic.git - Add _post_inflate_datetime and _pre_deflate_datetime to InflateColumn::DateTime to allow for modifying DateTime objects after inflation or before deflation. --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index ad01126..7b09ebd 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -227,6 +227,8 @@ blblack: Brandon L. Black bluefeet: Aran Deltac +boghead: Bryan Beeley + bricas: Brian Cassidy brunov: Bruno Vecchi diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 50c66a1..0966657 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -178,21 +178,12 @@ sub register_column { $self->throw_exception ("Error while inflating ${value} for ${column} on ${self}: $err"); } - $dt->set_time_zone($timezone) if $timezone; - $dt->set_locale($locale) if $locale; - return $dt; + return $obj->_post_inflate_datetime( $dt, \%info ); }, deflate => sub { my ($value, $obj) = @_; - if ($timezone) { - carp "You're using a floating timezone, please see the documentation of" - . " DBIx::Class::InflateColumn::DateTime for an explanation" - if ref( $value->time_zone ) eq 'DateTime::TimeZone::Floating' - and not $info{floating_tz_ok} - and not $ENV{DBIC_FLOATING_TZ_OK}; - $value->set_time_zone($timezone); - $value->set_locale($locale) if $locale; - } + + $value = $obj->_pre_deflate_datetime( $value, \%info ); $obj->_deflate_from_datetime( $value, \%info ); }, } @@ -224,6 +215,65 @@ sub _datetime_parser { shift->result_source->storage->datetime_parser (@_); } +sub _post_inflate_datetime { + my( $self, $dt, $info ) = @_; + + my $timezone; + if (exists $info->{timezone}) { + $timezone = $info->{timezone}; + } + elsif (exists $info->{extra} and exists $info->{extra}{timezone}) { + $timezone = $info->{extra}{timezone}; + } + + my $locale; + if (exists $info->{locale}) { + $locale = $info->{locale}; + } + elsif (exists $info->{extra} and exists $info->{extra}{locale}) { + $locale = $info->{extra}{locale}; + } + + $dt->set_time_zone($timezone) if $timezone; + $dt->set_locale($locale) if $locale; + + return $dt; +} + +sub _pre_deflate_datetime { + my( $self, $dt, $info ) = @_; + + my $timezone; + if (exists $info->{timezone}) { + $timezone = $info->{timezone}; + } + elsif (exists $info->{extra} and exists $info->{extra}{timezone}) { + $timezone = $info->{extra}{timezone}; + } + + my $locale; + if (exists $info->{locale}) { + $locale = $info->{locale}; + } + elsif (exists $info->{extra} and exists $info->{extra}{locale}) { + $locale = $info->{extra}{locale}; + } + + if ($timezone) { + carp "You're using a floating timezone, please see the documentation of" + . " DBIx::Class::InflateColumn::DateTime for an explanation" + if ref( $dt->time_zone ) eq 'DateTime::TimeZone::Floating' + and not $info->{floating_tz_ok} + and not $ENV{DBIC_FLOATING_TZ_OK}; + + $dt->set_time_zone($timezone); + } + + $dt->set_locale($locale) if $locale; + + return $dt; +} + 1; __END__