From c93959e34732b37db8784732cfafe121ddf5e831 Mon Sep 17 00:00:00 2001 From: Noel Maddy Date: Wed, 10 Jun 2015 08:23:02 -0600 Subject: [PATCH] Add docs on extending InflateColumn::DateTime --- lib/DBIx/Class/InflateColumn/DateTime.pm | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 7abf5acfe..2ed7ab4c7 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -297,6 +297,88 @@ B because this gets you into trouble using Lnext::method($dt, $info); + ... + return $dt; + } + +=head2 _post_inflate_datetime method + +This method is called to process the DateTime object after it has been +inflated from the database representation. If an explicit timezone or +locale habe been set for the column, those are applied to the DateTime +by this method after inflation. + +To extend, wrap the method: + + sub _post_inflate_datetime method + my ( $self, $dt, $info ) = @_; + ... + $dt = $self->next::method($dt, $info); + ... + return $dt; + } + +=head2 _ic_dt_method attribute + +The type of datetime data stored in the column is available in C<$info>, +set by the C method. This allows extensions to change +behavior depending on the type of datetime being processed. + +Available values, with their origins: + +=over + +=item timestamp_with_timezone + +SQL datatype "timestamp with time zone", or "timestamptz" + +=item timestamp_without_timezone + +SQL datatype "timestamp without time zone" + +=item smalldatetime + +SQL datatype "smalldatetime" + +=item datetime + +SQL datatype "datetime", or C attribute set on column + +=item timestamp + +SQL datatype "timestamp", or C attribute set on column + +=item date + +SQL datatype "date", or C attribute set on column + +=back + + my $date_method = $info->{_ic_dt_method}; + +=head2 __dbic_colname attribute + +The column name is available in the copy of C<$info> that is passed to +all of the inflation and deflation methods. This allows error messages +to use the column name. + + my $colname = $info->{__dbic_colname}; + =head1 SEE ALSO =over 4