DBIx-Class-DynamicDefault
view release on metacpan or search on metacpan
lib/DBIx/Class/DynamicDefault.pm view on Meta::CPAN
$self->$accessor($default_value);
}
return $self->next::method(@_);
}
sub update {
my ($self, $upd) = @_;
$self->set_inflated_columns($upd) if $upd;
my %dirty = $self->get_dirty_columns;
my @columns = @{ $self->__column_dynamic_default_triggers->{on_update} };
for my $column (@columns) {
my $column_name = $column->[0];
next if !%dirty && !$column->[2];
next if exists $dirty{$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);
$dirty{$column_name} = 1;
}
return $self->next::method;
}
=head1 OPTIONS
=head2 dynamic_default_on_create
dynamic_default_on_create => sub { ... }
dynamic_default_on_create => 'method_name'
When inserting a new row all columns with the C<dynamic_default_on_create>
option will be set to the return value of the specified callback unless the
columns value has been explicitly set. The callback, that'll be invoked with
the row object as its only argument, may be a code reference or a method name.
=head2 dynamic_default_on_update
dynamic_default_on_update => sub { ... }
dynamic_default_on_update => 'method_name'
When updating a row all columns with the C<dynamic_default_on_update> option
will be set to the return value of the specified callback unless the columns
value has been explicitly set.
Columns will only be altered if other dirty columns exist. See C<always_update>
on how to change this.
=head2 always_update
always_update => 1
When setting C<always_update> to 1 C<dynamic_default_on_update> callbacks will
always be invoked, even if no other columns are dirty.
=head1 AUTHOR
Florian Ragwitz E<lt>rafl@debian.orgE<gt>
=head1 LICENSE
This software is copyright (c) 2008 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under
the same terms as perl itself.
=cut
1;
( run in 0.595 second using v1.01-cache-2.11-cpan-140bd7fdf52 )