X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDateTime%2FEpoch.pm;h=ec857f81a7d9ef4ac7e3f56bc5dceffffd041cdb;hb=b7f6b6adc44f4bee02eeb295eea5632d39c391f6;hp=f392c916775d95171c940fb7295380bb69014f14;hpb=29f37a29ee0497500d375de134ae39798f75ead8;p=dbsrgits%2FDBIx-Class-DateTime-Epoch.git diff --git a/lib/DBIx/Class/DateTime/Epoch.pm b/lib/DBIx/Class/DateTime/Epoch.pm index f392c91..ec857f8 100644 --- a/lib/DBIx/Class/DateTime/Epoch.pm +++ b/lib/DBIx/Class/DateTime/Epoch.pm @@ -3,43 +3,51 @@ package DBIx::Class::DateTime::Epoch; use strict; use warnings; -our $VERSION = '0.05'; +our $VERSION = '0.07'; 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 { my( $self, $value, $info, @rest ) = @_; - $self->next::method( $value, $info, @rest ) - unless $info->{ data_type } =~ m{int} || $info->{ inflate_datetime } eq 'epoch'; + return $self->next::method( $value, $info, @rest ) + unless $info->{ data_type } =~ m{int}i || $info->{ inflate_datetime } eq 'epoch'; return DateTime->from_epoch( epoch => $value ); } sub _deflate_from_datetime { my( $self, $value, $info, @rest ) = @_; - $self->next::method( $value, $info, @rest ) - unless $info->{ data_type } =~ m{int} || $info->{ inflate_datetime } eq 'epoch'; + return $self->next::method( $value, $info, @rest ) + unless $info->{ data_type } =~ m{int}i || $info->{ inflate_datetime } eq 'epoch'; return $value->epoch; } @@ -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>. @@ -122,11 +134,11 @@ Overrides column deflation to call C on the column value. =over 4 -=item * DBIx::Class +=item * L -=item * DBIx::Class::TimeStamp +=item * L -=item * DateTime +=item * L =back @@ -138,7 +150,7 @@ Adam Paynter Eadapay@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Brian Cassidy +Copyright 2006-2011 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.