DBIx/QuickDB/Driver/MySQLCom.pm

filter: Statementstmt 43.5% 34 / 78 Branchbran 12.5% 5 / 40 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 60.0% 9 / 15 Podpod 40.0% 2 / 5 totaltotal 29.0% 50 / 172 CC 28 SCAR 45.5
CC
28
Cov
28%
viable
188.8
init
20.0
bootstrap
20.0
CRAP 94.9
« DBIx/QuickDB.pm ↑ Summary DBIx/QuickDB/Pool.pm »
1 package DBIx::QuickDB::Driver::MySQLCom;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 our $VERSION = '0.000065';
6  
7 12 ▶use IPC::Cmd qw/can_run/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Capture::Tiny qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶use parent 'DBIx::QuickDB::Driver::MySQL';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use DBIx::QuickDB::Util::HashBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 14 ▶sub provider { 'MySQL Community Server' }
Subroutine provider: called CC=1 SCAR=0.0
Pod undocumented
14  
15 29 ▶sub dbd_driver_order { my $class = shift; $class->SUPER::dbd_driver_order($ENV{QDB_MYSQLD_DBD}) }
Subroutine dbd_driver_order: called CC=1 SCAR=0.0
Pod undocumented
16  
17 0 ▶sub init {
Subroutine init: not called CC=4 SCAR=30.0
Pod documented
18 0 my $self = shift;
19  
20 0 my $binary = $self->server_bin;
21 0 ▶ my ($help, $stderr) = capture { system($binary, '--help', '--verbose') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
22  
23 0 ▶ if ($help =~ m/--initialize/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($help =~ /--initialize/) { } 0 0 0
elsif ($help =~ /--bootstrap/) { } 0 0 0
24 0 $self->{+USE_BOOTSTRAP} = 0;
25 }
26 elsif ($help =~ m/--bootstrap/) {
27 0 $self->{+USE_BOOTSTRAP} = 1;
28  
29 0 ▶ $self->{+USE_INSTALLDB} = $self->install_bin ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->install_bin ? : 0 0 0
30 }
31  
32 0 $self->SUPER::init();
33 }
34  
35 0 ▶sub verify_provider {
Subroutine verify_provider: not called CC=3 SCAR=24.8
Pod undocumented
36 0 my $class = shift;
37 0 my ($bin, $provider) = @_;
38  
39 0 ▶ $provider //= $class->provider;
Condition0%0/3
$provider //= $class->provider
l!l&&r!l&&!r
000
MC/DC0%0/2
$provider //= $class->provider
$provider $class->provider
Truth table0%0/3
A //= B
A= $providerB= $class->provider
ABresult
1X1
011
000
40  
41 0 ▶ my ($v, $stderr) = capture { system($bin, '-V') };
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 ▶ return 1 if $v =~ m/$provider/i;
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /$provider/i 0 0 0
43 0 return 0;
44 }
45  
46 29 ▶sub viable {
Subroutine viable: called CC=20 SCAR=52.4
Pod documented
47 29 my $this = shift;
48 29 my ($spec) = @_;
49  
50 29 ▶ my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 29 29
51  
52 29 my @bad;
53  
54 29 ▶ push @bad => "Could not load either 'DBD::MariaDB' or 'DBD::mysql', needed for everything"
Branch: 1 branch
BranchTrueFalseTotal
unless $this->dbd_driver 29 0 29
55 unless $this->dbd_driver;
56  
57 29 ▶ if (!keys %{$this->provider_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not keys %{$this->provider_info;}) { } 29 0 29
58 29 push @bad => "Installed MySQL is not " . $this->provider;
59 }
60 else {
61 0 ▶ if ($spec->{bootstrap}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'bootstrap'}) { } 0 0 0
elsif ($spec->{'autostart'}) { } 0 0 0
62 0 ▶ push @bad => "'mysqld' command is missing, needed for bootstrap" unless $check{server} && -x $check{server};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"server"} and -x $check{"server"} 0 0 0
Condition0%0/3
$check{"server"} and -x $check{"server"}
!ll&&!rl&&r
000
MC/DC0%0/2
$check{"server"} and -x $check{"server"}
$check{"server"} -x $check{"server"}
Truth table0%0/3
A and B
A= $check{"server"}B= -x $check{"server"}
ABresult
0X0
100
111
63 }
64 elsif ($spec->{autostart}) {
65 0 ▶ push @bad => "'mysqld' command is missing, needed for autostart" unless $check{server} && -x $check{server};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"server"} and -x $check{"server"} 0 0 0
Condition0%0/3
$check{"server"} and -x $check{"server"}
!ll&&!rl&&r
000
MC/DC0%0/2
$check{"server"} and -x $check{"server"}
$check{"server"} -x $check{"server"}
Truth table0%0/3
A and B
A= $check{"server"}B= -x $check{"server"}
ABresult
0X0
100
111
66 }
67  
68 0 ▶ if ($spec->{load_sql}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"load_sql"}) 0 0 0
69 0 ▶ push @bad => "'mysql' command is missing, needed for load_sql" unless $check{client} && -x $check{client};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"client"} and -x $check{"client"} 0 0 0
Condition0%0/3
$check{"client"} and -x $check{"client"}
!ll&&!rl&&r
000
MC/DC0%0/2
$check{"client"} and -x $check{"client"}
$check{"client"} -x $check{"client"}
Truth table0%0/3
A and B
A= $check{"client"}B= -x $check{"client"}
ABresult
0X0
100
111
70 }
71 }
72  
73 29 ▶ if ($check{server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check{"server"}) 0 29 29
74 0 my $version = $this->version_string;
75 0 ▶ if ($version && $version =~ m/(\d+)\.(\d+)\.(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version and $version =~ /(\d+)\.(\d+)\.(\d+)/) 0 0 0
Condition0%0/3
$version and $version =~ /(\d+)\.(\d+)\.(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$version and $version =~ /(\d+)\.(\d+)\.(\d+)/
$version $version =~ /(\d+)\.(\d+)\.(\d+)/
Truth table0%0/3
A and B
A= $versionB= $version =~ /(\d+)\.(\d+)\.(\d+)/
ABresult
0X0
100
111
76 0 my ($a, $b, $c) = ($1, $2, $3);
77 0 ▶ push @bad => "'mysqld' is too old ($a.$b.$c), need at least 5.6.0"
Branch: 1 branch
BranchTrueFalseTotal
if $a < 5 or $a == 5 and $b < 6 0 0 0
Condition0%0/6
$a < 5 or $a == 5 and $b < 6
l!l&&r!l&&!r
000
$a == 5 and $b < 6
!ll&&!rl&&r
000
MC/DC0%0/3
$a < 5 or $a == 5 and $b < 6
$a < 5 $a == 5 $b < 6
Truth table0%0/4
A or B and C
A= $a < 5B= $a == 5C= $b < 6
ABCresult
1XX1
0111
00X0
0100
78 if $a < 5 || ($a == 5 && $b < 6);
79 }
80 }
81  
82 29 ▶ return (1, undef) unless @bad;
Branch: 1 branch
BranchTrueFalseTotal
unless @bad 0 29 29
83 29 return (0, join "\n" => @bad);
84 }
85  
86 0 ▶sub bootstrap {
Subroutine bootstrap: not called CC=4 SCAR=30.0
87 0 my $self = shift;
88  
89 0 my $init_file = $self->SUPER::bootstrap(@_);
90 0 my $data_dir = $self->{+DATA_DIR};
91  
92 0 ▶ if ($self->{+USE_BOOTSTRAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'use_bootstrap'}) { } 0 0 0
93 0 ▶ if ($self->{+USE_INSTALLDB}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_installdb"}) 0 0 0
94 0 local $ENV{PERL5LIB} = "";
95 # mysql_install_db does not read our defaults file, so the config's
96 # user=root (added when running as root) does not reach it -- pass it
97 # explicitly here so bootstrap works as root too. See MySQL.pm's
98 # _default_config for the rationale.
99 0 ▶ my @root = $self->_run_as_root ? ('--user=root') : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->_run_as_root ? : 0 0 0
100 0 $self->run_command([$self->install_bin, '--datadir=' . $data_dir, @root]);
101 }
102 0 $self->write_config();
103 0 $self->run_command([$self->start_command, '--bootstrap'], {stdin => $init_file});
104 }
105 else {
106 0 $self->write_config();
107 0 $self->run_command([$self->start_command, '--initialize']);
108 0 $self->start;
109 0 $self->load_sql("", $init_file);
110 }
111  
112 0 return;
113 }
114  
115 0 ▶sub _default_config {
Subroutine _default_config: not called CC=1 SCAR=6.9
116 0 my $self = shift;
117  
118 0 my %config = $self->SUPER::_default_config(@_);
119  
120 0 $config{mysql}->{'no-auto-rehash'} = '';
121  
122 0 return %config;
123 }
124  
125  
126 12 1;
127  
128 __END__
« DBIx/QuickDB.pm ↑ Summary DBIx/QuickDB/Pool.pm »