Skip to content
Browse files

Encapsulate DBI params in a closure.

Thanks to Brad Bowman for the patch and John Siracusa for the sanity check.
  • Loading branch information...
1 parent 08bb82d commit 5c922445e799c5782515e8500fee37a1a29b6911 @theory committed
Showing with 14 additions and 8 deletions.
  1. +4 −0 Changes
  2. +10 −8 lib/DBIx/Connector.pm
View
4 Changes
@@ -1,6 +1,10 @@
Revision history for Perl extension DBIx::Connector.
0.52
+ - The DBI params are now encapsulated in a code reference, rather than
+ stored as the passed array, so that the password is less likely to be
+ displayed in a dump. Idea borrowed from Rose::DB. Patch from Brad
+ Bowman.
0.51 2012-02-18T00:14:48Z
- Fixed internal exception handling on Perls less than 5.14, where some
View
18 lib/DBIx/Connector.pm
@@ -10,8 +10,9 @@ our $VERSION = '0.52';
sub new {
my $class = shift;
+ my @args = @_;
bless {
- _args => [@_],
+ _args => sub { @args },
_svp_depth => 0,
_mode => 'no_ping',
_dond => 1,
@@ -22,22 +23,23 @@ sub DESTROY { $_[0]->disconnect if $_[0]->{_dond} }
sub _connect {
my $self = shift;
+ my @args = $self->{_args}->();
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 +47,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 {
@@ -56,7 +58,7 @@ sub driver {
if (my $dbh = $self->{_dbh}) {
$dbh->{Driver}{Name};
} else {
- (DBI->parse_dsn( $self->{_args}[0]))[1];
+ (DBI->parse_dsn( ($self->{_args}->())[0]) )[1];
}
};
$self->{driver} = DBIx::Connector::Driver->new( $driver );

0 comments on commit 5c92244

Please sign in to comment.
Something went wrong with that request. Please try again.