Revision 17e54707
Von Moritz Bunkus vor etwa 13 Jahren hinzugefügt
SL/DB/Object.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use English qw(-no_match_vars); |
|
5 | 6 |
use Rose::DB::Object; |
6 | 7 |
use List::MoreUtils qw(any); |
7 | 8 |
|
... | ... | |
111 | 112 |
sub save { |
112 | 113 |
my ($self, @args) = @_; |
113 | 114 |
|
114 |
my $result;
|
|
115 |
my ($result, $exception);
|
|
115 | 116 |
my $worker = sub { |
116 | 117 |
SL::DB::Object::Hooks::run_hooks($self, 'before_save'); |
117 |
$result = $self->SUPER::save(@args); |
|
118 |
$exception = $EVAL_ERROR unless eval { |
|
119 |
$result = $self->SUPER::save(@args); |
|
120 |
1; |
|
121 |
}; |
|
118 | 122 |
SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); |
119 | 123 |
}; |
120 | 124 |
|
121 | 125 |
$self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
126 |
|
|
127 |
die $exception if $exception; |
|
128 |
|
|
122 | 129 |
return $result; |
123 | 130 |
} |
124 | 131 |
|
125 | 132 |
sub delete { |
126 | 133 |
my ($self, @args) = @_; |
127 | 134 |
|
128 |
my $result;
|
|
135 |
my ($result, $exception);
|
|
129 | 136 |
my $worker = sub { |
130 | 137 |
SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); |
131 |
$result = $self->SUPER::delete(@args); |
|
138 |
$exception = $EVAL_ERROR unless eval { |
|
139 |
$result = $self->SUPER::delete(@args); |
|
140 |
1; |
|
141 |
}; |
|
132 | 142 |
SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); |
133 | 143 |
}; |
134 | 144 |
|
135 | 145 |
$self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
146 |
|
|
147 |
die $exception if $exception; |
|
148 |
|
|
136 | 149 |
return $result; |
137 | 150 |
} |
138 | 151 |
|
Auch abrufbar als: Unified diff
Exceptions beim Speicher/Löschen von SL::DB-Objekten hochbubblen lassen
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.