Merge 'trunk' into 'sybase_mssql'
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Triggers.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::Triggers;
fe5d862b 3
cc8d8678 4use strict;
5use warnings;
fe5d862b 6use Class::Trigger;
7
8sub insert {
9 my $self = shift;
e60dc79f 10
11 return $self->create(@_) unless ref $self;
12
fe5d862b 13 $self->call_trigger('before_create');
147dd158 14 $self->next::method(@_);
fe5d862b 15 $self->call_trigger('after_create');
16 return $self;
17}
18
19sub update {
20 my $self = shift;
21 $self->call_trigger('before_update');
22 my @to_update = keys %{$self->{_dirty_columns} || {}};
23 return -1 unless @to_update;
147dd158 24 $self->next::method(@_);
fe5d862b 25 $self->call_trigger('after_update');
26 return $self;
27}
28
29sub delete {
30 my $self = shift;
31 $self->call_trigger('before_delete') if ref $self;
147dd158 32 $self->next::method(@_);
fe5d862b 33 $self->call_trigger('after_delete') if ref $self;
34 return $self;
35}
36
cc8d8678 37sub store_column {
38 my ($self, $column, $value, @rest) = @_;
39 my $vals = { $column => $value };
40 $self->call_trigger("before_set_${column}", $value, $vals);
147dd158 41 return $self->next::method($column, $vals->{$column});
cc8d8678 42}
43
fe5d862b 441;