On Thu, Jan 04, 2007 at 11:11:10AM +0000, Ash Berlin wrote:
> $c->model('MyAppDB')->txn_do(sub {
> # Do some insertions here....
> });
Yes, this is pretty much how I do it too, e.g.:
sub _add_new_reply {
my ($self, $c) = @_;
my ($new_reply);
# some checks
# otherwise, the form data is ok ...
else {
# try to add the reply to the thread
eval {
$new_reply = $c->model('ParleyDB')->schema->txn_do(
sub { return $self->_txn_add_new_reply($c) }
);
};
# deal with any transaction errors
if ($@) { # Transaction failed
die "something terrible has happened!" #
if ($@ =~ /Rollback failed/); # Rollback failed
$c->stash->{error}{message} =
qq{Database transaction failed: [EMAIL PROTECTED];
$c->log->error( $@ );
return;
}
}
}
[source: http://xrl.us/t4w3]
and then all the db manipulation goes into "sub _txn_add_new_reply{...}"
I think this is pretty much how the docs recommend to do it. I've not
yet thought of a cleaner way to do this.
Chiz
--
Chisel Wright
e: [EMAIL PROTECTED]
w: http://www.herlpacker.co.uk/
Q: What's tiny and yellow and very, very, dangerous?
A: A canary with the super-user password.
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/