| 1 | package App::JESP::Driver::mysql; | ||||||||||||||||||||||||||||
| 2 | 1 | $App::JESP::Driver::mysql::VERSION = '0.016'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | extends qw/App::JESP::Driver/; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Which qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IPC::Run qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Log::Any qw/$log/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use String::ShellQuote; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | App::JESP::Driver::mysql - mysql driver. Subclasses App::JESP::Driver | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | has 'mysql' => ( is => 'ro', isa => 'Str', lazy_build => 1 ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub _build_mysql{ | ||||||||||||||||||||||||||
|
Subroutine
_build_mysql: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 24 | 0 | my $mysql = File::Which::which('mysql'); | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | unless( $mysql ){ die "Cannot find 'mysql' in path ".$ENV{PATH}.". Set this in the plan."; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless( -x $mysql ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | die "Found '$mysql' but it is not executable\n"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | $log->info("Found mysql client at '$mysql'"); | |||||||||||||||||||||||||||
| 30 | 0 | return $mysql; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 apply_sql | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Specificaly apply sql to mysql by using the command line client. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | See Superclass. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub apply_sql{ | ||||||||||||||||||||||||||
|
Subroutine
apply_sql: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self, $sql) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | my $mysql = $self->mysql(); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my @cmd = ( $mysql ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Time to build the command according to the dsn properties | ||||||||||||||||||||||||||||
| 48 | 0 | my $properties = {}; | |||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | eval "require DBD::mysql" or die "Please install DBD::mysql for this to work\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn( $self->jesp()->dsn() ); | |||||||||||||||||||||||||||
| 53 | 0 | DBD::mysql->_OdbcParse( $driver_dsn , $properties , [] ); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $properties->{user} ||= $self->jesp()->username(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$properties->{"user"} ||= $self->jesp->username
MC/DC0%0/2
$properties->{"user"} ||= $self->jesp->username
$properties->{"user"}
$self->jesp->username
Truth table0%0/3
A ||= B
A= $properties->{"user"}B= $self->jesp->username
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $properties->{password} ||= $self->jesp()->password(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$properties->{"password"} ||= $self->jesp->password
MC/DC0%0/2
$properties->{"password"} ||= $self->jesp->password
$properties->{"password"}
$self->jesp->password
Truth table0%0/3
A ||= B
A= $properties->{"password"}B= $self->jesp->password
| |||||||||||||||||||||||||||||
| 56 | 0 | $log->trace('mysql properties: '.Dumper( $properties )); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | push @cmd , '-B'; # This is a batch command. We dont want interactive at all. | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if( my $user = $properties->{user} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | push @cmd , ( '-u' , String::ShellQuote::shell_quote( $user )); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if( my $database = $properties->{database} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | push @cmd , ( '-D' , String::ShellQuote::shell_quote( $database )); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if( my $host = $properties->{host} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | push @cmd , ( '-h' , String::ShellQuote::shell_quote( $host )); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if( my $port = $properties->{port} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | push @cmd , ( '-P' , String::ShellQuote::shell_quote( $port )); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if( my $mysql_socket = $properties->{mysql_socket} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | push @cmd , ( '-S' , String::ShellQuote::shell_quote( $mysql_socket )); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if( my $password = $properties->{password} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | push @cmd , ( '-p'.String::ShellQuote::shell_quote( $password )); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $on_stdout = sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 0 | $log->info( @_ ); | |||||||||||||||||||||||||||
| 83 | 0 | }; | |||||||||||||||||||||||||||
| 84 | 0 | my @stderr; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $on_stderr = sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 0 | $log->warn( @_ ); | |||||||||||||||||||||||||||
| 87 | 0 | push @stderr , @_; | |||||||||||||||||||||||||||
| 88 | 0 | }; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Outside testing, be verbose. | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | local $ENV{IPCRUNDEBUG} = 'basic' unless( $ENV{AUTOMATED_TESTING} || $ENV{HARNESS_ACTIVE} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"AUTOMATED_TESTING"} or $ENV{"HARNESS_ACTIVE"}
MC/DC0%0/2
$ENV{"AUTOMATED_TESTING"} or $ENV{"HARNESS_ACTIVE"}
$ENV{"AUTOMATED_TESTING"}
$ENV{"HARNESS_ACTIVE"}
Truth table0%0/3
A or B
A= $ENV{"AUTOMATED_TESTING"}B= $ENV{"HARNESS_ACTIVE"}
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | IPC::Run::run( \@cmd, \$sql , $on_stdout , $on_stderr ) or die join(' ', @cmd).": $? : ".join("\n", @stderr )."\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | $log->info("Done"); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||||||||