MySQL-Util
view release on metacpan or search on metacpan
t/testlib.pl view on Meta::CPAN
use Modern::Perl;
use Carp;
use String::Util ':all';
sub get_dbh {
my %conf = parse_conf();
return DBI->connect(
$conf{DBI_DSN},
$conf{DBI_USER},
$conf{DBI_PASS},
{
RaiseError => 1,
PrintError => 0
}
);
}
sub get_mysql_util {
my %conf = parse_conf();
return MySQL::Util->new(
dsn => $conf{DBI_DSN},
user => $conf{DBI_USER},
pass => $conf{DBI_PASS},
span => 0
);
}
sub parse_dsn {
my %conf = parse_conf();
my %ret;
foreach my $part ( split /:|;/, $conf{DBI_DSN} ) {
next unless $part =~ /=/;
my ( $key, $value ) = split /=/, $part;
$ret{$key} = $value;
}
if ( !defined $ret{host} ) {
$ret{host} = 'localhost';
}
if ( !defined $ret{database} ) {
if ( !defined $ret{dbname} ) {
$ret{database} = 'testmysqlutil';
$ret{dbname} = 'testmysqlutil';
}
}
elsif ( !defined $ret{dbname} ) {
$ret{dbname} = $ret{database};
}
if ( !defined $ret{port} ) {
$ret{port} = 3306;
}
return %ret;
}
( run in 1.241 second using v1.01-cache-2.11-cpan-39bf76dae61 )