[Bast-commits] r4818 -
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:32 BST 2008
Author: rafl
Date: 2008-09-18 18:11:32 +0100 (Thu, 18 Sep 2008)
New Revision: 4818
Modified:
DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm
Log:
Some simplifications.
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-18 17:11:08 UTC (rev 4817)
+++ DBIx-Class-DynamicDefault/1.000/trunk/lib/DBIx/Class/DynamicDefault.pm 2008-09-18 17:11:32 UTC (rev 4818)
@@ -56,31 +56,26 @@
$self->next::method(@_);
- my @update_columns;
- my @create_columns;
+ my %triggers = map { $_ => [] } qw/update create/;
for my $column ($self->columns) {
my $info = $self->column_info($column);
my $accessor = $info->{accessor} || $column;
- 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;
+ for my $op (qw/update create/) {
+ my $meth = $info->{ "dynamic_default_on_${op}" };
+ push @{ $triggers{$op} }, [$column => sub {
+ my $row = shift;
+ $row->$accessor( $row->$meth );
+ }, $op eq 'update' ? ($info->{always_update} || 0) : ()] if $meth;
+ }
}
- if (@update_columns || @create_columns) {
+ if (map { @{ $triggers{$_} } } qw/update create/) {
$self->__column_dynamic_default_triggers({
- on_update => [sort { $b->[2] <=> $a->[2] } @update_columns],
- on_create => \@create_columns,
+ on_update => [sort { $b->[2] <=> $a->[2] } @{ $triggers{update} }],
+ on_create => $triggers{create},
});
}
}
More information about the Bast-commits
mailing list