=head1 SYNOPSIS use Transactions; my $dbh = DBI->connect(...); our $T = $dbh;
Instead of using a global variable in the caller's package, I wonder if it mightn't be better to pass a reference to the variable to be used into the module when it's use'ed, like so:
package Transactions; our $Object; sub import { my $class = shift; $Object = shift; # somehow fall back to Exporter::Tidy? # goto &Exporter::Tidy::import; maybe? } ... sub transaction(&) { ... eval { $$Object->begin_work(); # double $ because it's a ref-to-a-ref $block->(); } ... } =head1 SYNOPSIS my $dbh = DBI->connect(...); use Transactions \$dbh; transaction { for (1..10) { my $sth = $dbh->prepare(...); $sth->execute() or rollback; } }; ...
Just a thought. :) Of course, it makes it a little bit harder to integrate with Exporter::Tidy. *shrug*
bbfu
Black flowers blossom
Fearless on my breath
In reply to Re: RFC: Transactions.pm
by bbfu
in thread RFC: Transactions.pm
by Juerd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |