| 1 | package DBIO::MySQL::EV::ConnectInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MySQL/MariaDB connection-info utilities for DBIO async driver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 51 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 51 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 51 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 51 | ▶ | use DBIO::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 51 | ▶ | use DBIO::Storage (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 51 | our @EXPORT_OK = qw( dbi_to_conninfo ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # What EV::MariaDB->new takes besides its callbacks and loop (EV::MariaDB 0.09, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # %ALLOWED_ARGS). db, its alias of database, is read as database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 51 | my %NATIVE = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | host port user password database unix_socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | connect_timeout read_timeout write_timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | compress multi_statements charset init_command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ssl_key ssl_cert ssl_ca ssl_capath ssl_cipher ssl_verify_server_cert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | utf8 found_rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # The DSN keys of DBD::mysql and DBD::MariaDB that EV::MariaDB has a parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # for, by the part after the mysql_ / mariadb_ prefix (both DBDs read their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # connect attributes out of the DSN too, and out of the attribute hash). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # mysql_ssl has no parameter of its own, and mysql_enable_utf8mb4 / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # mysql_enable_utf8 (DBD::mysql only; DBD::MariaDB has no such attribute, it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # always utf8mb4) stand for two parameters, charset and utf8: both are handled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # apart. The other attributes of the DBDs (mariadb_auto_reconnect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # mysql_ssl_optional, mysql_read_default_file, ...) have nothing to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # translated into and are refused, in the DSN and among the attributes alike. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # The one exception is *_auto_reconnect with a false value (0, ''): it asks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # for nothing and is let through, leaving no key (karr k80). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 51 | my %DBD_KEY = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | socket => 'unix_socket', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | connect_timeout => 'connect_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | read_timeout => 'read_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | write_timeout => 'write_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | compression => 'compress', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | init_command => 'init_command', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | multi_statements => 'multi_statements', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | client_found_rows => 'found_rows', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ssl_ca_file => 'ssl_ca', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ssl_ca_path => 'ssl_capath', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ssl_client_key => 'ssl_key', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ssl_client_cert => 'ssl_cert', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ssl_cipher => 'ssl_cipher', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ssl_verify_server_cert => 'ssl_verify_server_cert', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # The attributes the storage takes out of the connect attributes itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # (DBIO::Storage::Async::_strip_private_connect_attrs). A broker's DBI-form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # answer may carry them: a Vault broker selects this transport with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # async => 'ev'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 78 | ▶ | sub _dbio_private_attr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbio_private_attr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 78 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 78 | return scalar grep { $_ eq $name } 'async', 'ignore_version', 'cursor_class', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | DBIO::Storage->_dbio_storage_option_names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | DBIO::Storage->_dbio_sql_maker_option_names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Every refusal reads alike, so a caller reading another's answer (the broker's) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # can tell it from a DSN that is no DSN of this driver. Names and keys only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 40 | ▶ | sub _refuse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 40 | my ($what) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 40 | die "MySQL ev refuses the connect info: $what\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 35 | ▶ | sub _sorted_unique { sort keys %{{ map { $_ => 1 } @_ }} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sorted_unique: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # The parameters of a DSN's tail (after dbi:mysql:) as EV::MariaDB named | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 230 | ▶ | sub _dsn_parameters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dsn_parameters: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 230 | my ($params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 230 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 230 | ▶ | if ($params !~ /=/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # database[:host[:port]], read the way both DBDs read it and the way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # dbio-mysql reads it (karr k98). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | _refuse('a positional part beside a semicolon') if $params =~ /;/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | my @part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | my $left = $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | while (length $left) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 18 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 18 | ▶ | if ($left =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | ($val, $left) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | ($val, $left) = ($left, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 18 | $val =~ s/\[|]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 18 | push @part, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | _refuse('a positional DSN with more than database, host and port') if @part > 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | for my $name (qw( database host port )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 18 | my $val = shift @part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 18 | ▶ | $h{$name} = $val if defined $val && length $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $val and length $val
MC/DC100%2/2
defined $val and length $val
defined $val
length $val
Truth table100%3/3
A and B
A= defined $valB= length $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | return { h => \%h, from => {}, src => {}, unknown => [], twice => [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 222 | my %st = ( h => \%h, from => {}, src => {}, unknown => [], twice => [] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 222 | for my $kv (split /;/, $params) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 594 | ▶ | next unless $kv =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 594 | ▶ | _refuse('a positional part beside key=value parts') unless $kv =~ /^[^=]+=/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 593 | my ($k, $v) = split /=/, $kv, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 593 | _absorb(\%st, 'dsn', lc $k, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 221 | return \%st; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # One key of a DSN or of the attribute hash, by its lowercase name, into the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # state of the reading (%st). $src is 'dsn' or 'attr'. Only the keys of a DSN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # are bare EV::MariaDB names or the host / dbname aliases; both sources take | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # the DBD ones under their mysql_ / mariadb_ prefix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 635 | ▶ | sub _absorb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_absorb: called CC=21 SCAR=30.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 635 | my ($st, $src, $k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | my $target = $src ne 'dsn' ? undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | : $k eq 'hostname' ? 'host' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | : $k eq 'dbname' || $k eq 'db' ? 'database' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 635 | ▶ | : $NATIVE{$k} ? $k | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$k eq "dbname" or $k eq "db"
MC/DC50%1/2
$k eq "dbname" or $k eq "db"
$k eq "dbname"
$k eq "db"
Truth table66%2/3
A or B
A= $k eq "dbname"B= $k eq "db"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 635 | ▶ | if (!defined $target && $k =~ /^(?:mysql|mariadb)_(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $target and $k =~ /^(?:mysql|mariadb)_(.+)$/
MC/DC100%2/2
not defined $target and $k =~ /^(?:mysql|mariadb)_(.+)$/
not defined $target
$k =~ /^(?:mysql|mariadb)_(.+)$/
Truth table100%3/3
not(A) and B
A= not defined $targetB= $k =~ /^(?:mysql|mariadb)_(.+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 96 | my $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 96 | ▶ | if ($name eq 'ssl') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | $st->{ssl} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 90 | ▶ | if (($k =~ /^mysql_/) && ($name eq 'enable_utf8mb4' || $name eq 'enable_utf8')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$k =~ /^mysql_/ and $name eq "enable_utf8mb4" || $name eq "enable_utf8"
$name eq "enable_utf8mb4" or $name eq "enable_utf8"
MC/DC100%3/3
$k =~ /^mysql_/ and $name eq "enable_utf8mb4" || $name eq "enable_utf8"
$k =~ /^mysql_/
$name eq "enable_utf8mb4"
$name eq "enable_utf8"
Truth table100%4/4
A and B or C
A= $k =~ /^mysql_/B= $name eq "enable_utf8mb4"C= $name eq "enable_utf8"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Two parameters at once, settled when everything is read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | $st->{enable}{$name} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # auto_reconnect off asks for nothing: this transport never reconnects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # silently. Only a true value is a request it cannot meet (karr k80). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 78 | ▶ | return if $name eq 'auto_reconnect' && !$v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq "auto_reconnect" and not $v
MC/DC100%2/2
$name eq "auto_reconnect" and not $v
$name eq "auto_reconnect"
not $v
Truth table100%3/3
A and not(B)
A= $name eq "auto_reconnect"B= not $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 67 | $target = $DBD_KEY{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 606 | ▶ | unless (defined $target) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 29 | push @{ $st->{unknown} }, $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 29 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # The same parameter twice: under another name, or (DSN against attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # hash) with another value. The attribute hash and the one beside it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # override each other, as their other keys do. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | push @{ $st->{twice} }, $target | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | if exists $st->{from}{$target} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | && ($st->{from}{$target} ne $k | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | || ($st->{src}{$target} ne $src | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 577 | ▶ | && (defined $v ? $v : '') ne (defined $st->{h}{$target} ? $st->{h}{$target} : ''))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%9/9
exists $st->{"from"}{$target} and $st->{"from"}{$target} ne $k || $st->{"src"}{$target} ne $src && (defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
$st->{"from"}{$target} ne $k or $st->{"src"}{$target} ne $src and (defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
$st->{"src"}{$target} ne $src and (defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
MC/DC100%4/4
exists $st->{"from"}{$target} and $st->{"from"}{$target} ne $k || $st->{"src"}{$target} ne $src && (defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
exists $st->{"from"}{$target}
$st->{"from"}{$target} ne $k
$st->{"src"}{$target} ne $src
(defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
Truth table100%5/5
A and B or C and D
A= exists $st->{"from"}{$target}B= $st->{"from"}{$target} ne $kC= $st->{"src"}{$target} ne $srcD= (defined $v ? $v : "") ne (defined $st->{"h"}{$target} ? $st->{"h"}{$target} : "")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 577 | $st->{from}{$target} = $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 577 | $st->{src}{$target} = $src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 577 | $st->{h}{$target} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 577 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # The reading done: what the DBD keys that stand for several parameters mean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # and the refusals. Names keys, never a value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 227 | ▶ | sub _settle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_settle: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 227 | my ($st) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 227 | my $h = $st->{h}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # mysql_enable_utf8mb4 (utf8mb4) wins over mysql_enable_utf8 (utf8), as in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # DBD::mysql. Either asks for the charset and for the strings coming back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # flagged as characters, which is what EV::MariaDB's utf8 => 1 does (karr k80). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # An explicit charset / utf8 stands only if it says the same. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 227 | my ($charset) = map { $_->[1] } grep { $st->{enable}{ $_->[0] } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | [ enable_utf8mb4 => 'utf8mb4' ], [ enable_utf8 => 'utf8' ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 227 | ▶ | if ($charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | ▶ | push @{ $st->{twice} }, 'charset' if defined $h->{charset} && $h->{charset} ne $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $h->{"charset"} and $h->{"charset"} ne $charset
MC/DC100%2/2
defined $h->{"charset"} and $h->{"charset"} ne $charset
defined $h->{"charset"}
$h->{"charset"} ne $charset
Truth table100%3/3
A and B
A= defined $h->{"charset"}B= $h->{"charset"} ne $charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | ▶ | $h->{charset} //= $charset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$h->{"charset"} //= $charset
MC/DC0%0/2
$h->{"charset"} //= $charset
$h->{"charset"}
$charset
Truth table66%2/3
A //= B
A= $h->{"charset"}B= $charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | ▶ | $h->{utf8} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$h->{"utf8"} //= 1
MC/DC100%1/1
$h->{"utf8"} //= 1
$h->{"utf8"}
Truth table100%2/2
A
A= $h->{"utf8"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | _refuse(sprintf 'key(s) EV::MariaDB has no parameter for (%s); a DSN or the attributes ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | . 'here take host, port, database (dbname), user, password, the EV::MariaDB ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | . 'parameter names (DSN only) and of the DBD ones mysql_enable_utf8mb4, ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | . 'mysql_enable_utf8 and %s (mariadb_ likewise, except those two)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 26 | join(', ', _sorted_unique(@{ $st->{unknown} })), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 227 | ▶ | join(', ', map { "mysql_$_" } sort keys %DBD_KEY)) if @{ $st->{unknown} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | _refuse(sprintf 'DSN and attributes give (%s) more than once under different names or values', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 201 | ▶ | join(', ', _sorted_unique(@{ $st->{twice} }))) if @{ $st->{twice} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 197 | my $ssl = $st->{ssl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | _refuse('mysql_ssl (mariadb_ssl) without any of mysql_ssl_ca_file, ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | . 'mysql_ssl_ca_path, mysql_ssl_client_cert, mysql_ssl_client_key or ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | . 'mysql_ssl_cipher: EV::MariaDB turns SSL on by those alone, so the ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | . 'connection would be opened without it') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | if defined $ssl && length $ssl && $ssl ne '0' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 197 | ▶ | && !grep { defined $h->{$_} } qw( ssl_ca ssl_capath ssl_cert ssl_key ssl_cipher ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $ssl and length $ssl and $ssl ne 0 and not grep({defined $h->{$_};} "ssl_ca", "ssl_capath", "ssl_cert", "ssl_key", "ssl_cipher")
defined $ssl and length $ssl and $ssl ne 0
defined $ssl and length $ssl
MC/DC75%3/4
defined $ssl and length $ssl and $ssl ne 0 and not grep({defined $h->{$_};} "ssl_ca", "ssl_capath", "ssl_cert", "ssl_key", "ssl_cipher")
defined $ssl
length $ssl
$ssl ne 0
not grep({defined $h->{$_};} "ssl_ca", "ssl_capath", "ssl_cert", "ssl_key", "ssl_cipher")
Truth table80%4/5
A and B and C and not(D)
A= defined $sslB= length $sslC= $ssl ne 0D= not grep({defined $h->{$_};} "ssl_ca", "ssl_capath", "ssl_cert", "ssl_key", "ssl_cipher")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 195 | return $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 250 | ▶ | sub dbi_to_conninfo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbi_to_conninfo: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 250 | my ($info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Copies: a slice of @$info itself would create the slots it looks at, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # the array is the caller's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 250 | my ($dsn, $user, $pass, $attrs, $extra_attrs) = @$info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # The DSN is named, never its password (karr k76): masked as core masks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # connect info in every message, given the connect info it belongs to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 250 | ▶ | die DBIO::Util::mask_connect_secrets( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $dsn and $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
MC/DC100%2/2
defined $dsn and $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
defined $dsn
$dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
Truth table100%3/3
A and B
A= defined $dsnB= $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 'expected dbi:mysql:/dbi:MariaDB:... DSN, got: ' . (defined $dsn ? $dsn : '(undef)') . "\n", $info, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ) unless defined $dsn && $dsn =~ s{^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$}{$1}i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 230 | my $st = _dsn_parameters($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 227 | my %h = %{ $st->{h} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 227 | $st->{h} = \%h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # The explicit credentials beat the DSN's own (karr k64): a broker's answer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # carries the credentials that rotate, a DSN written earlier does not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 227 | ▶ | $h{user} = $user if defined $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 227 | ▶ | $h{password} = $pass if defined $pass; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 227 | my (%opts, @unapplied); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # \%attrs, then \%extra_attributes: the later one wins. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 227 | for my $given (grep { ref $_ eq 'HASH' } $attrs, $extra_attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 160 | ▶ | $h{pool_size} = $given->{pool_size} if $given->{pool_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # The DBD attributes (mysql_*, mariadb_*) EV::MariaDB has a parameter for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # are read like the same keys of the DSN; any other is refused, not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # dropped (karr k80). An undef value names nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 160 | ▶ | for my $k (sort grep { /^(?:mysql|mariadb)_/i && defined $given->{$_} } keys %$given) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
/^(?:mysql|mariadb)_/i && defined $given->{$_}
MC/DC100%2/2
/^(?:mysql|mariadb)_/i && defined $given->{$_}
/^(?:mysql|mariadb)_/i
defined $given->{$_}
Truth table100%3/3
A && B
A= /^(?:mysql|mariadb)_/iB= defined $given->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 42 | _absorb($st, 'attr', lc $k, $given->{$k}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # A connection parameter among the attributes (charset, connect_timeout, ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # is no DBI attribute and would be lost: refused (karr k80), by the measure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # of the options beside an AccessBroker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # (Storage::_mysql_refuse_parameters_beside_broker). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | push @unapplied, grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 160 | ▶ | $_ ne 'pool_size' && defined $given->{$_} && length $given->{$_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%12/12
$_ ne 'pool_size' && defined $given->{$_} && length $given->{$_} && !/^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/ && !_dbio_private_attr($_)
$_ ne "pool_size" and defined $given->{$_} and length $given->{$_} and not /^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/
$_ ne "pool_size" and defined $given->{$_} and length $given->{$_}
$_ ne "pool_size" and defined $given->{$_}
MC/DC100%5/5
$_ ne 'pool_size' && defined $given->{$_} && length $given->{$_} && !/^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/ && !_dbio_private_attr($_)
$_ ne "pool_size"
defined $given->{$_}
length $given->{$_}
not /^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/
!_dbio_private_attr($_)
Truth table100%6/6
A and B and C and not(D) && not(E)
A= $_ ne "pool_size"B= defined $given->{$_}C= length $given->{$_}D= not /^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/E= !_dbio_private_attr($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | && !/^(?:[A-Z]|private_|dbi_|dbd_|mysql_|mariadb_)/ && !_dbio_private_attr($_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } keys %$given; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 227 | _settle($st); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 195 | ▶ | _refuse(sprintf 'connection parameter(s) given as connect attributes (%s) would ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | . 'be dropped, EV::MariaDB being no DBD. Give them in the DSN ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | . '(charset=...;connect_timeout=...); of the attributes only pool_size is ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | . 'read, and DBI attributes are dropped', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | join(', ', _sorted_unique(@unapplied))) if @unapplied; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 190 | return [ \%h, \%opts ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 51 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||