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