X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/c73b26581660fe0d06ac40a37a93277018174005..de0f9532013c861dae78aa01b9633284d1ceee7c:/SL/DB/Object.pm diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm old mode 100644 new mode 100755 index a2db47f48..a80640cad --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -9,6 +9,7 @@ use SL::DB; use SL::DB::Helper::Attr; use SL::DB::Helper::Metadata; use SL::DB::Helper::Manager; +use SL::DB::Object::Hooks; use base qw(Rose::DB::Object); @@ -94,6 +95,47 @@ sub call_sub_if { return $check ? $self->$sub(@_) : $self; } +# These three functions cannot sit in SL::DB::Object::Hooks because +# mixins don't deal well with super classes (SUPER is the current +# package's super class, not $self's). +sub load { + my ($self, @args) = @_; + + SL::DB::Object::Hooks::run_hooks($self, 'before_load'); + my $result = $self->SUPER::load(@args); + SL::DB::Object::Hooks::run_hooks($self, 'after_load', $result); + + return $result; +} + +sub save { + my ($self, @args) = @_; + + my $result; + my $worker = sub { + SL::DB::Object::Hooks::run_hooks($self, 'before_save'); + $result = $self->SUPER::save(@args); + SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); + }; + + $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); + return $result; +} + +sub delete { + my ($self, @args) = @_; + + my $result; + my $worker = sub { + SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); + $result = $self->SUPER::delete(@args); + SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); + }; + + $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); + return $result; +} + 1; __END__