DBIx/QuickDB/Driver/MySQLCom.pm

filter: Statementstmt 44.1% 34 / 77 Branchbran 13.1% 5 / 38 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 60.0% 9 / 15 Podpod 40.0% 2 / 5 totaltotal 29.5% 50 / 169 CC 27 SCAR 45.7
CC
27
Cov
29%
viable
188.8
init
20.0
verify_provider
12.0
CRAP 96.1
« DBIx/QuickDB.pm ↑ Summary DBIx/QuickDB/Watcher.pm »
1 package DBIx::QuickDB::Driver::MySQLCom;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 our $VERSION = '0.000047';
6  
7 11 ▶use IPC::Cmd qw/can_run/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Capture::Tiny qw/capture/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 ▶use parent 'DBIx::QuickDB::Driver::MySQL';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use DBIx::QuickDB::Util::HashBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶sub provider { 'MySQL Community Server' }
Subroutine provider: called CC=1 SCAR=0.0
Pod undocumented
14  
15 27 ▶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 sub init {
18 0 ▶ my $self = shift;
Subroutine init: not called CC=4 SCAR=30.0
Pod documented
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 sub verify_provider {
36 0 ▶ my $class = shift;
Subroutine verify_provider: not called CC=3 SCAR=24.8
Pod undocumented
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 sub viable {
47 27 ▶ my $this = shift;
Subroutine viable: called CC=20 SCAR=52.4
Pod documented
48 27 my ($spec) = @_;
49  
50 27 ▶ my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 27 27
51  
52 27 my @bad;
53  
54 27 ▶ push @bad => "Could not load either 'DBD::MariaDB' or 'DBD::mysql', needed for everything"
Branch: 1 branch
BranchTrueFalseTotal
unless $this->dbd_driver 27 0 27
55 unless $this->dbd_driver;
56  
57 27 ▶ if (!keys %{$this->provider_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not keys %{$this->provider_info;}) { } 27 0 27
58 27 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 27 ▶ if ($check{server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check{"server"}) 0 27 27
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 27 ▶ return (1, undef) unless @bad;
Branch: 1 branch
BranchTrueFalseTotal
unless @bad 0 27 27
83 27 return (0, join "\n" => @bad);
84 }
85  
86 sub bootstrap {
87 0 ▶ my $self = shift;
Subroutine bootstrap: not called CC=3 SCAR=24.8
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 0 $self->run_command([$self->install_bin, '--datadir=' . $data_dir]);
96 }
97 0 $self->write_config();
98 0 $self->run_command([$self->start_command, '--bootstrap'], {stdin => $init_file});
99 }
100 else {
101 0 $self->write_config();
102 0 $self->run_command([$self->start_command, '--initialize']);
103 0 $self->start;
104 0 $self->load_sql("", $init_file);
105 }
106  
107 0 return;
108 }
109  
110 sub _default_config {
111 0 ▶ my $self = shift;
Subroutine _default_config: not called CC=1 SCAR=6.9
112  
113 0 my %config = $self->SUPER::_default_config(@_);
114  
115 0 $config{mysql}->{'no-auto-rehash'} = '';
116  
117 0 return %config;
118 }
119  
120  
121 11 1;
122  
123 __END__
« DBIx/QuickDB.pm ↑ Summary DBIx/QuickDB/Watcher.pm »