test tweaks and a bugfix
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / AutoUpdate.pm
CommitLineData
a3018bd3 1package DBIx::Class::CDBICompat::AutoUpdate;
2
3use strict;
4use warnings;
5
6use base qw/Class::Data::Inheritable/;
7
8__PACKAGE__->mk_classdata('__AutoCommit');
9
10sub set {
11 my $self = shift;
12 $self->NEXT::set(@_);
13 $self->update if ($self->autoupdate && $self->{_in_database});
14}
15
16sub autoupdate {
17 my $proto = shift;
18 ref $proto
19 ? $proto->_obj_autoupdate(@_)
20 : $proto->_class_autoupdate(@_) ;
21}
22
23sub _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
32sub _class_autoupdate {
33 my ($class, $set) = @_;
34 $class->__AutoCommit($set) if defined $set;
35 return $class->__AutoCommit;
36}
37
381;