Test2/Tools/QuickDB.pm

filter: Statementstmt 74.1% 46 / 62 Branchbran 57.1% 16 / 28 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 74.5% 85 / 114 CC 20 SCAR 27.8
CC
20
Cov
71%
skipall_unless_can_db
24.8
get_db_or_skipall
5.6
get_db
2.0
CRAP 16.1
« DBIx/QuickDB/Pool.pm ↑ Summary DBIx/QuickDB/Driver/SQLite.pm »
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
BranchTrueFalseTotal
if (@_ == 1) { } 10 16 26
18 10 ▶ my $type = ref($_[0]) || '';
Condition100%2/2
ref $_[0] || ''
l!l
19
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
Aresult
11
00
19 10 ▶ if (!$type) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $type) { } 9 1 10
elsif ($type eq 'ARRAY') { } 1 0 1
elsif ($type eq 'HASH') { } 0 0 0
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
BranchTrueFalseTotal
unless defined $spec{"bootstrap"} 26 0 26
39 26 ▶ $spec{autostart} = 1 unless defined $spec{autostart};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"autostart"} 26 0 26
40 26 ▶ $spec{load_sql} = 1 unless defined $spec{load_sql};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"load_sql"} 26 0 26
41  
42 26 ▶ my $drivers = $spec{driver} ? [$spec{driver}] : $spec{drivers} || [DBIx::QuickDB->plugins];
Branch: 1 branch
BranchTrueFalseTotal
$spec{'driver'} ? : 13 13 26
Condition100%2/2
$spec{"drivers"} or ["DBIx::QuickDB"->plugins]
l!l
103
MC/DC100%1/1
$spec{"drivers"} or ["DBIx::QuickDB"->plugins]
$spec{"drivers"}
Truth table100%2/2
A
A= $spec{"drivers"}
Aresult
11
00
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
BranchTrueFalseTotal
unless defined $driver 0 51 51
48 51 my ($v, $fqn, $why) = DBIx::QuickDB->check_driver($driver, \%spec);
49 51 ▶ $reason = $why if @$drivers == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$drivers == 1 20 31 51
50 51 ▶ next unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 51 0 51
51 0 $ok = $fqn;
52 0 last;
53 }
54  
55 26 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 0 26 26
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'
l!l
206
MC/DC100%1/1
$reason || 'no db driver is viable'
$reason
Truth table100%2/2
A
A= $reason
Aresult
11
00
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
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
79 2 ▶ my $spec = shift(@_) || {};
Condition100%2/2
shift @_ || {}
l!l
11
MC/DC100%1/1
shift @_ || {}
shift @_
Truth table100%2/2
A
A= shift @_
Aresult
11
00
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
BranchTrueFalseTotal
$name ? : 0 0 0
85  
86 0 $ctx->release;
87  
88 0 return $db;
89 }
90  
91 23 1;
92  
93 __END__
« DBIx/QuickDB/Pool.pm ↑ Summary DBIx/QuickDB/Driver/SQLite.pm »