[Bast-commits] r4783 - in trunk/DBIx-Class-TimeStamp: .
lib/DBIx/Class
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Wed Aug 27 01:18:55 BST 2008
Author: rafl
Date: 2008-08-27 01:18:55 +0100 (Wed, 27 Aug 2008)
New Revision: 4783
Modified:
trunk/DBIx-Class-TimeStamp/Makefile.PL
trunk/DBIx-Class-TimeStamp/lib/DBIx/Class/TimeStamp.pm
Log:
Port to DBIx::Class::DynamicDefault.
Modified: trunk/DBIx-Class-TimeStamp/Makefile.PL
===================================================================
--- trunk/DBIx-Class-TimeStamp/Makefile.PL 2008-08-27 00:08:38 UTC (rev 4782)
+++ trunk/DBIx-Class-TimeStamp/Makefile.PL 2008-08-27 00:18:55 UTC (rev 4783)
@@ -5,6 +5,7 @@
requires 'DateTime';
requires 'DBIx::Class';
+requires 'DBIx::Class::DynamicDefault';
build_requires 'DateTime::Format::MySQL';
build_requires 'Class::Accessor::Grouped';
Modified: trunk/DBIx-Class-TimeStamp/lib/DBIx/Class/TimeStamp.pm
===================================================================
--- trunk/DBIx-Class-TimeStamp/lib/DBIx/Class/TimeStamp.pm 2008-08-27 00:08:38 UTC (rev 4782)
+++ trunk/DBIx-Class-TimeStamp/lib/DBIx/Class/TimeStamp.pm 2008-08-27 00:18:55 UTC (rev 4783)
@@ -9,12 +9,7 @@
our $VERSION = '0.04';
-__PACKAGE__->load_components( qw/InflateColumn::DateTime/ );
-__PACKAGE__->mk_classdata(
- '__column_timestamp_triggers' => {
- on_update => [], on_create => []
- }
-);
+__PACKAGE__->load_components( qw/DynamicDefault InflateColumn::DateTime/ );
=head1 NAME
@@ -47,63 +42,25 @@
=cut
sub add_columns {
- my $self = shift;
+ my ($self, @cols) = @_;
+ my @columns;
- # Add everything else, get everything setup, and then process
- $self->next::method(@_);
-
- my @update_columns = ();
- my @create_columns = ();
+ while (my $col = shift @cols) {
+ my $info = ref $cols[0] ? shift @cols : {};
- foreach my $column ( $self->columns ) {
- my $info = $self->column_info($column);
if ( $info->{data_type} =~ /^(datetime|date|timestamp)$/i ) {
- if ( $info->{set_on_update} ) {
- push @update_columns, $column;
+ if ( delete $info->{set_on_update} ) {
+ $info->{dynamic_default_on_update} = 'get_timestamp';
}
- if ( $info->{set_on_create} ) {
- push @create_columns, $column;
+ if ( delete $info->{set_on_create} ) {
+ $info->{dynamic_default_on_create} = 'get_timestamp';
}
}
- }
- if ( @update_columns or @create_columns ) {
- my $triggers = {
- on_update => [ @update_columns ],
- on_create => [ @create_columns ],
- };
- $self->__column_timestamp_triggers($triggers);
- }
-}
-sub insert {
- my $self = shift;
- my $attrs = shift;
-
- my $now = $self->get_timestamp();
-
- my @columns = @{ $self->__column_timestamp_triggers()->{on_create} };
-
- foreach my $column ( @columns ) {
- next if defined $self->get_column( $column );
- $self->$column($now);
+ push @columns, $col => $info;
}
-
- return $self->next::method(@_);
-}
-sub update {
- my $self = shift;
-
- my $now = $self->get_timestamp();
- my %dirty = $self->get_dirty_columns();
- my @columns = @{ $self->__column_timestamp_triggers()->{on_update} };
-
- foreach my $column ( @columns ) {
- next if exists $dirty{ $column };
- $self->$column($now);
- }
-
- return $self->next::method(@_);
+ return $self->next::method(@columns);
}
=head1 METHODS
More information about the Bast-commits
mailing list