transaction {
select_handle($dhb);
...
};
Not an option, because you need the handle before you begin the transaction. Won't begin the transaction inside the block, because that would allow stuff to be done outside the transaction while visually, it's in the transaction code block.
Simple to use modules have their limitations. The limitation of this one is that you shouldn't use nested transactions. I think that's acceptable in most cases.
I've only seen nested transactions being used to rollback multiple things. But it's easy to create a wrapper module for that:
package NeedsAName;
sub new { return bless \@_, shift }
sub AUTOLOAD { $_->$AUTOLOAD(@_) for @{+shift}; }
package main;
use Transactions;
my $dbh1 = DBI->connect(...);
my $dbh2 = DBI->connect(...);
our $T = NeedsAName->new($dbh1, $dbh2);
transaction {
...
};
Juerd
# { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }