From: Peter Rabbitson Date: Mon, 7 Jan 2013 18:45:05 +0000 (-0500) Subject: Simplify dbh_do invocation, and only alias @_ when needed X-Git-Tag: v0.08205~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6864429af43e4ab081343157784d5e00dca7200d;p=dbsrgits%2FDBIx-Class.git Simplify dbh_do invocation, and only alias @_ when needed --- diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index 6e17e9e..6b88d28 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -180,7 +180,10 @@ sub txn_do { DBIx::Class::Storage::BlockRunner->new( storage => $self, run_code => $coderef, - run_args => \@_, # take a ref instead of a copy, to preserve coderef @_ aliasing semantics + run_args => @_ + ? \@_ # take a ref instead of a copy, to preserve @_ aliasing + : [] # semantics within the coderef, but only if needed + , # (pseudoforking doesn't like this trick much) wrap_txn => 1, retry_handler => sub { ! ( $_[0]->retried_count or $_[0]->storage->connected ) }, )->run; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a9a8381..19bc2bc 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -794,11 +794,25 @@ sub dbh_do { return $self->$run_target($self->_get_dbh, @_) if $self->{_in_do_block} or $self->transaction_depth; - my $args = \@_; + my $cref = (ref $run_target eq 'CODE') + ? $run_target + : $self->can($run_target) || $self->throw_exception(sprintf ( + 'Can\'t locate object method "%s" via package "%s"', + $run_target, + (ref $self || $self), + )) + ; + + # take a ref instead of a copy, to preserve @_ aliasing + # semantics within the coderef, but only if needed + # (pseudoforking doesn't like this trick much) + my $args = @_ ? \@_ : []; + unshift @$args, $self, $self->_get_dbh; DBIx::Class::Storage::BlockRunner->new( storage => $self, - run_code => sub { $self->$run_target ($self->_get_dbh, @$args ) }, + run_code => $cref, + run_args => $args, wrap_txn => 0, retry_handler => sub { ! ( $_[0]->retried_count or $_[0]->storage->connected ) }, )->run;