| 1 | package Test2::Tools::QuickDB; | ||||||||||||||||||||
| 2 | 23 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 23 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 23 | our $VERSION = '0.000047'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 23 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 23 | ▶ | use Test2::API qw/context/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 23 | ▶ | use DBIx::QuickDB(); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 23 | ▶ | use Importer Importer => 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 23 | our @EXPORT = qw/get_db_or_skipall get_db skipall_unless_can_db/; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub skipall_unless_can_db { | ||||||||||||||||||||
| 16 | 26 | ▶ | my %spec; | ||||||||||||||||||
|
Subroutine
skipall_unless_can_db: called CC=17 SCAR=32.1
Pod
documented
| |||||||||||||||||||||
| 17 | 26 | ▶ | if (@_ == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 10 | ▶ | my $type = ref($_[0]) || ''; | ||||||||||||||||||
|
Condition100%2/2
ref $_[0] || ''
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
| |||||||||||||||||||||
| 19 | 10 | ▶ | if (!$type) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 20 | 9 | $spec{driver} = $_[0]; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | elsif ($type eq 'ARRAY') { | ||||||||||||||||||||
| 23 | 1 | $spec{drivers} = $_[0]; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | elsif ($type eq 'HASH') { | ||||||||||||||||||||
| 26 | 0 | %spec = %{$_[0]}; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | else { | ||||||||||||||||||||
| 29 | 0 | croak "Invalid Argument: $_[0]"; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | else { | ||||||||||||||||||||
| 33 | 16 | %spec = @_; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 26 | my $ctx = context(); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 26 | ▶ | $spec{bootstrap} = 1 unless defined $spec{bootstrap}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 26 | ▶ | $spec{autostart} = 1 unless defined $spec{autostart}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 26 | ▶ | $spec{load_sql} = 1 unless defined $spec{load_sql}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 26 | ▶ | my $drivers = $spec{driver} ? [$spec{driver}] : $spec{drivers} || [DBIx::QuickDB->plugins]; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$spec{"drivers"} or ["DBIx::QuickDB"->plugins]
MC/DC100%1/1
$spec{"drivers"} or ["DBIx::QuickDB"->plugins]
$spec{"drivers"}
Truth table100%2/2
A
A= $spec{"drivers"}
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 26 | my $reason; | |||||||||||||||||||
| 45 | 26 | my $ok = 0; | |||||||||||||||||||
| 46 | 26 | for my $driver (@$drivers) { | |||||||||||||||||||
| 47 | 51 | ▶ | next unless defined $driver; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 51 | my ($v, $fqn, $why) = DBIx::QuickDB->check_driver($driver, \%spec); | |||||||||||||||||||
| 49 | 51 | ▶ | $reason = $why if @$drivers == 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 51 | ▶ | next unless $v; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | $ok = $fqn; | |||||||||||||||||||
| 52 | 0 | last; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 26 | ▶ | if ($ok) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | $ctx->release; | |||||||||||||||||||
| 57 | 0 | return $ok; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 26 | ▶ | $ctx->plan(0, 'SKIP' => $reason || "no db driver is viable"); | ||||||||||||||||||
|
Condition100%2/2
$reason || 'no db driver is viable'
MC/DC100%1/1
$reason || 'no db driver is viable'
$reason
Truth table100%2/2
A
A= $reason
| |||||||||||||||||||||
| 61 | 0 | $ctx->release; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub get_db { | ||||||||||||||||||||
| 67 | # Get a context in case anything below here has testing code. | ||||||||||||||||||||
| 68 | 0 | ▶ | my $ctx = context(); | ||||||||||||||||||
|
Subroutine
get_db: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | my $db = DBIx::QuickDB->build_db(@_); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | $ctx->release; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | return $db; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | sub get_db_or_skipall { | ||||||||||||||||||||
| 78 | 2 | ▶ | my $name = ref($_[0]) ? undef : shift(@_); | ||||||||||||||||||
|
Subroutine
get_db_or_skipall: called CC=4 SCAR=17.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 2 | ▶ | my $spec = shift(@_) || {}; | ||||||||||||||||||
|
Condition100%2/2
shift @_ || {}
MC/DC100%1/1
shift @_ || {}
shift @_
Truth table100%2/2
A
A= shift @_
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 2 | my $ctx = context(); | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 2 | skipall_unless_can_db(%$spec); | |||||||||||||||||||
| 84 | 0 | ▶ | my $db = get_db($name ? $name : (), $spec); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | $ctx->release; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | return $db; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 23 | 1; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||