EV/ConnectInfo.pm

filter: Statementstmt 40.7% 11 / 27 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 75.0% 3 / 4 Podpod 0.0% 0 / 1 totaltotal 21.2% 14 / 66 CC 13 SCAR 50.0
CC
13
Cov
21%
dbi_to_conninfo
182.0
BEGIN
1.0
BEGIN
1.0
CRAP 148.1
↑ Summary EV/TestHarness.pm »
1 package DBIO::MySQL::EV::ConnectInfo;
2 # ABSTRACT: MySQL/MariaDB connection-info utilities for DBIO async driver
3  
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our @EXPORT_OK = qw( dbi_to_conninfo );
9  
10  
11 0 ▶sub dbi_to_conninfo {
Subroutine dbi_to_conninfo: not called CC=13 SCAR=52.0
Pod undocumented
12 0 my ($info) = @_;
13 0 my ($dsn, $user, $pass, $attrs) = @$info;
14 0 ▶ die "expected dbi:mysql:/dbi:MariaDB:... DSN, got: " . (defined $dsn ? $dsn : '(undef)') . "\n"
Branch: 2 branches
BranchTrueFalseTotal
unless defined $dsn and $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i 0 0 0
defined $dsn ? : 0 0 0
Condition0%0/3
defined $dsn and $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dsn and $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
defined $dsn $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
Truth table0%0/3
A and B
A= defined $dsnB= $dsn =~ s/^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$/$1/i
ABresult
0X0
100
111
15 unless defined $dsn && $dsn =~ s{^dbi:(?:mysql(?:\.\w+)?|mariadb):(.+)$}{$1}i;
16 0 my $params = $1;
17 0 my %h;
18 0 for my $kv (split /;/, $params) {
19 0 ▶ next unless $kv =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $kv =~ /\S/ 0 0 0
20 0 my ($k, $v) = split /=/, $kv, 2;
21 0 $k = lc $k;
22 0 ▶ $k = 'database' if $k eq 'dbname';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "dbname" 0 0 0
23 0 $h{$k} = $v;
24 }
25 0 ▶ $h{user} //= $user if defined $user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $user 0 0 0
Condition0%0/3
$h{"user"} //= $user
l!l&&r!l&&!r
000
MC/DC0%0/2
$h{"user"} //= $user
$h{"user"} $user
Truth table0%0/3
A //= B
A= $h{"user"}B= $user
ABresult
1X1
011
000
26 0 ▶ $h{password} //= $pass if defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pass 0 0 0
Condition0%0/3
$h{"password"} //= $pass
l!l&&r!l&&!r
000
MC/DC0%0/2
$h{"password"} //= $pass
$h{"password"} $pass
Truth table0%0/3
A //= B
A= $h{"password"}B= $pass
ABresult
1X1
011
000
27 0 my %opts;
28 0 ▶ $h{pool_size} = $attrs->{pool_size} if ref $attrs eq 'HASH' && $attrs->{pool_size};
Branch: 1 branch
BranchTrueFalseTotal
if ref $attrs eq "HASH" and $attrs->{"pool_size"} 0 0 0
Condition0%0/3
ref $attrs eq "HASH" and $attrs->{"pool_size"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $attrs eq "HASH" and $attrs->{"pool_size"}
ref $attrs eq "HASH" $attrs->{"pool_size"}
Truth table0%0/3
A and B
A= ref $attrs eq "HASH"B= $attrs->{"pool_size"}
ABresult
0X0
100
111
29 0 return [ \%h, \%opts ];
30 }
31  
32 7 1;
33  
34 __END__
35  
36 =pod
37  
38 =encoding UTF-8
39  
40 =head1 NAME
41  
42 DBIO::MySQL::EV::ConnectInfo - MySQL/MariaDB connection-info utilities for DBIO async driver
43  
44 =head1 VERSION
45  
46 version 0.900001
47  
48 =func dbi_to_conninfo
49  
50 my $async_info = dbi_to_conninfo([ 'dbi:MariaDB:database=test;host=localhost', $user, $pass, \%attrs ]);
51  
52 Translate a DBI-style connect-info arrayref (C<[$dsn, $user, $pass, \%attrs]>,
53 as produced by the sync L<DBIO::MySQL::Storage>) into the async
54 C<[ \%conninfo, \%opts ]> shape consumed by L<DBIO::MySQL::EV::Storage>.
55  
56 The C<dbi:mysql:> / C<dbi:MariaDB:> DSN is parsed into named L<EV::MariaDB>
57 parameters (C<host>, C<port>, C<database>, ...); C<dbname> is normalised to
58 C<database> (EV::MariaDB's spelling). C<$user> / C<$pass> fill in C<user> /
59 C<password> when not already present in the DSN. A C<pool_size> attribute, if
60 given, is carried into the conninfo hash. Dies unless the DSN is in a
61 C<dbi:mysql:>-family form, since EV::MariaDB does not understand the DSN string.
62  
63 =head1 AUTHOR
64  
65 DBIO Authors
66  
67 =head1 COPYRIGHT AND LICENSE
68  
69 Copyright (C) 2026 DBIO Authors
70  
71 This is free software; you can redistribute it and/or modify it under
72 the same terms as the Perl 5 programming language system itself.
73  
74 =cut
↑ Summary EV/TestHarness.pm »