Perform/DButils.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 39 CC 3 SCAR 19.5
CC
3
Cov
0%
open_db
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1  
2 package DBIx::Informix::Perform::DButils;
3 use strict;
4 use base 'Exporter';
5  
6 our @EXPORT_OK = qw(&open_db);
7  
8 use DBI;
9  
10 our %DB_MARKERS =
11 ( Pg => { dbname => 'dbname=',
12 host => 'host=',
13 },
14 mysql => { dbname => 'database=',
15 host => 'host=',
16 },
17 );
18  
19 sub open_db
20 {
21 my $dbname = shift; # May be a connect arg.
22  
23 my $connect_arg = $dbname;
24 if ($connect_arg !~ /^dbi:/) { # not already a DBI connect-arg...
25 my $dbtype = $ENV{DB_CLASS} || 'Pg';
26 $connect_arg = "dbi:$dbtype:";
27 my $specifics = $DB_MARKERS{$dbtype};
28 $connect_arg .= $$specifics{'dbname'} . $dbname . ";";
29 my $host = $ENV{DB_HOST};
30 $connect_arg .= $$specifics{'host'} . $host . ";"
31 if ($host);
32 }
33 my $dbuser = $ENV{DB_USER};
34 my $dbpass = $ENV{DB_PASSWORD};
35 my $dbh = DBI->connect($connect_arg, $dbuser, $dbpass)
36 or die "Unable to connect to '$connect_arg' as user '$dbuser'";
37 return $dbh;
38 }
39  
40 1;