DBIx/QuickDB/Driver/MySQL.pm

filter: Statementstmt 30.0% 65 / 216 Branchbran 7.7% 7 / 90 Conditioncond 12.5% 4 / 32 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 44.7% 17 / 38 Podpod 45.8% 11 / 24 totaltotal 24.8% 104 / 418 CC 69 SCAR 43.4
CC
69
Cov
22%
version_string
210.0
write_config
156.0
init
132.0
CRAP 77.0
« DBIx/QuickDB/Watcher.pm ↑ Summary DBIx/QuickDB/Driver.pm »
1 package DBIx::QuickDB::Driver::MySQL;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '0.000047';
6  
7 13 ▶use Capture::Tiny qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Carp qw/confess croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use DBIx::QuickDB::Util qw/strip_hash_defaults/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use IPC::Cmd qw/can_run/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Scalar::Util qw/reftype blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use parent 'DBIx::QuickDB::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 use DBIx::QuickDB::Util::HashBase qw{
15 <data_dir <temp_dir <socket <pid_file <cfg_file
16  
17 +dbd_driver
18 <mysqld_provider
19 <use_bootstrap
20 <use_installdb
21  
22 <character_set_server
23  
24 <config
25 13 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 0 ▶sub provider { croak "'$_[0]' does not implement provider" }
Subroutine provider: not called CC=1 SCAR=6.9
Pod undocumented
28 0 ▶sub verify_provider { croak "'$_[0]' does not implement verify_provider" }
Subroutine verify_provider: not called CC=1 SCAR=6.9
Pod undocumented
29  
30 40 ▶sub dbd_driver_order { shift; grep { $_ } @_, 'DBD::MariaDB', 'DBD::mysql' }
Subroutine dbd_driver_order: called CC=1 SCAR=0.0
Pod undocumented
31  
32 16 ▶sub server_bin_list { qw/mysqld/ }
Subroutine server_bin_list: called CC=1 SCAR=0.0
Pod undocumented
33 0 ▶sub client_bin_list { qw/mysql/ }
Subroutine client_bin_list: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶sub install_bin_list { qw/mysql_install_db/ }
Subroutine install_bin_list: not called CC=1 SCAR=6.9
Pod undocumented
35 40 ▶sub server_bin { $_[0]->provider_info->{server_bin} }
Subroutine server_bin: called CC=1 SCAR=0.0
Pod undocumented
36 40 ▶sub client_bin { $_[0]->provider_info->{client_bin} }
Subroutine client_bin: called CC=1 SCAR=0.0
Pod undocumented
37 0 ▶sub install_bin { $_[0]->provider_info->{install_bin} }
Subroutine install_bin: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub error_log { "$_[0]->{+DIR}/error.log" }
Subroutine error_log: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 13 my %PROVIDER_CACHE;
41 sub provider_info {
42 120 ▶ my $this = shift;
Subroutine provider_info: called CC=15 SCAR=46.1
Pod undocumented
43  
44 120 ▶ my $class = blessed($this) || $this;
Condition33%1/3
builtin::blessed($this) || $this
l!l&&r!l&&!r
01200
MC/DC0%0/2
builtin::blessed($this) || $this
builtin::blessed($this) $this
Truth table33%1/3
A || B
A= builtin::blessed($this)B= $this
ABresult
1X1
011
000
45 120 ▶ return $PROVIDER_CACHE{$class} if $PROVIDER_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $PROVIDER_CACHE{$class} 97 23 120
46  
47 23 my %found;
48  
49 23 my $viable = 0;
50 23 for my $bin ($this->server_bin_list) {
51 30 ▶ if (my $mysqld = can_run($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mysqld = can_run($bin)) 0 30 30
52 0 ▶ $found{server_bin} = $mysqld if $this->verify_provider($mysqld);
Branch: 1 branch
BranchTrueFalseTotal
if $this->verify_provider($mysqld) 0 0 0
53 0 ▶ last if $found{server_bin};
Branch: 1 branch
BranchTrueFalseTotal
if $found{"server_bin"} 0 0 0
54 }
55 }
56  
57 23 ▶ return $PROVIDER_CACHE{$class} = {} unless $found{server_bin};
Branch: 1 branch
BranchTrueFalseTotal
unless $found{"server_bin"} 23 0 23
58  
59 0 for my $bin ($this->client_bin_list) {
60 0 ▶ if (my $mysql = can_run($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mysql = can_run($bin)) 0 0 0
61 0 $found{client_bin} = $mysql;
62 0 last;
63 }
64 }
65  
66 0 ▶ return $PROVIDER_CACHE{$class} = {} unless $found{client_bin};
Branch: 1 branch
BranchTrueFalseTotal
unless $found{"client_bin"} 0 0 0
67  
68 0 for my $bin ($this->install_bin_list) {
69 0 ▶ if (my $install = can_run($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $install = can_run($bin)) 0 0 0
70 0 ▶ my ($stdout, $stderr) = capture { system($install, '--help') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 my $output = $stdout . "\n" . $stderr;
72 0 ▶ unless ($output =~ m/is deprecated/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /is deprecated/) 0 0 0
73 0 $found{install_bin} = $install;
74 }
75 0 ▶ last if $found{install_bin};
Branch: 1 branch
BranchTrueFalseTotal
if $found{"install_bin"} 0 0 0
76 }
77 }
78  
79 0 return $PROVIDER_CACHE{$class} = \%found;
80 }
81  
82 sub choose {
83 0 ▶ my $this = shift;
Subroutine choose: not called CC=4 SCAR=30.0
Pod undocumented
84  
85 0 my $spec = { bootstrap => 1, load_sql => 1 };
86  
87 0 require DBIx::QuickDB::Driver::MariaDB;
88 0 my ($ok, $why) = DBIx::QuickDB::Driver::MariaDB->viable($spec);
89 0 ▶ return 'DBIx::QuickDB::Driver::MariaDB' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
90  
91 0 require DBIx::QuickDB::Driver::MySQLCom;
92 0 ($ok, $why) = DBIx::QuickDB::Driver::MySQLCom->viable($spec);
93 0 ▶ return 'DBIx::QuickDB::Driver::MySQLCom' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
94  
95 0 require DBIx::QuickDB::Driver::Percona;
96 0 ($ok, $why) = DBIx::QuickDB::Driver::Percona->viable($spec);
97 0 ▶ return 'DBIx::QuickDB::Driver::Percona' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
98  
99 0 return undef;
100 }
101  
102 sub viable {
103 7 ▶ my $this = shift;
Subroutine viable: called CC=4 SCAR=14.7
Pod documented
104 7 my ($spec) = @_;
105  
106 7 require DBIx::QuickDB::Driver::MariaDB;
107 7 require DBIx::QuickDB::Driver::MySQLCom;
108 7 require DBIx::QuickDB::Driver::Percona;
109  
110 7 my ($ok1, $why1) = DBIx::QuickDB::Driver::MariaDB->viable($spec);
111 7 my ($ok2, $why2) = DBIx::QuickDB::Driver::MySQLCom->viable($spec);
112 7 my ($ok3, $why3) = DBIx::QuickDB::Driver::Percona->viable($spec);
113  
114 7 ▶ return (1, undef) if $ok1 || $ok2 || $ok3;
Branch: 1 branch
BranchTrueFalseTotal
if $ok1 or $ok2 or $ok3 0 7 7
Condition33%2/6
$ok1 or $ok2 or $ok3
l!l&&r!l&&!r
007
$ok1 or $ok2
l!l&&r!l&&!r
007
MC/DC0%0/3
$ok1 or $ok2 or $ok3
$ok1 $ok2 $ok3
Truth table25%1/4
A or B or C
A= $ok1B= $ok2C= $ok3
ABCresult
1XX1
01X1
0011
0000
115  
116 7 return (0, join("\n" => $why1, $why2, $why3));
117 }
118  
119 sub new {
120 0 ▶ my $class = shift;
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
121  
122 0 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
123 0 ▶ my $real_class = $class->choose or croak("Neither MariaDB, MySQL (Oracle/Community), or Percona are viable");
Branch: 1 branch
BranchTrueFalseTotal
my $real_class = $class->choose or croak("Neither MariaDB, MySQL (Oracle/Community), or Percona are viable") 0 0 0
124 0 return $real_class->new(@_);
125 }
126  
127 0 ▶ my $self = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
128 0 bless($self, $class);
129 0 $self->init();
130  
131 0 return $self;
132 }
133  
134 sub version_string {
135 0 ▶ my ($class_or_self, @other) = @_;
Subroutine version_string: not called CC=14 SCAR=53.5
Pod documented
136  
137 0 my $binary;
138  
139 # Go in reverse order assuming the last param hash provided is most important
140 0 for my $arg (reverse @_) {
141 0 ▶ my $type = reftype($arg) or next; # skip if not a ref
Branch: 1 branch
BranchTrueFalseTotal
my $type = builtin::reftype($arg) or next 0 0 0
142 0 ▶ next unless $type eq 'HASH'; # We have a hashref, possibly blessed
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "HASH" 0 0 0
143  
144 # If we find a launcher we are done looping, we want to use this binary.
145 0 ▶ if (blessed($arg) && $arg->can('server_bin')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->can("server_bin")) 0 0 0
Condition0%0/3
builtin::blessed($arg) and $arg->can("server_bin")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($arg) and $arg->can("server_bin")
builtin::blessed($arg) $arg->can("server_bin")
Truth table0%0/3
A and B
A= builtin::blessed($arg)B= $arg->can("server_bin")
ABresult
0X0
100
111
146 0 ▶ $binary = $arg->server_bin and last;
Branch: 1 branch
BranchTrueFalseTotal
$binary = $arg->server_bin and last 0 0 0
147 }
148  
149 0 for my $l (qw/server_bin mysqld mariadbd/) {
150 0 ▶ $binary = $arg->{$l} and last;
Branch: 1 branch
BranchTrueFalseTotal
$binary = $arg->{$l} and last 0 0 0
151 }
152  
153 0 ▶ last if $binary;
Branch: 1 branch
BranchTrueFalseTotal
if $binary 0 0 0
154 }
155  
156 0 ▶ unless ($binary) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($binary) 0 0 0
157 0 ▶ if ($class_or_self eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_or_self eq __PACKAGE__) { } 0 0 0
158 0 ▶ if (my $sel = $class_or_self->choose) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sel = $class_or_self->choose) 0 0 0
159 0 $binary = $sel->server_bin;
160 }
161 }
162 else {
163 0 $binary = $class_or_self->server_bin;
164 }
165 }
166  
167 0 ▶ croak "Could not find a viable server binary" unless $binary;
Branch: 1 branch
BranchTrueFalseTotal
unless $binary 0 0 0
168  
169 # Call the binary with '-V', capturing and returning the output using backticks.
170 0 ▶ my ($v, $stderr) = capture { system($binary, '-V') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
171  
172 0 return $v;
173 }
174  
175 sub dbd_driver {
176 40 ▶ my $in = shift;
Subroutine dbd_driver: called CC=6 SCAR=21.8
Pod documented
177  
178 40 ▶ return $in->{+DBD_DRIVER} if blessed($in) && $in->{+DBD_DRIVER};
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($in) and $in->{"dbd_driver"} 0 40 40
Condition33%1/3
builtin::blessed($in) and $in->{"dbd_driver"}
!ll&&!rl&&r
4000
MC/DC0%0/2
builtin::blessed($in) and $in->{"dbd_driver"}
builtin::blessed($in) $in->{"dbd_driver"}
Truth table33%1/3
A and B
A= builtin::blessed($in)B= $in->{"dbd_driver"}
ABresult
0X0
100
111
179  
180 40 for my $driver ($in->dbd_driver_order) {
181 80 my $file = $driver;
182 80 $file =~ s{::}{/}g;
183 80 $file .= ".pm";
184 80 ▶ eval { require($file); 1 } or next;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file; 1 } } or next 80 0 80
185  
186 0 ▶ return $in->{+DBD_DRIVER} = $driver if blessed($in);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($in) 0 0 0
187 0 return $driver;
188 }
189  
190 40 return undef;
191 }
192  
193 sub list_env_vars {
194 0 ▶ my $self = shift;
Subroutine list_env_vars: not called CC=1 SCAR=6.9
Pod documented
195 return (
196 0 $self->SUPER::list_env_vars(),
197 qw{
198 LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN LIBMYSQL_PLUGINS
199 LIBMYSQL_PLUGIN_DIR MYSQLX_TCP_PORT MYSQLX_UNIX_PORT MYSQL_DEBUG
200 MYSQL_GROUP_SUFFIX MYSQL_HISTFILE MYSQL_HISTIGNORE MYSQL_HOME
201 MYSQL_HOST MYSQL_OPENSSL_UDF_DH_BITS_THRESHOLD
202 MYSQL_OPENSSL_UDF_DSA_BITS_THRESHOLD
203 MYSQL_OPENSSL_UDF_RSA_BITS_THRESHOLD MYSQL_PS1 MYSQL_PWD
204 MYSQL_SERVER_PREPARE MYSQL_TCP_PORT MYSQL_TEST_LOGIN_FILE
205 MYSQL_TEST_TRACE_CRASH MYSQL_TEST_TRACE_DEBUG MYSQL_UNIX_PORT
206 }
207 );
208 }
209  
210 sub _default_paths {
211 40 ▶ my $class = shift;
Subroutine _default_paths: called CC=1 SCAR=0.0
212  
213 return (
214 40 server => $class->server_bin,
215 client => $class->client_bin,
216 );
217 }
218  
219 sub _default_config {
220 0 ▶ my $self = shift;
Subroutine _default_config: not called CC=2 SCAR=17.9
221  
222 0 my $dir = $self->dir;
223 0 my $data_dir = $self->data_dir;
224 0 my $temp_dir = $self->temp_dir;
225 0 my $pid_file = $self->pid_file;
226 0 my $socket = $self->socket;
227  
228 return (
229 client => {
230 'socket' => $socket,
231 },
232  
233 mysql_safe => {
234 'socket' => $socket,
235 },
236  
237 mysql => {
238 'socket' => $socket,
239 },
240  
241 mysqld => {
242 'datadir' => $data_dir,
243 'pid-file' => $pid_file,
244 'socket' => $socket,
245 'tmpdir' => $temp_dir,
246  
247 'log_error' => "$dir/error.log",
248 'secure_file_priv' => $dir,
249 'default_storage_engine' => 'InnoDB',
250 'innodb_buffer_pool_size' => '20M',
251 'key_buffer_size' => '20M',
252 'max_connections' => '100',
253 'server-id' => '1',
254 'skip_grant_tables' => '1',
255 'skip_external_locking' => '',
256 'skip_networking' => '1',
257 'skip_name_resolve' => '1',
258 'max_allowed_packet' => '1M',
259 'max_binlog_size' => '20M',
260 'myisam_sort_buffer_size' => '8M',
261 'net_buffer_length' => '8K',
262 'read_buffer_size' => '256K',
263 'read_rnd_buffer_size' => '512K',
264 'sort_buffer_size' => '512K',
265 'table_open_cache' => '64',
266 'thread_cache_size' => '8',
267 'thread_stack' => '192K',
268 'innodb_io_capacity' => '2000',
269 'innodb_max_dirty_pages_pct' => '0',
270 'innodb_max_dirty_pages_pct_lwm' => '0',
271  
272 'character_set_server' => $self->{+CHARACTER_SET_SERVER},
273  
274 0 ▶ defined($ENV{QDB_MYSQL_SSL_FIPS}) ? ('ssl_fips_mode' => "$ENV{QDB_MYSQL_SSL_FIPS}") : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'QDB_MYSQL_SSL_FIPS'} ? : 0 0 0
275 },
276 );
277 }
278  
279 sub init {
280 0 ▶ my $self = shift;
Subroutine init: not called CC=11 SCAR=48.8
Pod documented
281 0 $self->SUPER::init();
282  
283 0 $self->dbd_driver; # Vivify this
284  
285 0 ▶ $self->{+CHARACTER_SET_SERVER} //= 'UTF8MB4';
Condition0%0/2
$self->{"character_set_server"} //= "UTF8MB4"
l!l
00
MC/DC0%0/1
$self->{"character_set_server"} //= "UTF8MB4"
$self->{"character_set_server"}
Truth table0%0/2
A
A= $self->{"character_set_server"}
Aresult
11
00
286  
287 0 $self->{+DATA_DIR} = $self->{+DIR} . '/data';
288 0 $self->{+TEMP_DIR} = $self->{+DIR} . '/temp';
289 0 $self->{+CFG_FILE} = $self->{+DIR} . '/my.cfg';
290 0 $self->{+PID_FILE} = $self->{+DIR} . '/mysql.pid';
291 0 ▶ $self->{+SOCKET} ||= $self->{+DIR} . '/mysql.sock';
Condition0%0/2
$self->{"socket"} ||= $self->{"dir"} . '/mysql.sock'
l!l
00
MC/DC0%0/1
$self->{"socket"} ||= $self->{"dir"} . '/mysql.sock'
$self->{"socket"}
Truth table0%0/2
A
A= $self->{"socket"}
Aresult
11
00
292  
293 0 ▶ $self->{+USERNAME} ||= 'root';
Condition0%0/2
$self->{"username"} ||= "root"
l!l
00
MC/DC0%0/1
$self->{"username"} ||= "root"
$self->{"username"}
Truth table0%0/2
A
A= $self->{"username"}
Aresult
11
00
294  
295 0 my %defaults = $self->_default_paths;
296 0 ▶ $self->{$_} ||= $defaults{$_} for keys %defaults;
Condition0%0/3
$self->{$_} ||= $defaults{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_} $defaults{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $defaults{$_}
ABresult
1X1
011
000
297  
298 0 my %cfg_defs = $self->_default_config;
299 0 ▶ my $cfg = { %{$self->{+CONFIG} || {}} };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"config"} or {} 0 0 0
300 0 $self->{+CONFIG} = $cfg;
301  
302 0 for my $key (keys %cfg_defs) {
303 0 ▶ if (defined $cfg->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cfg->{$key}) { } 0 0 0
304 0 my $subdft = $cfg_defs{$key};
305 0 my $subcfg = { %{$cfg->{$key}} };
306 0 $cfg->{$key} = $subcfg;
307  
308 0 for my $skey (keys %$subdft) {
309 0 ▶ next if defined $subcfg->{$skey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $subcfg->{$skey} 0 0 0
310 0 $subcfg->{$skey} = $subdft->{$skey};
311 }
312 }
313 else {
314 0 $cfg->{$key} = $cfg_defs{$key};
315 }
316 }
317 }
318  
319 sub clone_data {
320 0 ▶ my $self = shift;
Subroutine clone_data: not called CC=1 SCAR=6.9
Pod documented
321  
322 my $config = strip_hash_defaults(
323 0 $self->{+CONFIG},
324 {$self->_default_config},
325 );
326  
327 return (
328 $self->SUPER::clone_data(),
329  
330 CONFIG() => $config,
331 0 DBD_DRIVER() => $self->{+DBD_DRIVER},
332 );
333 }
334  
335 sub write_config {
336 0 ▶ my $self = shift;
Subroutine write_config: not called CC=12 SCAR=50.5
Pod documented
337 0 my (%params) = @_;
338  
339 0 my $cfg_file = $self->{+CFG_FILE};
340 0 ▶ open(my $cfh, '>', $cfg_file) or die "Could not open config file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $cfh, ">", $cfg_file or die "Could not open config file: $!" 0 0 0
341 0 my $conf = $self->{+CONFIG};
342 0 for my $section (sort keys %$conf) {
343 0 ▶ my $override = $params{$section} // {};
Condition0%0/2
$params{$section} // {}
l!l
00
MC/DC0%0/1
$params{$section} // {}
$params{$section}
Truth table0%0/2
A
A= $params{$section}
Aresult
11
00
344  
345 0 ▶ my $sconf = $conf->{$section} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $sconf = $conf->{$section} or next 0 0 0
346  
347 0 ▶ $sconf = { %$sconf, %{$override->{add}} } if $override->{add};
Branch: 1 branch
BranchTrueFalseTotal
if $override->{"add"} 0 0 0
348  
349 0 print $cfh "[$section]\n";
350 0 for my $key (sort keys %$sconf) {
351 0 my $val = $sconf->{$key};
352 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
353  
354 0 ▶ next if $override->{skip} && ($key =~ $override->{skip} || $val =~ $override->{skip});
Branch: 1 branch
BranchTrueFalseTotal
if $override->{"skip"} and $key =~ /$override->{"skip"}/ || $val =~ /$override->{"skip"}/ 0 0 0
Condition0%0/6
$override->{"skip"} and $key =~ /$override->{"skip"}/ || $val =~ /$override->{"skip"}/
!ll&&!rl&&r
000
$key =~ /$override->{"skip"}/ or $val =~ /$override->{"skip"}/
l!l&&r!l&&!r
000
MC/DC0%0/3
$override->{"skip"} and $key =~ /$override->{"skip"}/ || $val =~ /$override->{"skip"}/
$override->{"skip"} $key =~ /$override->{"skip"}/ $val =~ /$override->{"skip"}/
Truth table0%0/4
A and B or C
A= $override->{"skip"}B= $key =~ /$override->{"skip"}/C= $val =~ /$override->{"skip"}/
ABCresult
0XX0
1000
11X1
1011
355  
356 0 ▶ if (length($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $val) { } 0 0 0
357 0 print $cfh "$key = $val\n";
358 }
359 else {
360 0 print $cfh "$key\n";
361 }
362 }
363  
364 0 print $cfh "\n";
365 }
366 0 close($cfh);
367  
368 0 return;
369 }
370  
371 sub bootstrap {
372 0 ▶ my $self = shift;
Subroutine bootstrap: not called CC=4 SCAR=30.0
373  
374 0 my $data_dir = $self->{+DATA_DIR};
375 0 my $temp_dir = $self->{+TEMP_DIR};
376  
377 0 ▶ mkdir($data_dir) or die "Could not create data dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $data_dir or die "Could not create data dir: $!" 0 0 0
378 0 ▶ mkdir($temp_dir) or die "Could not create temp dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $temp_dir or die "Could not create temp dir: $!" 0 0 0
379  
380 0 my $init_file = "$self->{+DIR}/init.sql";
381 0 ▶ open(my $init, '>', $init_file) or die "Could not open init file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $init, ">", $init_file or die "Could not open init file: $!" 0 0 0
382 0 print $init "CREATE DATABASE quickdb;\n";
383 0 close($init);
384  
385 0 return $init_file;
386 }
387  
388 sub load_sql {
389 0 ▶ my $self = shift;
Subroutine load_sql: not called CC=1 SCAR=6.9
Pod documented
390 0 my ($db_name, $file) = @_;
391  
392 0 my $cfg_file = $self->{+CFG_FILE};
393  
394 0 $self->run_command(
395 [
396 $self->client_bin,
397 "--defaults-file=$cfg_file",
398 '-u' => 'root',
399 $db_name,
400 ],
401 {stdin => $file},
402 );
403 }
404  
405 sub shell_command {
406 0 ▶ my $self = shift;
Subroutine shell_command: not called CC=1 SCAR=6.9
Pod documented
407 0 my ($db_name) = @_;
408  
409 0 my $cfg_file = $self->{+CFG_FILE};
410 0 return ($self->client_bin, "--defaults-file=$cfg_file", $db_name);
411 }
412  
413 sub start_command {
414 0 ▶ my $self = shift;
Subroutine start_command: not called CC=1 SCAR=6.9
Pod documented
415  
416 0 my $cfg_file = $self->{+CFG_FILE};
417 0 return ($self->server_bin, "--defaults-file=$cfg_file", '--skip-grant-tables');
418 }
419  
420 sub connect_string {
421 0 ▶ my $self = shift;
Subroutine connect_string: not called CC=3 SCAR=24.8
Pod documented
422 0 my ($db_name) = @_;
423 0 ▶ $db_name = 'quickdb' unless defined $db_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $db_name 0 0 0
424  
425 0 my $socket = $self->{+SOCKET};
426  
427 0 ▶ if ($self->dbd_driver eq 'DBD::MariaDB') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dbd_driver eq 'DBD::MariaDB') { } 0 0 0
428 0 return "dbi:MariaDB:dbname=$db_name;mariadb_socket=$socket";
429 }
430 else {
431 0 return "dbi:mysql:dbname=$db_name;mysql_socket=$socket";
432 }
433 }
434  
435  
436 13 1;
437  
438 __END__
« DBIx/QuickDB/Watcher.pm ↑ Summary DBIx/QuickDB/Driver.pm »