Skip to content

Instantly share code, notes, and snippets.

@bowman
Created February 27, 2012 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bowman/1921289 to your computer and use it in GitHub Desktop.
Save bowman/1921289 to your computer and use it in GitHub Desktop.
DBIx::Connector - allow $pass wrapped in a closure
diff --git lib/DBIx/Connector.pm lib/DBIx/Connector.pm
index 75f4e7d..e330c75 100644
--- lib/DBIx/Connector.pm
+++ lib/DBIx/Connector.pm
@@ -22,22 +22,25 @@ sub DESTROY { $_[0]->disconnect if $_[0]->{_dond} }
sub _connect {
my $self = shift;
+ my @args = @{ $self->{_args} };
+ $args[2] = $args[2]->() if ref $args[2] eq 'CODE'; # reveal wrapped password
+
my $dbh = $self->{_dbh} = do {
if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) {
local $DBI::connect_via = 'connect'; # Disable Apache::DBI.
- DBI->connect( @{ $self->{_args} } );
+ DBI->connect( @args );
} else {
- DBI->connect( @{ $self->{_args} } );
+ DBI->connect( @args );
}
};
# Modify default values.
$dbh->STORE(AutoInactiveDestroy => 1) if DBI->VERSION > 1.613 && (
- @{ $self->{_args} } < 4 || !exists $self->{_args}[3]{AutoInactiveDestroy}
+ @args < 4 || !exists $args[3]{AutoInactiveDestroy}
);
- $dbh->STORE(RaiseError => 1) if @{ $self->{_args} } < 4 || (
- !exists $self->{_args}[3]{RaiseError} && !exists $self->{_args}[3]{HandleError}
+ $dbh->STORE(RaiseError => 1) if @args < 4 || (
+ !exists $args[3]{RaiseError} && !exists $args[3]{HandleError}
);
# Where are we?
@@ -45,7 +48,7 @@ sub _connect {
$self->{_tid} = threads->tid if $INC{'threads.pm'};
# Set up the driver and go!
- return $self->driver->_connect($dbh, @{ $self->{_args} });
+ return $self->driver->_connect($dbh, @args);
}
sub driver {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment