Commit | Line | Data |
fe5d862b |
1 | package DBIx::Class::CDBICompat::Triggers; |
2 | |
cc8d8678 |
3 | use strict; |
4 | use warnings; |
fe5d862b |
5 | use Class::Trigger; |
6 | |
7 | sub insert { |
8 | my $self = shift; |
9 | $self->call_trigger('before_create'); |
147dd158 |
10 | $self->next::method(@_); |
fe5d862b |
11 | $self->call_trigger('after_create'); |
12 | return $self; |
13 | } |
14 | |
15 | sub update { |
16 | my $self = shift; |
17 | $self->call_trigger('before_update'); |
18 | my @to_update = keys %{$self->{_dirty_columns} || {}}; |
19 | return -1 unless @to_update; |
147dd158 |
20 | $self->next::method(@_); |
fe5d862b |
21 | $self->call_trigger('after_update'); |
22 | return $self; |
23 | } |
24 | |
25 | sub delete { |
26 | my $self = shift; |
27 | $self->call_trigger('before_delete') if ref $self; |
147dd158 |
28 | $self->next::method(@_); |
fe5d862b |
29 | $self->call_trigger('after_delete') if ref $self; |
30 | return $self; |
31 | } |
32 | |
cc8d8678 |
33 | sub store_column { |
34 | my ($self, $column, $value, @rest) = @_; |
35 | my $vals = { $column => $value }; |
36 | $self->call_trigger("before_set_${column}", $value, $vals); |
147dd158 |
37 | return $self->next::method($column, $vals->{$column}); |
cc8d8678 |
38 | } |
39 | |
fe5d862b |
40 | 1; |