X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FInflateColumn%2FDateTime.pm;h=e1c5de76793ab95bce1ef8f84f7bc0152e4c5c5d;hp=a650d69b83ba30e09974d35b5cacac821d1bd59a;hb=33a126efc599d5bb1284929ba2c80527c5bd0951;hpb=ec7eb955621dd50dbc9a239f54b0d547b2ea9102 diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index a650d69..e1c5de7 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -53,6 +53,18 @@ Chains with the L method, and sets up datetime columns appropriately. This would not normally be directly called by end users. +In the case of an invalid date, L will throw an exception. To +bypass these exceptions and just have the inflation return undef, use +the C option in the column info: + + "broken_date", + { + data_type => "datetime", + default_value => '0000-00-00', + is_nullable => 1, + datetime_undef_if_invalid => 1 + } + =cut sub register_column { @@ -73,7 +85,8 @@ sub register_column { { inflate => sub { my ($value, $obj) = @_; - my $dt = $obj->_datetime_parser->$parse($value); + my $dt = eval { $obj->_datetime_parser->$parse($value); }; + die "Error while inflating ${value} for ${column} on ${self}: $@" if $@ and not $info->{datetime_undef_if_invalid}; $dt->set_time_zone($timezone) if $timezone; return $dt; },