our $VERSION = '0.10';
-__PACKAGE__->mk_classdata(
- '__column_userstamp_triggers' => {
- on_update => [], on_create => []
- }
-);
+__PACKAGE__->load_components( qw/DynamicDefault/ );
=head1 NAME
=cut
sub add_columns {
- my $self = shift;
-
- # Add everything else, get everything setup, and then process
- $self->next::method(@_);
-
- my @update_columns = ();
- my @create_columns = ();
-
- foreach my $column ( $self->columns ) {
- my $info = $self->column_info($column);
- if ( $info->{store_user_on_update} ) {
- push @update_columns, $column;
- }
- if ( $info->{store_user_on_create} ) {
- push @create_columns, $column;
- }
- }
- if ( @update_columns or @create_columns ) {
- my $triggers = {
- on_update => [ @update_columns ],
- on_create => [ @create_columns ],
- };
- $self->__column_userstamp_triggers($triggers);
- }
-}
-
-sub insert {
- my $self = shift;
- my $attrs = shift;
+ my ($self, @cols) = @_;
+ my @columns;
- my $user_id = $self->get_current_user_id;
+ while (my $col = shift @cols) {
+ my $info = ref $cols[0] ? shift @cols : {};
- my @columns = @{ $self->__column_userstamp_triggers()->{on_create} };
-
- foreach my $column ( @columns ) {
- next if defined $self->get_column( $column );
- my $accessor = $self->column_info($column)->{accessor} || $column;
- $self->$accessor($user_id);
- }
-
- return $self->next::method(@_);
-}
-
-sub update {
- my $self = shift;
-
- my $user_id = $self->get_current_user_id;
- my %dirty = $self->get_dirty_columns();
- my @columns = @{ $self->__column_userstamp_triggers()->{on_update} };
+ if ( delete $info->{store_user_on_update} ) {
+ $info->{dynamic_default_on_update} = 'get_current_user_id';
+ }
+ if ( delete $info->{store_user_on_create} ) {
+ $info->{dynamic_default_on_create} = 'get_current_user_id';
+ }
- foreach my $column ( @columns ) {
- next if exists $dirty{ $column };
- my $accessor = $self->column_info($column)->{accessor} || $column;
- $self->$accessor($user_id);
+ push @columns, $col => $info;
}
- return $self->next::method(@_);
+ return $self->next::method(@columns);
}
=head1 METHODS