Async/ConnectInfo.pm

filter: Statementstmt 86.3% 19 / 22 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 72.5% 29 / 40 CC 5 SCAR 13.0
CC
5
Cov
77%
escape_conninfo
6.5
conninfo_string
2.0
BEGIN
1.0
CRAP 3.7
« Async/Storage.pm ↑ Summary Async/TransactionContext.pm »
1 package DBIO::PostgreSQL::Async::ConnectInfo;
2 # ABSTRACT: PostgreSQL connection string utilities for DBIO async driver
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our @EXPORT_OK = qw( escape_conninfo conninfo_string );
9  
10  
11 sub escape_conninfo {
12 2 ▶ my $val = shift;
Subroutine escape_conninfo: called CC=4 SCAR=18.7
Pod undocumented
13 2 ▶ return "''" unless defined $val && length $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and length $val 0 2 2
Condition33%1/3
defined $val and length $val
!ll&&!rl&&r
002
MC/DC0%0/2
defined $val and length $val
defined $val length $val
Truth table33%1/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
14 2 ▶ return $val unless $val =~ /[\s'\\]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /[\s'\\]/ 2 0 2
15 0 $val =~ s/\\/\\\\/g;
16 0 $val =~ s/'/\\'/g;
17 0 return "'$val'";
18 }
19  
20  
21 sub conninfo_string {
22 2 ▶ my ($ci) = @_;
Subroutine conninfo_string: called CC=2 SCAR=6.9
Pod undocumented
23 2 ▶ return $ci unless ref $ci;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ci 1 1 2
24  
25 2 return join(' ', map { "$_=" . escape_conninfo($ci->{$_}) }
26 1 grep { defined $ci->{$_} } keys %$ci);
27 }
28  
29 5 1;
30  
31 __END__
32  
33 =pod
34  
35 =encoding UTF-8
36  
37 =head1 NAME
38  
39 DBIO::PostgreSQL::Async::ConnectInfo - PostgreSQL connection string utilities for DBIO async driver
40  
41 =head1 VERSION
42  
43 version 0.900000
44  
45 =func escape_conninfo
46  
47 my $escaped = escape_conninfo($value);
48  
49 Escape a single connection parameter value for use in a libpq conninfo string.
50 Handles whitespace, single quotes, and backslashes.
51  
52 =func conninfo_string
53  
54 my $str = conninfo_string({ host => 'localhost', port => 5432 });
55  
56 Convert a hashref of connection parameters into a libpq connection string.
57 Skips undefined values.
58  
59 =head1 AUTHOR
60  
61 DBIO Authors
62  
63 =head1 COPYRIGHT AND LICENSE
64  
65 Copyright (C) 2026 DBIO Authors
66  
67 This is free software; you can redistribute it and/or modify it under
68 the same terms as the Perl 5 programming language system itself.
69  
70 =cut
« Async/Storage.pm ↑ Summary Async/TransactionContext.pm »