f576276f9dca70b3b827282cc104ecb2cf41756b
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / AutoUpdate.pm
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_column {
11   my $self = shift;
12   my $ret = $self->NEXT::set_column(@_);
13   $self->update if ($self->autoupdate && $self->{_in_database});
14   return $ret;
15 }
16
17 sub autoupdate {
18         my $proto = shift;
19         ref $proto
20           ? $proto->_obj_autoupdate(@_)
21           : $proto->_class_autoupdate(@_) ;
22 }
23
24 sub _obj_autoupdate {
25         my ($self, $set) = @_;
26         my $class = ref $self;
27         $self->{__AutoCommit} = $set if defined $set;
28         defined $self->{__AutoCommit}
29                 ? $self->{__AutoCommit}
30                 : $class->_class_autoupdate;
31 }
32
33 sub _class_autoupdate {
34         my ($class, $set) = @_;
35         $class->__AutoCommit($set) if defined $set;
36         return $class->__AutoCommit;
37 }
38
39 1;