if ($self->{_can_do_transactions}) { local $dbh->{AutoCommit} = 0; eval { code_that_touches_db(); $dbh->commit; }; if ($@) { my $msg = $@; eval { $dbh->rollback }; die $msg; } } else { code_that_touches_db(); }