Subject: | More catchy connecting interface |
Hi.
How about this new connect() interface.
DBIx::Simple->connect({
driver => 'mysql',
database => 'test',
username => 'foo',
password => 'boo',
options => {
RaiseError => 1,
}
});
If connect() distinguish the type of the args (hashref or array).
I think DBIx::Simple is more catchy!
my quick hack
sub connect {
my ($class, @arguments) = @_;
my $self = { lc_columns => 1 };
if (defined $arguments[0] and UNIVERSAL::isa($arguments[0],
'DBI::db')) {
$self->{dbh} = shift @arguments;
Carp::carp("Additional arguments for $class->connect are ignored")
if @arguments;
} elsif (ref $arguments[0] eq 'HASH') {
$arguments[0]{options}{PrintError} ||= 0;
$arguments[0]{dsn} = sprintf 'dbi:%s:%s'
, $arguments[0]{driver} || ''
, $arguments[0]{database} || '';
$self->{dbh} = DBI->connect(
$arguments[0]{dsn},
$arguments[0]{username},
$arguments[0]{password},
$arguments[0]{options},
);
} else {
$arguments[3]->{PrintError} = 0
unless defined $arguments[3] and defined
$arguments[3]{PrintError};
$self->{dbh} = DBI->connect(@arguments);
}
...