blib/lib/DBIx/QuickDB/Driver/MySQL.pm

filter: Statementstmt 69.0% 152 / 220 Branchbran 39.3% 37 / 94 Conditioncond 50.0% 17 / 34 MC/DCmcdc 21.0% 4 / 19 Subroutinesub 66.6% 26 / 39 Podpod 48.0% 12 / 25 totaltotal 57.5% 248 / 431 CC 72 SCAR 35.4
CC
72
Cov
59%
version_string
210.0
choose
20.0
init
18.2
CRAP 34.6
« lib/DBIx/QuickDB/Watcher.pm ↑ Summary blib/lib/DBIx/QuickDB/Driver/PostgreSQL.pm »
1 package DBIx::QuickDB::Driver::MySQL;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 our $VERSION = '0.000066';
6  
7 20 ▶use Capture::Tiny qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use Carp qw/confess croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use DBIx::QuickDB::Util qw/strip_hash_defaults find_bin/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use Scalar::Util qw/reftype blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 ▶use parent 'DBIx::QuickDB::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use DBIx::QuickDB::Util::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 <data_dir <temp_dir <socket <pid_file <cfg_file
15  
16 +dbd_driver
17 <mysqld_provider
18 <use_bootstrap
19 <use_installdb
20  
21 <character_set_server
22  
23 <config
24 20 };
25  
26 0 ▶sub provider { croak "'$_[0]' does not implement provider" }
Subroutine provider: not called CC=1 SCAR=6.9
Pod undocumented
27 0 ▶sub verify_provider { croak "'$_[0]' does not implement verify_provider" }
Subroutine verify_provider: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 # True when we are running as root (EUID 0) on a platform where that matters.
30 # mysqld/mariadbd refuse to start as root without an explicit user=root. Factored
31 # out as a method so tests can simulate root without actually being it. $> is not
32 # meaningful on Windows, so it never reports root there.
33 3 ▶sub _run_as_root { $^O ne 'MSWin32' && $> == 0 }
Subroutine _run_as_root: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$^O ne "MSWin32" and $> == 0 3 0 3
34  
35 54 ▶sub dbd_driver_order { shift; grep { $_ } @_, 'DBD::MariaDB', 'DBD::mysql' }
Subroutine dbd_driver_order: called CC=1 SCAR=0.0
Pod undocumented
36  
37 20 ▶sub server_bin_list { qw/mysqld/ }
Subroutine server_bin_list: called CC=1 SCAR=0.0
Pod undocumented
38 0 ▶sub client_bin_list { qw/mysql/ }
Subroutine client_bin_list: not called CC=1 SCAR=6.9
Pod undocumented
39 0 ▶sub install_bin_list { qw/mysql_install_db/ }
Subroutine install_bin_list: not called CC=1 SCAR=6.9
Pod undocumented
40 64 ▶sub server_bin { $_[0]->provider_info->{server_bin} }
Subroutine server_bin: called CC=1 SCAR=0.0
Pod undocumented
41 60 ▶sub client_bin { $_[0]->provider_info->{client_bin} }
Subroutine client_bin: called CC=1 SCAR=0.0
Pod undocumented
42 3 ▶sub install_bin { $_[0]->provider_info->{install_bin} }
Subroutine install_bin: called CC=1 SCAR=0.0
Pod undocumented
43 0 ▶sub error_log { "$_[0]->{+DIR}/error.log" }
Subroutine error_log: not called CC=1 SCAR=6.9
Pod undocumented
44  
45 20 my %PROVIDER_CACHE;
46 177 ▶sub provider_info {
Subroutine provider_info: called CC=15 SCAR=27.8
Pod undocumented
47 177 my $this = shift;
48  
49 177 ▶ my $class = blessed($this) || $this;
Condition33%1/3
builtin::blessed($this) || $this
l!l&&r!l&&!r
01770
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
50 177 ▶ return $PROVIDER_CACHE{$class} if $PROVIDER_CACHE{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $PROVIDER_CACHE{$class} 143 34 177
51  
52 34 my %found;
53  
54 34 my $viable = 0;
55 34 for my $bin ($this->server_bin_list) {
56 46 ▶ if (my $mysqld = find_bin($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mysqld = find_bin($bin)) 2 44 46
57 2 ▶ $found{server_bin} = $mysqld if $this->verify_provider($mysqld);
Branch: 1 branch
BranchTrueFalseTotal
if $this->verify_provider($mysqld) 2 0 2
58 2 ▶ last if $found{server_bin};
Branch: 1 branch
BranchTrueFalseTotal
if $found{"server_bin"} 2 0 2
59 }
60 }
61  
62 34 ▶ return $PROVIDER_CACHE{$class} = {} unless $found{server_bin};
Branch: 1 branch
BranchTrueFalseTotal
unless $found{"server_bin"} 32 2 34
63  
64 2 for my $bin ($this->client_bin_list) {
65 2 ▶ if (my $mysql = find_bin($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mysql = find_bin($bin)) 2 0 2
66 2 $found{client_bin} = $mysql;
67 2 last;
68 }
69 }
70  
71 2 ▶ return $PROVIDER_CACHE{$class} = {} unless $found{client_bin};
Branch: 1 branch
BranchTrueFalseTotal
unless $found{"client_bin"} 0 2 2
72  
73 2 for my $bin ($this->install_bin_list) {
74 3 ▶ if (my $install = find_bin($bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $install = find_bin($bin)) 1 2 3
75 1 ▶ my ($stdout, $stderr) = capture { system($install, '--help') };
Subroutine __ANON__: called CC=1 SCAR=0.0
76 1 my $output = $stdout . "\n" . $stderr;
77 1 ▶ unless ($output =~ m/is deprecated/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($output =~ /is deprecated/) 1 0 1
78 1 $found{install_bin} = $install;
79 }
80 1 ▶ last if $found{install_bin};
Branch: 1 branch
BranchTrueFalseTotal
if $found{"install_bin"} 1 0 1
81 }
82 }
83  
84 2 return $PROVIDER_CACHE{$class} = \%found;
85 }
86  
87 0 ▶sub choose {
Subroutine choose: not called CC=4 SCAR=30.0
Pod undocumented
88 0 my $this = shift;
89  
90 0 my $spec = { bootstrap => 1, load_sql => 1 };
91  
92 0 require DBIx::QuickDB::Driver::MariaDB;
93 0 my ($ok, $why) = DBIx::QuickDB::Driver::MariaDB->viable($spec);
94 0 ▶ return 'DBIx::QuickDB::Driver::MariaDB' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
95  
96 0 require DBIx::QuickDB::Driver::MySQLCom;
97 0 ($ok, $why) = DBIx::QuickDB::Driver::MySQLCom->viable($spec);
98 0 ▶ return 'DBIx::QuickDB::Driver::MySQLCom' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
99  
100 0 require DBIx::QuickDB::Driver::Percona;
101 0 ($ok, $why) = DBIx::QuickDB::Driver::Percona->viable($spec);
102 0 ▶ return 'DBIx::QuickDB::Driver::Percona' if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
103  
104 0 return undef;
105 }
106  
107 8 ▶sub viable {
Subroutine viable: called CC=4 SCAR=14.7
Pod documented
108 8 my $this = shift;
109 8 my ($spec) = @_;
110  
111 8 require DBIx::QuickDB::Driver::MariaDB;
112 8 require DBIx::QuickDB::Driver::MySQLCom;
113 8 require DBIx::QuickDB::Driver::Percona;
114  
115 8 my ($ok1, $why1) = DBIx::QuickDB::Driver::MariaDB->viable($spec);
116 8 my ($ok2, $why2) = DBIx::QuickDB::Driver::MySQLCom->viable($spec);
117 8 my ($ok3, $why3) = DBIx::QuickDB::Driver::Percona->viable($spec);
118  
119 8 ▶ return (1, undef) if $ok1 || $ok2 || $ok3;
Branch: 1 branch
BranchTrueFalseTotal
if $ok1 or $ok2 or $ok3 0 8 8
Condition33%2/6
$ok1 or $ok2 or $ok3
l!l&&r!l&&!r
008
$ok1 or $ok2
l!l&&r!l&&!r
008
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
120  
121 8 return (0, join("\n" => $why1, $why2, $why3));
122 }
123  
124 2 ▶sub new {
Subroutine new: called CC=4 SCAR=16.6
Pod undocumented
125 2 my $class = shift;
126  
127 2 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 2 2
128 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
129 0 return $real_class->new(@_);
130 }
131  
132 2 ▶ my $self = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 2 2
133 2 bless($self, $class);
134 2 $self->init();
135  
136 2 return $self;
137 }
138  
139 0 ▶sub version_string {
Subroutine version_string: not called CC=14 SCAR=53.5
Pod documented
140 0 my ($class_or_self, @other) = @_;
141  
142 0 my $binary;
143  
144 # Go in reverse order assuming the last param hash provided is most important
145 0 for my $arg (reverse @_) {
146 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
147 0 ▶ next unless $type eq 'HASH'; # We have a hashref, possibly blessed
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "HASH" 0 0 0
148  
149 # If we find a launcher we are done looping, we want to use this binary.
150 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
151 0 ▶ $binary = $arg->server_bin and last;
Branch: 1 branch
BranchTrueFalseTotal
$binary = $arg->server_bin and last 0 0 0
152 }
153  
154 0 for my $l (qw/server_bin mysqld mariadbd/) {
155 0 ▶ $binary = $arg->{$l} and last;
Branch: 1 branch
BranchTrueFalseTotal
$binary = $arg->{$l} and last 0 0 0
156 }
157  
158 0 ▶ last if $binary;
Branch: 1 branch
BranchTrueFalseTotal
if $binary 0 0 0
159 }
160  
161 0 ▶ unless ($binary) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($binary) 0 0 0
162 0 ▶ if ($class_or_self eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_or_self eq __PACKAGE__) { } 0 0 0
163 0 ▶ if (my $sel = $class_or_self->choose) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sel = $class_or_self->choose) 0 0 0
164 0 $binary = $sel->server_bin;
165 }
166 }
167 else {
168 0 $binary = $class_or_self->server_bin;
169 }
170 }
171  
172 0 ▶ croak "Could not find a viable server binary" unless $binary;
Branch: 1 branch
BranchTrueFalseTotal
unless $binary 0 0 0
173  
174 # Call the binary with '-V', capturing and returning the output using backticks.
175 0 ▶ my ($v, $stderr) = capture { system($binary, '-V') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
176  
177 0 return $v;
178 }
179  
180 54 ▶sub dbd_driver {
Subroutine dbd_driver: called CC=6 SCAR=21.8
Pod documented
181 54 my $in = shift;
182  
183 54 ▶ return $in->{+DBD_DRIVER} if blessed($in) && $in->{+DBD_DRIVER};
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($in) and $in->{"dbd_driver"} 0 54 54
Condition33%1/3
builtin::blessed($in) and $in->{"dbd_driver"}
!ll&&!rl&&r
5400
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
184  
185 54 for my $driver ($in->dbd_driver_order) {
186 108 my $file = $driver;
187 108 $file =~ s{::}{/}g;
188 108 $file .= ".pm";
189 0 ▶ eval { require($file); 1 } or next;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file; 1 } } or next 0 108 108
190  
191 0 ▶ return $in->{+DBD_DRIVER} = $driver if blessed($in);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($in) 0 0 0
192 0 return $driver;
193 }
194  
195 54 return undef;
196 }
197  
198 0 ▶sub list_env_vars {
Subroutine list_env_vars: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200 return (
201 0 $self->SUPER::list_env_vars(),
202 qw{
203 LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN LIBMYSQL_PLUGINS
204 LIBMYSQL_PLUGIN_DIR MYSQLX_TCP_PORT MYSQLX_UNIX_PORT MYSQL_DEBUG
205 MYSQL_GROUP_SUFFIX MYSQL_HISTFILE MYSQL_HISTIGNORE MYSQL_HOME
206 MYSQL_HOST MYSQL_OPENSSL_UDF_DH_BITS_THRESHOLD
207 MYSQL_OPENSSL_UDF_DSA_BITS_THRESHOLD
208 MYSQL_OPENSSL_UDF_RSA_BITS_THRESHOLD MYSQL_PS1 MYSQL_PWD
209 MYSQL_SERVER_PREPARE MYSQL_TCP_PORT MYSQL_TEST_LOGIN_FILE
210 MYSQL_TEST_TRACE_CRASH MYSQL_TEST_TRACE_DEBUG MYSQL_UNIX_PORT
211 }
212 );
213 }
214  
215 60 ▶sub _default_paths {
Subroutine _default_paths: called CC=1 SCAR=0.0
216 60 my $class = shift;
217  
218 return (
219 60 server => $class->server_bin,
220 client => $class->client_bin,
221 );
222 }
223  
224 2 ▶sub _default_config {
Subroutine _default_config: called CC=3 SCAR=11.2
225 2 my $self = shift;
226  
227 2 my $dir = $self->dir;
228 2 my $data_dir = $self->data_dir;
229 2 my $temp_dir = $self->temp_dir;
230 2 my $pid_file = $self->pid_file;
231 2 my $socket = $self->socket;
232  
233 return (
234 client => {
235 'socket' => $socket,
236 },
237  
238 mysql_safe => {
239 'socket' => $socket,
240 },
241  
242 mysql => {
243 'socket' => $socket,
244 },
245  
246 mysqld => {
247 'datadir' => $data_dir,
248 'pid-file' => $pid_file,
249 'socket' => $socket,
250 'tmpdir' => $temp_dir,
251  
252 'log_error' => "$dir/error.log",
253 'secure_file_priv' => $dir,
254 'default_storage_engine' => 'InnoDB',
255 'innodb_buffer_pool_size' => '20M',
256  
257 # MariaDB 10.11+ reserves address space for the maximum, default
258 # 8T, which Cygwin cannot map. The server raises the max to match
259 # a larger configured size on its own.
260 'loose-innodb_buffer_pool_size_max' => '20M',
261  
262 'key_buffer_size' => '20M',
263 'max_connections' => '100',
264 'server-id' => '1',
265 'skip_grant_tables' => '1',
266 'skip_external_locking' => '',
267 'skip_networking' => '1',
268 'skip_name_resolve' => '1',
269  
270 # The X Plugin (MySQL/Percona 5.7.12+) defaults ON with a GLOBAL
271 # default socket (/tmp/mysqlx.sock) and TCP port (33060), so
272 # concurrent instances contend on shared resources even though
273 # each has its own datadir/socket. The loose- prefix downgrades
274 # the option to a warning on servers without the plugin (MariaDB,
275 # old MySQL) instead of a fatal unknown-variable error.
276 'loose-mysqlx' => 'OFF',
277 'max_allowed_packet' => '1M',
278 'max_binlog_size' => '20M',
279 'myisam_sort_buffer_size' => '8M',
280 'net_buffer_length' => '8K',
281 'read_buffer_size' => '256K',
282 'read_rnd_buffer_size' => '512K',
283 'sort_buffer_size' => '512K',
284 'table_open_cache' => '64',
285 'thread_cache_size' => '8',
286 'thread_stack' => '192K',
287 'innodb_io_capacity' => '2000',
288 'innodb_max_dirty_pages_pct' => '0',
289 'innodb_max_dirty_pages_pct_lwm' => '0',
290  
291 'character_set_server' => $self->{+CHARACTER_SET_SERVER},
292  
293 # Modern mysqld/mariadbd refuse to run as root (EUID 0) unless
294 # explicitly told 'user=root'. QuickDB has no dedicated service
295 # account to drop to, so when we ARE root we tell the server to stay
296 # root -- this is exactly the documented override. Every server
297 # invocation (bootstrap/--initialize/start) reads this defaults file,
298 # so a single config entry covers them all. As a non-root user the
299 # option would be ignored with a warning, so only add it as root.
300 $self->_run_as_root ? ('user' => 'root') : (),
301  
302 2 ▶ defined($ENV{QDB_MYSQL_SSL_FIPS}) ? ('ssl_fips_mode' => "$ENV{QDB_MYSQL_SSL_FIPS}") : (),
Branch: 2 branches
BranchTrueFalseTotal
$self->_run_as_root ? : 0 2 2
defined $ENV{'QDB_MYSQL_SSL_FIPS'} ? : 0 2 2
303 },
304 );
305 }
306  
307 2 ▶sub init {
Subroutine init: called CC=11 SCAR=29.0
Pod documented
308 2 my $self = shift;
309 2 $self->SUPER::init();
310  
311 2 $self->dbd_driver; # Vivify this
312  
313 2 ▶ $self->{+CHARACTER_SET_SERVER} //= 'UTF8MB4';
Condition50%1/2
$self->{"character_set_server"} //= "UTF8MB4"
l!l
02
MC/DC0%0/1
$self->{"character_set_server"} //= "UTF8MB4"
$self->{"character_set_server"}
Truth table50%1/2
A
A= $self->{"character_set_server"}
Aresult
11
00
314  
315 2 $self->{+DATA_DIR} = $self->{+DIR} . '/data';
316 2 $self->{+TEMP_DIR} = $self->{+DIR} . '/temp';
317 2 $self->{+CFG_FILE} = $self->{+DIR} . '/my.cfg';
318 2 $self->{+PID_FILE} = $self->{+DIR} . '/mysql.pid';
319 2 ▶ $self->{+SOCKET} ||= $self->{+DIR} . '/mysql.sock';
Condition50%1/2
$self->{"socket"} ||= $self->{"dir"} . '/mysql.sock'
l!l
02
MC/DC0%0/1
$self->{"socket"} ||= $self->{"dir"} . '/mysql.sock'
$self->{"socket"}
Truth table50%1/2
A
A= $self->{"socket"}
Aresult
11
00
320  
321 2 ▶ $self->{+USERNAME} ||= 'root';
Condition50%1/2
$self->{"username"} ||= "root"
l!l
02
MC/DC0%0/1
$self->{"username"} ||= "root"
$self->{"username"}
Truth table50%1/2
A
A= $self->{"username"}
Aresult
11
00
322  
323 2 my %defaults = $self->_default_paths;
324 2 ▶ $self->{$_} ||= $defaults{$_} for keys %defaults;
Condition33%1/3
$self->{$_} ||= $defaults{$_}
l!l&&r!l&&!r
400
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_} $defaults{$_}
Truth table33%1/3
A ||= B
A= $self->{$_}B= $defaults{$_}
ABresult
1X1
011
000
325  
326 2 my %cfg_defs = $self->_default_config;
327 2 ▶ my $cfg = { %{$self->{+CONFIG} || {}} };
Condition50%1/2
$self->{'config'} || {}
l!l
02
MC/DC0%0/1
$self->{'config'} || {}
$self->{'config'}
Truth table50%1/2
A
A= $self->{'config'}
Aresult
11
00
328 2 $self->{+CONFIG} = $cfg;
329  
330 2 for my $key (keys %cfg_defs) {
331 14 ▶ if (defined $cfg->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cfg->{$key}) { } 0 14 14
332 0 my $subdft = $cfg_defs{$key};
333 0 my $subcfg = { %{$cfg->{$key}} };
334 0 $cfg->{$key} = $subcfg;
335  
336 0 for my $skey (keys %$subdft) {
337 0 ▶ next if defined $subcfg->{$skey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $subcfg->{$skey} 0 0 0
338 0 $subcfg->{$skey} = $subdft->{$skey};
339 }
340 }
341 else {
342 14 $cfg->{$key} = $cfg_defs{$key};
343 }
344 }
345 }
346  
347 0 ▶sub clone_data {
Subroutine clone_data: not called CC=1 SCAR=6.9
Pod documented
348 0 my $self = shift;
349  
350 my $config = strip_hash_defaults(
351 0 $self->{+CONFIG},
352 {$self->_default_config},
353 );
354  
355 return (
356 $self->SUPER::clone_data(),
357  
358 CONFIG() => $config,
359 0 DBD_DRIVER() => $self->{+DBD_DRIVER},
360 );
361 }
362  
363 2 ▶sub write_config {
Subroutine write_config: called CC=12 SCAR=24.9
Pod documented
364 2 my $self = shift;
365 2 my (%params) = @_;
366  
367 2 my $cfg_file = $self->{+CFG_FILE};
368 2 ▶ 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: $!" 2 0 2
369 2 my $conf = $self->{+CONFIG};
370 2 for my $section (sort keys %$conf) {
371 14 ▶ my $override = $params{$section} // {};
Condition100%2/2
$params{$section} // {}
l!l
212
MC/DC100%1/1
$params{$section} // {}
$params{$section}
Truth table100%2/2
A
A= $params{$section}
Aresult
11
00
372  
373 14 ▶ my $sconf = $conf->{$section} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $sconf = $conf->{$section} or next 14 0 14
374  
375 14 ▶ $sconf = { %$sconf, %{$override->{add}} } if $override->{add};
Branch: 1 branch
BranchTrueFalseTotal
if $override->{"add"} 2 12 14
376  
377 14 print $cfh "[$section]\n";
378 14 for my $key (sort keys %$sconf) {
379 144 my $val = $sconf->{$key};
380 144 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 144 144
381  
382 144 ▶ next if $override->{skip} && ($key =~ $override->{skip} || $val =~ $override->{skip});
Branch: 1 branch
BranchTrueFalseTotal
if $override->{"skip"} and $key =~ /$override->{"skip"}/i || $val =~ /$override->{"skip"}/i 12 132 144
Condition100%6/6
$override->{"skip"} and $key =~ /$override->{"skip"}/i || $val =~ /$override->{"skip"}/i
!ll&&!rl&&r
765612
$key =~ /$override->{"skip"}/i or $val =~ /$override->{"skip"}/i
l!l&&r!l&&!r
10256
MC/DC100%3/3
$override->{"skip"} and $key =~ /$override->{"skip"}/i || $val =~ /$override->{"skip"}/i
$override->{"skip"} $key =~ /$override->{"skip"}/i $val =~ /$override->{"skip"}/i
Truth table100%4/4
A and B or C
A= $override->{"skip"}B= $key =~ /$override->{"skip"}/iC= $val =~ /$override->{"skip"}/i
ABCresult
0XX0
1000
11X1
1011
383  
384 132 ▶ if (length($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $val) { } 128 4 132
385 128 print $cfh "$key = $val\n";
386 }
387 else {
388 4 print $cfh "$key\n";
389 }
390 }
391  
392 14 print $cfh "\n";
393 }
394 2 close($cfh);
395  
396 2 return;
397 }
398  
399 1 ▶sub bootstrap {
Subroutine bootstrap: called CC=4 SCAR=14.1
400 1 my $self = shift;
401  
402 1 my $data_dir = $self->{+DATA_DIR};
403 1 my $temp_dir = $self->{+TEMP_DIR};
404  
405 1 ▶ mkdir($data_dir) or die "Could not create data dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $data_dir or die "Could not create data dir: $!" 1 0 1
406 1 ▶ mkdir($temp_dir) or die "Could not create temp dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $temp_dir or die "Could not create temp dir: $!" 1 0 1
407  
408 1 my $init_file = "$self->{+DIR}/init.sql";
409 1 ▶ 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: $!" 1 0 1
410 1 print $init "DROP DATABASE IF EXISTS test;\n";
411 1 print $init "CREATE DATABASE quickdb;\n";
412 1 close($init);
413  
414 1 return $init_file;
415 }
416  
417 0 ▶sub load_sql {
Subroutine load_sql: not called CC=1 SCAR=6.9
Pod documented
418 0 my $self = shift;
419 0 my ($db_name, $file) = @_;
420  
421 0 my $cfg_file = $self->{+CFG_FILE};
422  
423 0 $self->run_command(
424 [
425 $self->client_bin,
426 "--defaults-file=$cfg_file",
427 '-u' => 'root',
428 $db_name,
429 ],
430 {stdin => $file},
431 );
432 }
433  
434 0 ▶sub shell_command {
Subroutine shell_command: not called CC=1 SCAR=6.9
Pod documented
435 0 my $self = shift;
436 0 my ($db_name) = @_;
437  
438 0 my $cfg_file = $self->{+CFG_FILE};
439 0 return ($self->client_bin, "--defaults-file=$cfg_file", $db_name);
440 }
441  
442 1 ▶sub start_command {
Subroutine start_command: called CC=1 SCAR=0.0
Pod documented
443 1 my $self = shift;
444  
445 1 my $cfg_file = $self->{+CFG_FILE};
446 1 return ($self->server_bin, "--defaults-file=$cfg_file", '--skip-grant-tables');
447 }
448  
449 # The 'mysql' schema exists from install time; 'quickdb' may not yet (MySQL's
450 # --initialize bootstrap starts the server before loading the SQL creating it).
451 2 ▶sub start {
Subroutine start: called CC=2 SCAR=6.9
Pod documented
452 2 my $self = shift;
453 2 ▶ return if $self->started;
Branch: 1 branch
BranchTrueFalseTotal
if $self->started 1 1 2
454  
455 1 $self->SUPER::start(@_);
456 1 $self->_wait_for_connect('mysql');
457  
458 1 return;
459 }
460  
461 0 ▶sub connect_string {
Subroutine connect_string: not called CC=3 SCAR=24.8
Pod documented
462 0 my $self = shift;
463 0 my ($db_name) = @_;
464 0 ▶ $db_name = 'quickdb' unless defined $db_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $db_name 0 0 0
465  
466 0 my $socket = $self->{+SOCKET};
467  
468 0 ▶ if ($self->dbd_driver eq 'DBD::MariaDB') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dbd_driver eq 'DBD::MariaDB') { } 0 0 0
469 0 return "dbi:MariaDB:dbname=$db_name;mariadb_socket=$socket";
470 }
471 else {
472 0 return "dbi:mysql:dbname=$db_name;mysql_socket=$socket";
473 }
474 }
475  
476  
477 20 1;
478  
479 __END__
« lib/DBIx/QuickDB/Watcher.pm ↑ Summary blib/lib/DBIx/QuickDB/Driver/PostgreSQL.pm »