From 17e547071d67a5063e3067b1dd72035c0192bacb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 2 Nov 2011 16:34:05 +0100 Subject: [PATCH] =?utf8?q?Exceptions=20beim=20Speicher/L=C3=B6schen=20von?= =?utf8?q?=20SL::DB-Objekten=20hochbubblen=20lassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die R::DB::O::transaction()-Funktion clobbert Exceptions irgendwie. Deshalb diese erneut werfen, sofern sie beim Speichern auftreten, und nicht nur einen Fehler zurückliefern. --- SL/DB/Object.pm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index a80640cad..d1e6cb0aa 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -2,6 +2,7 @@ package SL::DB::Object; use strict; +use English qw(-no_match_vars); use Rose::DB::Object; use List::MoreUtils qw(any); @@ -111,28 +112,40 @@ sub load { sub save { my ($self, @args) = @_; - my $result; + my ($result, $exception); my $worker = sub { SL::DB::Object::Hooks::run_hooks($self, 'before_save'); - $result = $self->SUPER::save(@args); + $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; + my ($result, $exception); my $worker = sub { SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); - $result = $self->SUPER::delete(@args); + $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; } -- 2.20.1