File Coverage

blib/lib/DBIx/DBSchema/_util.pm
Criterion Covered Total %
statement 15 32 46.8
branch 0 14 0.0
condition 0 6 0.0
subroutine 5 8 62.5
pod n/a
total 20 60 33.3


line stmt bran cond sub pod time code
1             # internal utility subroutines used by multiple classes
2              
3             package DBIx::DBSchema::_util;
4              
5 1     1   6 use strict;
  1         1  
  1         46  
6 1     1   6 use vars qw(@ISA @EXPORT_OK);
  1         3  
  1         56  
7 1     1   6 use Exporter;
  1         1  
  1         38  
8 1     1   6 use Carp qw(confess);
  1         3  
  1         79  
9 1     1   8394 use DBI;
  1         24937  
  1         394  
10              
11             @ISA = qw(Exporter);
12             @EXPORT_OK = qw( _load_driver _dbh _parse_opt );
13              
14             sub _load_driver {
15 0     0     my($dbh) = @_;
16 0           my $driver;
17 0 0         if ( ref($dbh) ) {
18 0           $driver = $dbh->{Driver}->{Name};
19             } else {
20 0 0         $dbh =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i #nicked from DBI->connect
21             or '' =~ /()/; # ensure $1 etc are empty if match fails
22 0 0         $driver = $1 or confess "can't parse data source: $dbh";
23             }
24              
25             #require "DBIx/DBSchema/DBD/$driver.pm";
26             #$driver;
27 0 0 0       eval 'require "DBIx/DBSchema/DBD/$driver.pm"' and $driver or die $@;
28             }
29              
30             #sub _dbh_or_dbi_connect_args {
31             sub _dbh {
32 0     0     my($dbh) = shift;
33 0           my $created_dbh = 0;
34 0 0 0       unless ( ref($dbh) || ! @_ ) {
35 0 0         $dbh = DBI->connect( $dbh, @_ ) or die $DBI::errstr;
36 0           $created_dbh = 1;
37             }
38              
39 0           ( $dbh, $created_dbh );
40             }
41              
42             sub _parse_opt {
43 0     0     my $optref = shift;
44 0 0         if ( ref( $optref->[0] ) eq 'HASH' ) {
45 0           shift @$optref;
46             } else {
47 0           {};
48             }
49             }
50              
51             1;
52