File Coverage

blib/lib/Class/DBI/BaseDSN.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 10 70.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 40 44 90.9


line stmt bran cond sub pod time code
1 1     1   21477 use strict;
  1         2  
  1         60  
2             package Class::DBI::BaseDSN;
3 1     1   5 use vars qw($VERSION);
  1         3  
  1         92  
4             $VERSION = '1.22';
5              
6             sub set_db {
7 4     4 0 3381 my $package = shift;
8 4         9 my ($name, $dsn) = @_;
9              
10 1     1   5 my $isa = do { no strict 'refs'; \@{"$package\::ISA"} };
  1         10  
  1         294  
  4         5  
  4         5  
  4         13  
11 4         17 die "$package is not directly a ".__PACKAGE__
12 4 50       10 unless grep { __PACKAGE__ eq $_ } @$isa;
13              
14 4 50       20 $dsn =~ m/^(?:dbi:)?([^:]+)/i
15             or die "couldn't identify a backend from $dsn";
16              
17 4         13 my $backend = "Class::DBI::$1";
18              
19 4 100       230 unless (eval "require $backend; 1") {
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         497 my $file = $backend;
26 3         157 $file =~ s{::}{/}g;
27 3 100       98 $@ =~ /^Can't locate \Q$file\E\.pm / or die $@;
28              
29             # if it simply wasn't there fall back to Class::DBI
30 1         2 $backend = 'Class::DBI';
31 1         1203 require Class::DBI;
32             }
33              
34             # okay, get out of the way, and make like we were never here
35 2         286824 for (@$isa) {
36 2 50       38 $_ = $backend if $_ eq __PACKAGE__;
37             }
38              
39 2         28 my $method = $package->can('set_db');
40 2         7 unshift @_, $package;
41 2         10 goto &$method;
42             }
43              
44             1;
45              
46             __END__