File Coverage

blib/lib/DBIx/QuickDB/Driver/MySQLCom.pm
Criterion Covered Total %
statement 32 75 42.6
branch 5 38 13.1
condition 0 21 0.0
subroutine 9 15 60.0
pod 2 5 40.0
total 48 154 31.1


line stmt bran cond sub pod time code
1             package DBIx::QuickDB::Driver::MySQLCom;
2 11     11   261406 use strict;
  11         30  
  11         384  
3 11     11   51 use warnings;
  11         20  
  11         724  
4              
5             our $VERSION = '0.000040';
6              
7 11     11   2393 use IPC::Cmd qw/can_run/;
  11         201764  
  11         746  
8 11     11   1845 use Capture::Tiny qw/capture/;
  11         41726  
  11         524  
9              
10 11     11   59 use parent 'DBIx::QuickDB::Driver::MySQL';
  11         38  
  11         64  
11 11     11   668 use DBIx::QuickDB::Util::HashBase;
  11         45  
  11         64  
12              
13 13     13 0 53 sub provider { 'MySQL Community Server' }
14              
15 27     27 0 34 sub dbd_driver_order { my $class = shift; $class->SUPER::dbd_driver_order($ENV{QDB_MYSQLD_DBD}) }
  27         138  
16              
17             sub init {
18 0     0 1 0 my $self = shift;
19              
20 0         0 my $binary = $self->server_bin;
21 0     0   0 my ($help, $stderr) = capture { system($binary, '--help', '--verbose') };
  0         0  
22              
23 0 0       0 if ($help =~ m/--initialize/) {
    0          
24 0         0 $self->{+USE_BOOTSTRAP} = 0;
25             }
26             elsif ($help =~ m/--bootstrap/) {
27 0         0 $self->{+USE_BOOTSTRAP} = 1;
28              
29 0 0       0 $self->{+USE_INSTALLDB} = $self->install_bin ? 1 : 0;
30             }
31              
32 0         0 $self->SUPER::init();
33             }
34              
35             sub verify_provider {
36 0     0 0 0 my $class = shift;
37 0         0 my ($bin, $provider) = @_;
38              
39 0   0     0 $provider //= $class->provider;
40              
41 0     0   0 my ($v, $stderr) = capture { system($bin, '-V') };
  0         0  
42 0 0       0 return 1 if $v =~ m/$provider/i;
43 0         0 return 0;
44             }
45              
46             sub viable {
47 27     27 1 36 my $this = shift;
48 27         45 my ($spec) = @_;
49              
50 27 50       158 my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec);
51              
52 27         63 my @bad;
53              
54 27 50       110 push @bad => "Could not load either 'DBD::MariaDB' or 'DBD::mysql', needed for everything"
55             unless $this->dbd_driver;
56              
57 27 50       34 if (!keys %{$this->provider_info}) {
  27         56  
58 27         87 push @bad => "Installed MySQL is not " . $this->provider;
59             }
60             else {
61 0 0       0 if ($spec->{bootstrap}) {
    0          
62 0 0 0     0 push @bad => "'mysqld' command is missing, needed for bootstrap" unless $check{server} && -x $check{server};
63             }
64             elsif ($spec->{autostart}) {
65 0 0 0     0 push @bad => "'mysqld' command is missing, needed for autostart" unless $check{server} && -x $check{server};
66             }
67              
68 0 0       0 if ($spec->{load_sql}) {
69 0 0 0     0 push @bad => "'mysql' command is missing, needed for load_sql" unless $check{client} && -x $check{client};
70             }
71             }
72              
73 27 50       68 if ($check{server}) {
74 0         0 my $version = $this->version_string;
75 0 0 0     0 if ($version && $version =~ m/(\d+)\.(\d+)\.(\d+)/) {
76 0         0 my ($a, $b, $c) = ($1, $2, $3);
77 0 0 0     0 push @bad => "'mysqld' is too old ($a.$b.$c), need at least 5.6.0"
      0        
78             if $a < 5 || ($a == 5 && $b < 6);
79             }
80             }
81              
82 27 50       55 return (1, undef) unless @bad;
83 27         111 return (0, join "\n" => @bad);
84             }
85              
86             sub bootstrap {
87 0     0     my $self = shift;
88              
89 0           my $init_file = $self->SUPER::bootstrap(@_);
90 0           my $data_dir = $self->{+DATA_DIR};
91              
92 0 0         if ($self->{+USE_BOOTSTRAP}) {
93 0 0         if ($self->{+USE_INSTALLDB}) {
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     0     my $self = shift;
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             1;
122              
123             __END__