Skip to content

Commit

Permalink
Simplify dbh_do invocation, and only alias @_ when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Jan 21, 2013
1 parent ee204dc commit 6864429
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/DBIx/Class/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions lib/DBIx/Class/Storage/DBI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6864429

Please sign in to comment.