| 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
| |||||||||||
| 13 | |||||||||||
| 14 | 4 | ▶ | $dsn =~ m/^(?:dbi:)?([^:]+)/i | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||