line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::QuickDB; |
2
|
9
|
|
|
9
|
|
1178814
|
use strict; |
|
9
|
|
|
|
|
55
|
|
|
9
|
|
|
|
|
232
|
|
3
|
9
|
|
|
9
|
|
45
|
use warnings; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
341
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000023'; |
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
41
|
use Carp qw/croak/; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
407
|
|
8
|
9
|
|
|
9
|
|
68
|
use Test2::API qw/context/; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
308
|
|
9
|
9
|
|
|
9
|
|
2864
|
use DBIx::QuickDB(); |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
225
|
|
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
50
|
use Importer Importer => 'import'; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
69
|
|
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
|
30533
|
my %spec; |
17
|
12
|
100
|
|
|
|
57
|
if (@_ == 1) { |
18
|
4
|
|
100
|
|
|
23
|
my $type = ref($_[0]) || ''; |
19
|
4
|
100
|
|
|
|
15
|
if (!$type) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
20
|
3
|
|
|
|
|
11
|
$spec{driver} = $_[0]; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
elsif ($type eq 'ARRAY') { |
23
|
1
|
|
|
|
|
3
|
$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
|
|
|
|
|
26
|
%spec = @_; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
12
|
|
|
|
|
39
|
my $ctx = context(); |
37
|
|
|
|
|
|
|
|
38
|
12
|
50
|
|
|
|
36103
|
$spec{bootstrap} = 1 unless defined $spec{bootstrap}; |
39
|
12
|
50
|
|
|
|
52
|
$spec{autostart} = 1 unless defined $spec{autostart}; |
40
|
12
|
50
|
|
|
|
47
|
$spec{load_sql} = 1 unless defined $spec{load_sql}; |
41
|
|
|
|
|
|
|
|
42
|
12
|
100
|
100
|
|
|
73
|
my $drivers = $spec{driver} ? [$spec{driver}] : $spec{drivers} || [DBIx::QuickDB->plugins]; |
43
|
|
|
|
|
|
|
|
44
|
12
|
|
|
|
|
7590
|
my $reason; |
45
|
12
|
|
|
|
|
25
|
my $ok = 0; |
46
|
12
|
|
|
|
|
47
|
for my $driver (@$drivers) { |
47
|
24
|
50
|
|
|
|
62
|
next unless defined $driver; |
48
|
24
|
|
|
|
|
198
|
my ($v, $fqn, $why) = DBIx::QuickDB->check_driver($driver, \%spec); |
49
|
24
|
100
|
|
|
|
80
|
$reason = $why if @$drivers == 1; |
50
|
24
|
50
|
|
|
|
95
|
next unless $v; |
51
|
0
|
|
|
|
|
0
|
$ok = $fqn; |
52
|
0
|
|
|
|
|
0
|
last; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
12
|
50
|
|
|
|
40
|
if ($ok) { |
56
|
0
|
|
|
|
|
0
|
$ctx->release; |
57
|
0
|
|
|
|
|
0
|
return $ok; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
12
|
|
100
|
|
|
106
|
$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
|
2920
|
my $name = ref($_[0]) ? undef : shift(@_); |
79
|
2
|
|
100
|
|
|
9
|
my $spec = shift(@_) || {}; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
5
|
my $ctx = context(); |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
148
|
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__ |