use strict;
use warnings;
-our $VERSION = '0.04';
+our $VERSION = '0.08';
use base qw( DBIx::Class );
use DateTime;
-__PACKAGE__->load_components( qw/InflateColumn::DateTime/ );
+__PACKAGE__->load_components( qw( InflateColumn::DateTime ) );
+
+# back compat
+sub add_columns {
+ my( $class, @cols ) = @_;
+ my @columns;
+
+ while (my $col = shift @cols) {
+ my $info = ref $cols[0] ? shift @cols : {};
+
+ 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( @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 || (exists $info->{ inflate_datetime } && $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 || (exists $info->{ inflate_datetime } && $info->{ inflate_datetime } eq 'epoch');
return $value->epoch;
}
=head1 METHODS
+=head2 add_columns( )
+
+Provides backwards compatibility with the older DateTime::Epoch API.
+
=head2 _inflate_to_datetime( )
Overrides column inflation to use C<Datetime-E<gt>from_epoch>.
=over 4
-=item * DBIx::Class
+=item * L<DBIx::Class>
-=item * DBIx::Class::TimeStamp
+=item * L<DBIx::Class::TimeStamp>
-=item * DateTime
+=item * L<DateTime>
=back
=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.