+# 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, $exception);
+ my $worker = sub {
+ SL::DB::Object::Hooks::run_hooks($self, 'before_save');
+ $exception = $EVAL_ERROR unless eval {
+ $result = $self->SUPER::save(@args);
+ 1;
+ };
+ SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result);
+ };
+
+ $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+
+ die $exception if $exception;
+
+ return $result;
+}
+
+sub delete {
+ my ($self, @args) = @_;
+
+ my ($result, $exception);
+ my $worker = sub {
+ SL::DB::Object::Hooks::run_hooks($self, 'before_delete');
+ $exception = $EVAL_ERROR unless eval {
+ $result = $self->SUPER::delete(@args);
+ 1;
+ };
+ SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result);
+ };
+
+ $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+
+ die $exception if $exception;
+
+ return $result;
+}
+