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