| 1 | package DBIO; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Native relational mapping for Perl, built on DBI | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 348 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 348 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 348 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 348 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 348 | ▶ | use DBIO::Base (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 348 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 348 | ▶ | use DBIO::Skills (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 376 | ▶ | sub import { | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||
| 15 | 376 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||
| 16 | 376 | my $caller = caller; | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 376 | my ($role, @opts); | |||||||||||||||||||||||||||||||||
| 19 | 376 | for my $arg (@args) { | |||||||||||||||||||||||||||||||||
| 20 | 25 | ▶ | if (defined $arg && $arg =~ /^-/) { push @opts, $arg } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $arg and $arg =~ /^-/
MC/DC50%1/2
defined $arg and $arg =~ /^-/
defined $arg
$arg =~ /^-/
Truth table66%2/3
A and B
A= defined $argB= $arg =~ /^-/
| |||||||||||||||||||||||||||||||||||
| 21 | 14 | elsif (!defined $role) { $role = $arg } | |||||||||||||||||||||||||||||||||
| 22 | 0 | else { push @opts, $arg } | |||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 376 | ▶ | unless (defined $role) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | 362 | ▶ | if ($caller =~ /::Result::[^:]+$/) { $role = 'Core' } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 27 | 1 | elsif ($caller =~ /::ResultSet::[^:]+$/) { $role = 'ResultSet' } | |||||||||||||||||||||||||||||||||
| 28 | 357 | else { $role = 'Core' } | |||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 376 | my $base = "DBIO::$role"; | |||||||||||||||||||||||||||||||||
| 32 | 376 | DBIO::Util::assert_class_name($base); | |||||||||||||||||||||||||||||||||
| 33 | 376 | ▶ | eval "require $base; 1" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | or die "use DBIO '$role': cannot load $base: $@"; | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||||||
| 37 | 348 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 38 | 375 | ▶ | push @{"${caller}::ISA"}, $base unless $caller->isa($base); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 375 | strict->import; | |||||||||||||||||||||||||||||||||
| 42 | 375 | warnings->import; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | # Schema classes get the skills-override declaration sugar (see DBIO::Skills). | ||||||||||||||||||||||||||||||||||
| 45 | 375 | ▶ | _install_skill_sugar($caller) if $caller->isa('DBIO::Schema'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 375 | _apply_shortcut($caller, $_) for @opts; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | # Install the per-schema skills-override sugar into a schema class body: | ||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||
| 52 | # skills { 'mysql-database' => $md, ... }; # set/replace the whole map | ||||||||||||||||||||||||||||||||||
| 53 | # skill 'mysql-database' => $md; # merge a single entry | ||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||
| 55 | # Both write the schema's skills() classdata (DBIO::Schema). namespace::clean | ||||||||||||||||||||||||||||||||||
| 56 | # removes the helpers after compilation, so at runtime $schema->skill(...) and | ||||||||||||||||||||||||||||||||||
| 57 | # $schema->skills resolve to the inherited DBIO::Schema accessor/method rather | ||||||||||||||||||||||||||||||||||
| 58 | # than these declaration helpers. The classdata accessor is reached via its | ||||||||||||||||||||||||||||||||||
| 59 | # fully-qualified name to bypass the (still-installed) sugar during the body. | ||||||||||||||||||||||||||||||||||
| 60 | 11 | ▶ | sub _install_skill_sugar { | ||||||||||||||||||||||||||||||||
|
Subroutine
_install_skill_sugar: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 61 | 11 | my ($caller) = @_; | |||||||||||||||||||||||||||||||||
| 62 | 348 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 63 | 348 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 64 | 11 | ▶ | *{"${caller}::skills"} = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $map = (@_ == 1 && ref $_[0] eq 'HASH') ? $_[0] : { @_ }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||
| 66 | 1 | $caller->DBIO::Schema::skills($map); | |||||||||||||||||||||||||||||||||
| 67 | 11 | }; | |||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | *{"${caller}::skill"} = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 69 | 1 | my ($name, $markdown) = @_; | |||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | my $cur = $caller->DBIO::Schema::skills || {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$caller->DBIO::Schema::skills || {}
MC/DC0%0/1
$caller->DBIO::Schema::skills || {}
$caller->DBIO::Schema::skills
Truth table50%1/2
A
A= $caller->DBIO::Schema::skills
| |||||||||||||||||||||||||||||||||||
| 71 | 1 | $caller->DBIO::Schema::skills({ %$cur, $name => $markdown }); | |||||||||||||||||||||||||||||||||
| 72 | 11 | }; | |||||||||||||||||||||||||||||||||
| 73 | 11 | require namespace::clean; | |||||||||||||||||||||||||||||||||
| 74 | 11 | namespace::clean->import(-cleanee => $caller, qw(skills skill)); | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub skill { shift; DBIO::Skills->skill(@_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
skill: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub skills { shift; DBIO::Skills->skills(@_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
skills: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | # Shortcut resolution is two-tier and core never names a single driver: | ||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||
| 85 | # 1. Explicit stub DBIO::Shortcut::<key> -- a driver ships one for each | ||||||||||||||||||||||||||||||||||
| 86 | # curated alias (e.g. -pg, -mysql). It is lazy-loaded here (so it works even | ||||||||||||||||||||||||||||||||||
| 87 | # "cold") and its apply($caller) decides what to do, usually delegating to | ||||||||||||||||||||||||||||||||||
| 88 | # DBIO->apply_driver: | ||||||||||||||||||||||||||||||||||
| 89 | # package DBIO::Shortcut::pg; | ||||||||||||||||||||||||||||||||||
| 90 | # sub apply { DBIO->apply_driver($_[1], 'PostgreSQL') } | ||||||||||||||||||||||||||||||||||
| 91 | # 1; | ||||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||||
| 93 | # 2. No stub? Fall back to an ALREADY-LOADED driver whose name matches the key | ||||||||||||||||||||||||||||||||||
| 94 | # case-insensitively (-postgresql -> DBIO::PostgreSQL). The correct casing | ||||||||||||||||||||||||||||||||||
| 95 | # comes from the loaded symbol table, not from guessing. This is why the | ||||||||||||||||||||||||||||||||||
| 96 | # canonical name "just works" once the driver is loaded, with no stub. | ||||||||||||||||||||||||||||||||||
| 97 | 11 | ▶ | sub _apply_shortcut { | ||||||||||||||||||||||||||||||||
|
Subroutine
_apply_shortcut: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||
| 98 | 11 | my ($caller, $opt) = @_; | |||||||||||||||||||||||||||||||||
| 99 | 11 | (my $key = lc $opt) =~ s/^-//; | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 11 | ▶ | $key =~ /\A[a-z0-9_]+\z/ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | or die "use DBIO: invalid shortcut '$opt'"; | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 10 | my $stub = "DBIO::Shortcut::$key"; | |||||||||||||||||||||||||||||||||
| 105 | 10 | ▶ | if (eval { require "DBIO/Shortcut/$key.pm"; 1 }) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | $stub->can('apply') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 107 | or die "use DBIO $opt: $stub provides no apply() method"; | ||||||||||||||||||||||||||||||||||
| 108 | 7 | ▶ | eval { $stub->apply($caller); 1 } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | or die "use DBIO $opt: $@"; | ||||||||||||||||||||||||||||||||||
| 110 | 7 | return; | |||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||
| 112 | 3 | my $stub_err = $@; | |||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | die "use DBIO $opt: loading $stub failed: $stub_err" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | unless $stub_err =~ /\ACan't locate/; | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | if (my $name = _loaded_driver_for($key)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | 1 | DBIO->apply_driver($caller, $name); | |||||||||||||||||||||||||||||||||
| 118 | 1 | return; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 2 | die "use DBIO $opt: unknown shortcut '$opt' (no $stub, and no loaded driver " | |||||||||||||||||||||||||||||||||
| 122 | . "named '$key' -- is the driver installed and loaded?)\n"; | ||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | # Find an already-loaded driver whose namespace lower-cases to $key. A driver | ||||||||||||||||||||||||||||||||||
| 126 | # is a DBIO::<Name> main module whose DBIO::<Name>::Storage is loadable -- this | ||||||||||||||||||||||||||||||||||
| 127 | # guard keeps core classes (Core, Schema, ...) from ever matching. | ||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | sub _loaded_driver_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
_loaded_driver_for: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||
| 129 | 3 | my ($key) = @_; | |||||||||||||||||||||||||||||||||
| 130 | 348 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 131 | 3 | for my $ns (keys %{'DBIO::'}) { | |||||||||||||||||||||||||||||||||
| 132 | 91 | ▶ | $ns =~ s/::$// or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 133 | 64 | ▶ | next unless lc $ns eq $key; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | next unless $INC{"DBIO/$ns.pm"}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return $ns if eval { require "DBIO/$ns/Storage.pm"; 1 }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | 2 | return undef; | |||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | # Apply a driver to a class by the DBIO::<Name>::{Storage,Result} convention: | ||||||||||||||||||||||||||||||||||
| 141 | # pin the storage driver on a Schema, load the Result component on a Result | ||||||||||||||||||||||||||||||||||
| 142 | # class (only if the driver ships one). Driver shortcut stubs delegate here. | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 10 | ▶ | sub apply_driver { | ||||||||||||||||||||||||||||||||
|
Subroutine
apply_driver: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 145 | 10 | my ($class, $caller, $name) = @_; | |||||||||||||||||||||||||||||||||
| 146 | 10 | ▶ | if ($caller->isa('DBIO::Schema')) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 147 | 9 | $caller->storage_type("+DBIO::${name}::Storage"); | |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||
| 149 | elsif ($caller->isa('DBIO::Core')) { | ||||||||||||||||||||||||||||||||||
| 150 | $caller->load_components("${name}::Result") | ||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | if eval { require "DBIO/${name}/Result.pm"; 1 }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 15 | ▶ | sub driver_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
driver_for: called CC=14 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 157 | 15 | my ($class, @connect_info) = @_; | |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 15 | my $info = $connect_info[0]; | |||||||||||||||||||||||||||||||||
| 160 | $info = $info->{dbh_maker} // $info->{dsn} | ||||||||||||||||||||||||||||||||||
| 161 | 15 | ▶ | if ref $info eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$info->{"dbh_maker"} // $info->{"dsn"}
MC/DC100%2/2
$info->{"dbh_maker"} // $info->{"dsn"}
$info->{"dbh_maker"}
$info->{"dsn"}
Truth table100%3/3
A // B
A= $info->{"dbh_maker"}B= $info->{"dsn"}
| |||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | 15 | my $dbd; | |||||||||||||||||||||||||||||||||
| 164 | 15 | ▶ | if ((Scalar::Util::reftype($info) // '') eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
builtin::reftype($info) // ""
MC/DC100%1/1
builtin::reftype($info) // ""
builtin::reftype($info)
Truth table100%2/2
A
A= builtin::reftype($info)
| |||||||||||||||||||||||||||||||||||
| 165 | 4 | my $dbh = $info->(); | |||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | $dbd = Scalar::Util::blessed($dbh) && $dbh->{Driver} && $dbh->{Driver}{Name}; | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
builtin::blessed($dbh) && $dbh->{'Driver'} && $dbh->{'Driver'}{'Name'}
builtin::blessed($dbh) and $dbh->{"Driver"}
MC/DC33%1/3
builtin::blessed($dbh) && $dbh->{'Driver'} && $dbh->{'Driver'}{'Name'}
builtin::blessed($dbh)
$dbh->{"Driver"}
$dbh->{'Driver'}{'Name'}
Truth table50%2/4
A and B && C
A= builtin::blessed($dbh)B= $dbh->{"Driver"}C= $dbh->{'Driver'}{'Name'}
| |||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | DBIO::Exception->throw( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 'DBIO->driver_for: the connection code reference returned no database ' | ||||||||||||||||||||||||||||||||||
| 169 | . 'handle, so there is no DBD to name the driver.' | ||||||||||||||||||||||||||||||||||
| 170 | ) unless $dbd; | ||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | ▶ | elsif (defined $info && !ref $info) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $info and not ref $info
MC/DC50%1/2
defined $info and not ref $info
defined $info
not ref $info
Truth table66%2/3
A and not(B)
A= defined $infoB= not ref $info
| |||||||||||||||||||||||||||||||||||
| 173 | 9 | ($dbd) = $info =~ /^dbi:(\w*)/i; | |||||||||||||||||||||||||||||||||
| 174 | 9 | ▶ | DBIO::Exception->throw( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dbd and length $dbd
MC/DC50%1/2
defined $dbd and length $dbd
defined $dbd
length $dbd
Truth table66%2/3
A and B
A= defined $dbdB= length $dbd
| |||||||||||||||||||||||||||||||||||
| 175 | 'DBIO->driver_for: the DSN names no DBD (dbi:<driver>:...), so there is ' | ||||||||||||||||||||||||||||||||||
| 176 | . 'no driver to find.' | ||||||||||||||||||||||||||||||||||
| 177 | ) unless defined $dbd && length $dbd; | ||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||
| 180 | 2 | DBIO::Exception->throw( | |||||||||||||||||||||||||||||||||
| 181 | 'DBIO->driver_for takes connect info with a DSN or a code reference ' | ||||||||||||||||||||||||||||||||||
| 182 | . 'returning a database handle.' | ||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | # The driver registry lives on the storage class. Loaded here, not by | ||||||||||||||||||||||||||||||||||
| 187 | # use DBIO: the pragma every result class uses does not load the storage | ||||||||||||||||||||||||||||||||||
| 188 | # layer. | ||||||||||||||||||||||||||||||||||
| 189 | 11 | require DBIO::Storage::DBI; | |||||||||||||||||||||||||||||||||
| 190 | 11 | my $storage_class = DBIO::Storage::DBI->driver_storage_class($dbd); | |||||||||||||||||||||||||||||||||
| 191 | 11 | ▶ | my ($name) = defined $storage_class | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 192 | ? $storage_class =~ /\ADBIO::(\w+)::Storage(?:::|\z)/ | ||||||||||||||||||||||||||||||||||
| 193 | : (); | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | 11 | ▶ | DBIO::Exception->throw( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 196 | "DBIO->driver_for: DBD::$dbd names no DBIO driver, so the connection does " | ||||||||||||||||||||||||||||||||||
| 197 | . 'not say which driver to use (ADR 0067). Declare the driver: ' | ||||||||||||||||||||||||||||||||||
| 198 | . "use DBIO 'Schema', -<driver>, its component, or DBIO->apply_driver." | ||||||||||||||||||||||||||||||||||
| 199 | ) unless defined $name; | ||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | 7 | return $name; | |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 3 | ▶ | sub schema_for { | ||||||||||||||||||||||||||||||||
|
Subroutine
schema_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 206 | 3 | my ($class, @connect_info) = @_; | |||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | 3 | my $driver = $class->driver_for(@connect_info); | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 2 | my $schema_class = "DBIO::SchemaFor::$driver"; | |||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | unless ($schema_class->isa('DBIO::Schema')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | 1 | require DBIO::Schema; | |||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||
| 214 | 348 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 215 | 1 | @{"${schema_class}::ISA"} = ('DBIO::Schema'); | |||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||
| 217 | 1 | $class->apply_driver($schema_class, $driver); | |||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 2 | return $schema_class->connect(@connect_info); | |||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | 348 | 1; | |||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | __END__ | ||||||||||||||||||||||||||||||||||