[Bast-commits] r4817 -
DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Thu Sep 18 18:11:08 BST 2008
Author: rafl
Date: 2008-09-18 18:11:08 +0100 (Thu, 18 Sep 2008)
New Revision: 4817
Modified:
DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm
Log:
Make the triggers set the col values themself.
Modified: DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm
===================================================================
--- DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm 2008-09-17 06:57:36 UTC (rev 4816)
+++ DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm 2008-09-18 17:11:08 UTC (rev 4817)
@@ -62,13 +62,19 @@
for my $column ($self->columns) {
my $info = $self->column_info($column);
- my $update_trigger = $info->{dynamic_default_on_update};
- push @update_columns, [$column => $update_trigger, $info->{always_update} || 0]
- if $update_trigger;
+ my $accessor = $info->{accessor} || $column;
- my $create_trigger = $info->{dynamic_default_on_create};
- push @create_columns, [$column => $create_trigger]
- if $create_trigger;
+ my $update_meth = $info->{dynamic_default_on_update};
+ push @update_columns, [$column => sub {
+ my $row = shift;
+ $row->$accessor( $row->$update_meth );
+ }, $info->{always_update} || 0] if $update_meth;
+
+ my $create_meth = $info->{dynamic_default_on_create};
+ push @create_columns, [$column => sub {
+ my $row = shift;
+ $row->$accessor( $row->$create_meth );
+ }] if $create_meth;
}
if (@update_columns || @create_columns) {
@@ -88,10 +94,7 @@
next if defined $self->get_column($column_name);
my $meth = $column->[1];
- my $default_value = $self->$meth;
-
- my $accessor = $self->column_info($column_name)->{accessor} || $column_name;
- $self->$accessor($default_value);
+ $self->$meth;
}
return $self->next::method(@_);
@@ -110,11 +113,8 @@
next if exists $dirty{$column_name};
my $meth = $column->[1];
- my $default_value = $self->$meth;
+ $self->$meth;
- my $accessor = $self->column_info($column_name)->{accessor} || $column_name;
- $self->$accessor($default_value);
-
$dirty{$column_name} = 1;
}
More information about the Bast-commits
mailing list