[Bast-commits] r4774 - in DBIx-Class-UserStamp/1.000/trunk: .
lib/DBIx/Class
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Tue Aug 26 05:03:19 BST 2008
Author: rafl
Date: 2008-08-26 05:03:18 +0100 (Tue, 26 Aug 2008)
New Revision: 4774
Modified:
DBIx-Class-UserStamp/1.000/trunk/Makefile.PL
DBIx-Class-UserStamp/1.000/trunk/lib/DBIx/Class/UserStamp.pm
Log:
Port to DBIx::Class::DynamicDefault.
Modified: DBIx-Class-UserStamp/1.000/trunk/Makefile.PL
===================================================================
--- DBIx-Class-UserStamp/1.000/trunk/Makefile.PL 2008-08-26 01:36:09 UTC (rev 4773)
+++ DBIx-Class-UserStamp/1.000/trunk/Makefile.PL 2008-08-26 04:03:18 UTC (rev 4774)
@@ -4,6 +4,7 @@
all_from 'lib/DBIx/Class/UserStamp.pm';
requires 'DBIx::Class';
+requires 'DBIx::Class::DynamicDefault';
build_requires 'Class::Accessor::Grouped';
Modified: DBIx-Class-UserStamp/1.000/trunk/lib/DBIx/Class/UserStamp.pm
===================================================================
--- DBIx-Class-UserStamp/1.000/trunk/lib/DBIx/Class/UserStamp.pm 2008-08-26 01:36:09 UTC (rev 4773)
+++ DBIx-Class-UserStamp/1.000/trunk/lib/DBIx/Class/UserStamp.pm 2008-08-26 04:03:18 UTC (rev 4774)
@@ -7,11 +7,7 @@
our $VERSION = '0.10';
-__PACKAGE__->mk_classdata(
- '__column_userstamp_triggers' => {
- on_update => [], on_create => []
- }
-);
+__PACKAGE__->load_components( qw/DynamicDefault/ );
=head1 NAME
@@ -64,63 +60,23 @@
=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->{store_user_on_update} ) {
- push @update_columns, $column;
+ if ( delete $info->{store_user_on_update} ) {
+ $info->{dynamic_default_on_update} = 'get_current_user_id';
}
- if ( $info->{store_user_on_create} ) {
- push @create_columns, $column;
+ if ( delete $info->{store_user_on_create} ) {
+ $info->{dynamic_default_on_create} = 'get_current_user_id';
}
- }
- 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 $user_id = $self->get_current_user_id;
-
- 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);
+ push @columns, $col => $info;
}
-
- 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} };
-
- foreach my $column ( @columns ) {
- next if exists $dirty{ $column };
- my $accessor = $self->column_info($column)->{accessor} || $column;
- $self->$accessor($user_id);
- }
-
- return $self->next::method(@_);
+ return $self->next::method(@columns);
}
=head1 METHODS
More information about the Bast-commits
mailing list