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 => 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) = @_;
+    my $retval;
+    $self->txn_do( sub {
+                  $self->{deferred_exceptions} = [];
+                  $retval = $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) = @_;
+    push @{$self->{deferred_exceptions}}, $msg;
+  }
+
 =cut

 sub txn_do {

Attachment: dbic-deferred-exceptions-doc.patch
Description: Binary data

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to