[Dbix-class] schema deferred exception documentation patch
Bob MacCallum
uncoolbob at gmail.com
Mon May 21 14:50:48 GMT 2012
Hi,
mst helped me solve a little problem (thanks) and he suggested I
contribute a doc patch - I hope this is what he meant.
If you think the patch requires an explanation of *why* you would want
to do this (getting a single list of errors when loading a large chunk
of data is better than going through multiple rounds of fixing errors)
then I can add something to that effect.
cheers,
Bob.
(patch also attached (gmail will probably mangle the long lines))
% diff -ur DBIx-Class-0.08196 DBIx-Class-0.08196-docpatch
diff -ur DBIx-Class-0.08196/lib/DBIx/Class/Schema.pm
DBIx-Class-0.08196-docpatch/lib/DBIx/Class/Schema.pm
--- DBIx-Class-0.08196/lib/DBIx/Class/Schema.pm 2011-11-29
05:15:48.000000000 +0000
+++ DBIx-Class-0.08196-docpatch/lib/DBIx/Class/Schema.pm 2012-05-21
15:32:49.000000000 +0100
@@ -649,6 +649,33 @@
Connecting with C<< AutoCommit =3D> 1 >> is recommended.
+Using nested calls of txn_do as outlined below, it is possible to
+defer exceptions (e.g. from which a temporary recovery might be
+possible) until the end of the transaction.
+
+ package My::Schema;
+ # ...
+ sub txn_do_deferred {
+ my ($self, $coderef, @args) =3D @_;
+ my $retval;
+ $self->txn_do( sub {
+ $self->{deferred_exceptions} =3D [];
+ $retval =3D $self->txn_do($coderef, @args);
+ if (@{$self->{deferred_exceptions}}) {
+ warn "The following deferred exceptions were encountered:\n ".
+ join("\n ", @{$self->{deferred_exceptions}})."\nRolling back..=
.\n";
+ $self->txn_rollback();
+ }
+ }
+ );
+ return $retval;
+ }
+
+ sub defer_exception {
+ my ($self, $msg) =3D @_;
+ push @{$self->{deferred_exceptions}}, $msg;
+ }
+
=3Dcut
sub txn_do {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbic-deferred-exceptions-doc.patch
Type: application/octet-stream
Size: 1202 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120521/5d=
d3e343/dbic-deferred-exceptions-doc.obj
More information about the DBIx-Class
mailing list