blib/lib/Class/DBI/BaseDSN.pm

filter: Statementstmt 100% 31 / 31 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 91.3% 42 / 46 CC 7 SCAR 16.5
CC
7
Cov
93%
set_db
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Class::DBI::BaseDSN;
3 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $VERSION = '1.22';
5  
6 4 ▶sub set_db {
Subroutine set_db: called CC=7 SCAR=19.5
Pod undocumented
7 4 my $package = shift;
8 4 my ($name, $dsn) = @_;
9  
10 1 ▶ my $isa = do { no strict 'refs'; \@{"$package\::ISA"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
11 die "$package is not directly a ".__PACKAGE__
12 4 ▶ unless grep { __PACKAGE__ eq $_ } @$isa;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {__PACKAGE__ eq $_;} @$isa 0 4 4
13  
14 4 ▶ $dsn =~ m/^(?:dbi:)?([^:]+)/i
Branch: 1 branch
BranchTrueFalseTotal
$dsn =~ /^(?:dbi:)?([^:]+)/i or die "couldn't identify a backend from $dsn" 4 0 4
15 or die "couldn't identify a backend from $dsn";
16  
17 4 my $backend = "Class::DBI::$1";
18  
19 4 ▶ unless (eval "require $backend; 1") {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $backend; 1") 3 1 4
20 # Only quash "Can't locate" errors about the class we're pulling in.
21 # It may be that we have Class::DBI::$dsn but not something that it
22 # in turn needs (yes, dependencies should fix that, but they don't
23 # always: see rt.cpan.org#3982)
24  
25 3 my $file = $backend;
26 3 $file =~ s{::}{/}g;
27 3 ▶ $@ =~ /^Can't locate \Q$file\E\.pm / or die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ =~ /^Can't locate \Q$file\E\.pm / or die $@ 1 2 3
28  
29 # if it simply wasn't there fall back to Class::DBI
30 1 $backend = 'Class::DBI';
31 1 require Class::DBI;
32 }
33  
34 # okay, get out of the way, and make like we were never here
35 2 for (@$isa) {
36 2 ▶ $_ = $backend if $_ eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq __PACKAGE__ 2 0 2
37 }
38  
39 2 my $method = $package->can('set_db');
40 2 unshift @_, $package;
41 2 goto &$method;
42 }
43  
44 1 1;
45  
46 __END__
↑ Summary