in reply to RFC: Transactions.pm
=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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: RFC: Transactions.pm
by Juerd (Abbot) on Apr 28, 2003 at 05:51 UTC | |
by bbfu (Curate) on Apr 28, 2003 at 14:29 UTC | |
by Juerd (Abbot) on Apr 28, 2003 at 15:08 UTC |