Commit | Line | Data |
a3018bd3 |
1 | package DBIx::Class::CDBICompat::AutoUpdate; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base qw/Class::Data::Inheritable/; |
7 | |
8 | __PACKAGE__->mk_classdata('__AutoCommit'); |
9 | |
10 | sub set { |
11 | my $self = shift; |
12 | $self->NEXT::set(@_); |
13 | $self->update if ($self->autoupdate && $self->{_in_database}); |
14 | } |
15 | |
16 | sub autoupdate { |
17 | my $proto = shift; |
18 | ref $proto |
19 | ? $proto->_obj_autoupdate(@_) |
20 | : $proto->_class_autoupdate(@_) ; |
21 | } |
22 | |
23 | sub _obj_autoupdate { |
24 | my ($self, $set) = @_; |
25 | my $class = ref $self; |
26 | $self->{__AutoCommit} = $set if defined $set; |
27 | defined $self->{__AutoCommit} |
28 | ? $self->{__AutoCommit} |
29 | : $class->_class_autoupdate; |
30 | } |
31 | |
32 | sub _class_autoupdate { |
33 | my ($class, $set) = @_; |
34 | $class->__AutoCommit($set) if defined $set; |
35 | return $class->__AutoCommit; |
36 | } |
37 | |
38 | 1; |