From: Brian Cassidy Date: Mon, 1 Jun 2009 14:42:52 +0000 (-0300) Subject: a little better back-compat X-Git-Tag: 0.05^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=339c4caaefb306c5d0eb7c8ccff93ed927feaf0f;p=dbsrgits%2FDBIx-Class-DateTime-Epoch.git a little better back-compat --- diff --git a/lib/DBIx/Class/DateTime/Epoch.pm b/lib/DBIx/Class/DateTime/Epoch.pm index f392c91..a719233 100644 --- a/lib/DBIx/Class/DateTime/Epoch.pm +++ b/lib/DBIx/Class/DateTime/Epoch.pm @@ -9,23 +9,31 @@ use base qw( DBIx::Class ); use DateTime; -__PACKAGE__->load_components( qw( DynamicDefault InflateColumn::DateTime ) ); +__PACKAGE__->load_components( qw( InflateColumn::DateTime ) ); # back compat -sub register_column { - my( $class, $col, $info ) = @_; +sub add_columns { + my( $class, @cols ) = @_; + my @columns; - if( my $type = delete $info->{ epoch } ) { - $info->{ inflate_datetime } = 'epoch'; + while (my $col = shift @cols) { + my $info = ref $cols[0] ? shift @cols : {}; - if( $type =~ m{^[cm]time$} ) { - __PACKAGE__->load_components( 'TimeStamp' ); - $info->{ dynamic_default_on_create } = 'get_timestamp'; - $info->{ dynamic_default_on_update } = 'get_timestamp' if $type eq 'mtime'; + if( my $type = delete $info->{ epoch } ) { + $info->{ inflate_datetime } = 'epoch'; + + if( $type =~ m{^[cm]time$} ) { + __PACKAGE__->load_components( 'TimeStamp' ); + $info->{ set_on_create } = 1; + $info->{ set_on_update } = 1 if $type eq 'mtime'; + } } + + push @columns, $col => $info; + } - $class->next::method( $col, $info ); + $class->next::method( @columns ); } sub _inflate_to_datetime { @@ -110,6 +118,10 @@ modifications. =head1 METHODS +=head2 add_columns( ) + +Provides backwards compatibility with the older DateTime::Epoch API. + =head2 _inflate_to_datetime( ) Overrides column inflation to use Cfrom_epoch>.