| 1 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Oracle::TNS -- parse Oracle TNS descriptors / tnsnames.ora into a hashtree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## and build descriptor strings back from a hashtree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Copyright (c) 2026 Vladi Belperchinov-Shabanski "Cade" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## <cade@noxrun.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## http://cade.noxrun.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## LICENSE: GPLv2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ## Hashtree layout: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ## (DESCRIPTION=(ADDRESS=(HOST=a)(PORT=1521))(ADDRESS=(HOST=b)(PORT=1521)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ## (CONNECT_DATA=(SERVICE_NAME=X))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ## becomes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ## { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ## DESCRIPTION => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ## ADDRESS => [ { HOST => 'a', PORT => 1521 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ## { HOST => 'b', PORT => 1521 } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ## CONNECT_DATA => { SERVICE_NAME => 'X' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ## } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ## } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ## Repeated keys at the same level are collected into an array reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ## Keys are uppercased on parse. A single-element value may be given either | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ## as a scalar/hashref or as a one-element arrayref when building. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | package Oracle::TNS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | use Hash::Util::FieldHash qw( fieldhash ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | our $VERSION = '1.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | tns_parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | tns_parse_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | tns_build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | tns_build_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | tns_parse_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | tns_build_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | tns_mask_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # preferred output order for well-known keys, everything else sorted after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | our @KEY_ORDER = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | DESCRIPTION_LIST DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | LOAD_BALANCE FAILOVER SOURCE_ROUTE ENABLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ADDRESS_LIST ADDRESS PROTOCOL HOST PORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | CONNECT_DATA SERVICE_NAME SID SERVER INSTANCE_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | SECURITY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | my %KEY_RANK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | @KEY_RANK{ @KEY_ORDER } = ( 1 .. @KEY_ORDER ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # parsed hashref => [ [ KEY, value ], ... ] in parsed order, nested hashrefs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # weakened, used by tns_build() to keep the original order of values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # entries vanish with their hashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | fieldhash my %KEY_SEEN_ORDER; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ## PARSING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # parses a single descriptor string, e.g. "(DESCRIPTION=...)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # returns ( $hashtree, undef ) on success, ( undef, $error_message ) on error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub tns_parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 39 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 39 | my $str = __strip_comments( shift ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 39 | my $tree = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 39 | my $err = __parse_items( \$str, $tree ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 39 | ▶ | return ( undef, $err ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 32 | $str =~ /\G\s*/gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 32 | ▶ | return ( undef, "trailing data at offset " . pos( $str ) ) if pos( $str ) < length( $str ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 29 | ▶ | return ( undef, "empty descriptor" ) unless %$tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 26 | return ( $tree, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # parses tnsnames.ora content: "ALIAS[, ALIAS2] = (DESCRIPTION=...)" entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # and "NAME = value" entries (e.g. IFILE), one top-level group per alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # returns ( { ALIAS => $hashtree, NAME => $value, ... }, undef ) or ( undef, $error_message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub tns_parse_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_parse_names: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | my $str = __strip_comments( shift ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | my $names = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | ▶ | while( $str =~ /\G\s*([A-Za-z0-9_.\-]+(?:\s*,\s*[A-Za-z0-9_.\-]+)*)\s*=/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 25 | my @aliases = map { uc } split /\s*,\s*/, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 25 | ▶ | if( $str =~ /\G[^\S\n]*(?:"([^"\n]*)"|([^\s()"=](?:[^\n()"=]*[^\s()"=])?))[^\S\n]*(?=\n|\z)/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # "NAME = value" entry, repeated names collected into arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 10 | ▶ | my $val = defined $1 ? $1 : $2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 10 | for my $alias ( @aliases ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # same alias given as descriptor before, last one wins as for descriptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 10 | ▶ | delete $names->{ $alias } if ref( $names->{ $alias } ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 10 | __add_item( $names, $alias, $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | my $tree = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 15 | my $err = __parse_items( \$str, $tree, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 15 | ▶ | return ( undef, "alias $aliases[0]: $err" ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 14 | ▶ | return ( undef, "alias $aliases[0]: empty descriptor" ) unless %$tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 | $names->{ $_ } = $tree for @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | $str =~ /\G\s*/gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | ▶ | return ( undef, "unparsed data at offset " . pos( $str ) ) if pos( $str ) < length( $str ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | return ( $names, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # removes "# ..." comments up to the end of line, outside of quoted values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | sub __strip_comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__strip_comments: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 51 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 51 | ▶ | $str =~ s/("[^"]*")|#[^\n]*/defined $1 ? $1 : ''/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 51 | pos( $str ) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 51 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # parses "(KEY=VALUE)" / "(KEY=(...)(...))" groups into $hr, at most $max if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # returns undef on success, error message on failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | sub __parse_items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 176 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__parse_items: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 176 | my ( $sr, $hr, $max ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 176 | ▶ | my $order = $KEY_SEEN_ORDER{ $hr } ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$KEY_SEEN_ORDER{$hr} ||= []
MC/DC0%0/1
$KEY_SEEN_ORDER{$hr} ||= []
$KEY_SEEN_ORDER{$hr}
Truth table50%1/2
A
A= $KEY_SEEN_ORDER{$hr}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 176 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 176 | ▶ | while( ( ! $max or $count++ < $max ) and $$sr =~ /\G\s*\(/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
!$max || $count++ < $max and $$sr =~ /\G\s*\(/cg
not $max or $count++ < $max
MC/DC100%3/3
!$max || $count++ < $max and $$sr =~ /\G\s*\(/cg
not $max
$count++ < $max
$$sr =~ /\G\s*\(/cg
Truth table100%5/5
not(A) or B and C
A= not $maxB= $count++ < $maxC= $$sr =~ /\G\s*\(/cg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 299 | ▶ | return "expected KEY= at offset " . pos( $$sr ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | unless $$sr =~ /\G\s*([A-Za-z0-9_.\-]+)\s*=/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 297 | my $key = uc $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 297 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 297 | ▶ | if( $$sr =~ /\G(?=\s*\()/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # nested groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 122 | $val = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 122 | my $err = __parse_items( $sr, $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 122 | ▶ | return $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | elsif( $$sr =~ /\G\s*"([^"]*)"\s*/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # quoted scalar value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | $val = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | elsif( $$sr =~ /\G\s*([^()"]*?)\s*(?=\))/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # bare scalar value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 163 | $val = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | return "bad value for $key at offset " . pos( $$sr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 295 | ▶ | return "expected ) after $key at offset " . pos( $$sr ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | unless $$sr =~ /\G\s*\)/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 291 | __add_item( $hr, $key, $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 291 | push @$order, [ $key, $val ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 291 | ▶ | weaken( $order->[ -1 ][ 1 ] ) if ref( $val ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 168 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # adds a value under key, promoting to arrayref on repeated keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub __add_item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 301 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__add_item: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 301 | my ( $hr, $key, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 301 | ▶ | if( ! exists $hr->{ $key } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 272 | $hr->{ $key } = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | elsif( ref( $hr->{ $key } ) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | push @{ $hr->{ $key } }, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 27 | $hr->{ $key } = [ $hr->{ $key }, $val ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ## BUILDING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # builds descriptor string from hashtree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # $indent: undef -> single line, otherwise number of spaces per nesting level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # returns ( $string, undef ) or ( undef, $error_message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub tns_build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_build: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 51 | my ( $tree, $indent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 51 | ▶ | return ( undef, "hashref expected" ) unless ref( $tree ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 47 | ▶ | return ( undef, "empty hashtree" ) unless %$tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 45 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 45 | my $err = __build_items( $tree, \$out, $indent, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 45 | ▶ | return ( undef, $err ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 35 | $out =~ s/^\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 35 | return ( $out, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # builds tnsnames.ora content from { ALIAS => $hashtree, NAME => $value, ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # returns ( $string, undef ) or ( undef, $error_message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | sub tns_build_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_build_names: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | my ( $names, $indent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 14 | ▶ | return ( undef, "hashref expected" ) unless ref( $names ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 13 | ▶ | $indent = 2 unless defined $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 13 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 13 | for my $alias ( sort keys %$names ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 19 | my $v = $names->{ $alias }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 19 | ▶ | if( ! ref( $v ) or ref( $v ) eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $v or ref $v eq "ARRAY"
MC/DC100%2/2
not ref $v or ref $v eq "ARRAY"
not ref $v
ref $v eq "ARRAY"
Truth table100%3/3
not(A) or B
A= not ref $vB= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # "NAME = value" entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | for my $item ( ref( $v ) ? @$v : ( $v ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 11 | my $val = $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 11 | ▶ | return ( undef, "alias $alias: undefined value" ) unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 9 | ▶ | return ( undef, "alias $alias: hashref or scalar expected" ) if ref( $val ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 8 | ▶ | return ( undef, "alias $alias: double quote in value is not supported" ) if $val =~ /"/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | ▶ | return ( undef, "alias $alias: multiline value is not supported" ) if $val =~ /\n/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | ▶ | $val = qq["$val"] if $val eq '' or $val =~ /[()=#]|^\s|\s$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val eq "" or $val =~ /[()=#]|^\s|\s$/
MC/DC100%2/2
$val eq "" or $val =~ /[()=#]|^\s|\s$/
$val eq ""
$val =~ /[()=#]|^\s|\s$/
Truth table100%3/3
A or B
A= $val eq ""B= $val =~ /[()=#]|^\s|\s$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | $out .= "$alias = $val\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 11 | my ( $str, $err ) = tns_build( $v, $indent ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 11 | ▶ | return ( undef, "alias $alias: $err" ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 9 | $str =~ s/^/ /mg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 9 | $out .= "$alias =\n$str\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | return ( $out, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # emits all "(KEY=...)" groups of $hr into $$out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | sub __build_items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 165 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__build_items: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 165 | my ( $hr, $out, $indent, $level ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 165 | ▶ | my $pad = defined $indent ? "\n" . ( ' ' x ( $indent * $level ) ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 165 | for my $item ( __ordered_items( $hr ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 299 | my ( $key, $val ) = @$item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 299 | $$out .= "$pad($key="; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 299 | ▶ | if( ref( $val ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 122 | ▶ | return "empty hashref for $key" unless %$val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 120 | my $err = __build_items( $val, $out, $indent, $level + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 120 | ▶ | return $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 118 | ▶ | $$out .= $pad if defined $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | elsif( ! ref( $val ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 174 | ▶ | return "undefined value for $key" unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 171 | ▶ | return "double quote in value for $key is not supported" if $val =~ /"/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 169 | ▶ | $val = qq["$val"] if $val =~ /[()\s=#]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 169 | $$out .= $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | return "unsupported value type " . ref( $val ) . " for $key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 287 | $$out .= ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 153 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # returns ( [ KEY, value ], ... ) in output order: values found at parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # time go to their parsed position, other values of a parsed key follow the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # previous value of that key (or take its first position), keys not seen at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # parse time (or all, if not parsed) follow in predefined order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | sub __ordered_items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 165 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ordered_items: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 165 | my $hr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 165 | ▶ | my $slots = $KEY_SEEN_ORDER{ $hr } || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$KEY_SEEN_ORDER{$hr} || []
MC/DC100%1/1
$KEY_SEEN_ORDER{$hr} || []
$KEY_SEEN_ORDER{$hr}
Truth table100%2/2
A
A= $KEY_SEEN_ORDER{$hr}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 165 | my %first; # key => first slot of that key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 165 | for my $i ( reverse 0 .. $#$slots ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 175 | $first{ $slots->[ $i ][ 0 ] } = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 165 | my @at; # slot => [ items placed there ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | my @rest; # items of keys not seen at parse time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 165 | for my $key ( __sorted_keys( $hr ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 271 | my $v = $hr->{ $key }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 271 | ▶ | my @vals = ref( $v ) eq 'ARRAY' ? @$v : ( $v ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 271 | ▶ | if( ! exists $first{ $key } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 118 | push @rest, map { [ $key, $_ ] } @vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 118 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 153 | my $prev = $first{ $key }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 153 | my %taken; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 153 | for my $val ( @vals ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 174 | for my $i ( $prev .. $#$slots ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 215 | my ( $skey, $sval ) = @{ $slots->[ $i ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 215 | ▶ | next if $skey ne $key or $taken{ $i } or ! defined $sval or ! defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$skey ne $key or $taken{$i} or not defined $sval or not defined $val
$skey ne $key or $taken{$i} or not defined $sval
$skey ne $key or $taken{$i}
MC/DC75%3/4
$skey ne $key or $taken{$i} or not defined $sval or not defined $val
$skey ne $key
$taken{$i}
not defined $sval
not defined $val
Truth table80%4/5
A or B or not(C) or not(D)
A= $skey ne $keyB= $taken{$i}C= not defined $svalD= not defined $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 172 | ▶ | next unless ref( $val ) ? ref( $sval ) && $sval == $val : ! ref( $sval ) && $sval eq $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
ref $sval and $sval == $val
not ref $sval and $sval eq $val
MC/DC50%1/2
ref $sval and $sval == $val
ref $sval
$sval == $val
MC/DC50%1/2
not ref $sval and $sval eq $val
not ref $sval
$sval eq $val
Truth table66%2/3
A and B
A= ref $svalB= $sval == $val
Truth table66%2/3
not(A) and B
A= not ref $svalB= $sval eq $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 168 | $taken{ $i } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 168 | $prev = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 168 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 174 | push @{ $at[ $prev ] }, [ $key, $val ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 165 | ▶ | return ( map( { @{ $_ || [] } } @at ), @rest ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ || []
MC/DC100%1/1
$_ || []
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # well-known keys first in canonical order, rest alphabetically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | sub __sorted_keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 165 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__sorted_keys: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 165 | my $hr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 165 | ▶ | return sort { ( $KEY_RANK{ $a } || 999 ) <=> ( $KEY_RANK{ $b } || 999 ) or $a cmp $b } keys %$hr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition85%6/7
($KEY_RANK{$a} || 999) <=> ($KEY_RANK{$b} || 999) || $a cmp $b
$KEY_RANK{$a} || 999
$KEY_RANK{$b} || 999
MC/DC0%0/2
($KEY_RANK{$a} || 999) <=> ($KEY_RANK{$b} || 999) || $a cmp $b
$KEY_RANK{$a}
$a cmp $b
MC/DC100%1/1
$KEY_RANK{$b} || 999
$KEY_RANK{$b}
Truth table66%2/3
A || B
A= $KEY_RANK{$a}B= $a cmp $b
Truth table100%2/2
A
A= $KEY_RANK{$b}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ## CONNECT STRINGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | my $ALIAS_RE = qr/[A-Za-z0-9_.\-]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | my $EZCONNECT_RE = qr{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ^(?://)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | (?: \[ ( [^\]\s/\@]+ ) \] | ( [^:/\[\]\s\@]+ ) ) # host or [ipv6] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | (?: : ( \d+ ) )? # port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | (?: / ( [^:/\s\@]+ ) # service name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | (?: : ( [A-Za-z]+ ) )? # server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | (?: / ( [^/\s\@]+ ) )? # instance name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | )?$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | }x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # parses DBI/sqlplus style connect string: user/pass@target, user@target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # user/pass, /@target, target is a descriptor, an alias or EZConnect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # returns ( { USER, PASS, TNS | ALIAS | EZCONNECT }, undef ) or ( undef, $error_message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | sub tns_parse_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 67 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_parse_connect: called CC=23 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 67 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 67 | ▶ | return ( undef, "empty connect string" ) unless defined $str and $str =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $str and $str =~ /\S/
MC/DC100%2/2
defined $str and $str =~ /\S/
defined $str
$str =~ /\S/
Truth table100%3/3
A and B
A= defined $strB= $str =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 65 | $str =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 65 | pos( $str ) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 65 | $str =~ /\G\s*/gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 65 | my $conn = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 65 | ▶ | $conn->{ USER } = defined $1 ? $1 : $2 if $str =~ /\G(?:"([^"]*)"|([^\/\@"\s]+))/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 65 | ▶ | if( $str =~ /\G\//gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 53 | ▶ | if( $str =~ /\G(?:"([^"]*)"|([^\@"\s]+))/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 45 | ▶ | return ( undef, "password without user" ) unless exists $conn->{ USER }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 44 | ▶ | $conn->{ PASS } = defined $1 ? $1 : $2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | elsif( exists $conn->{ USER } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 3 | return ( undef, "missing password after / at offset " . pos( $str ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | elsif( ! exists $conn->{ USER } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | return ( undef, "expected user or / at offset " . pos( $str ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 59 | ▶ | if( $str =~ /\G\@\s*/gc ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 51 | my $target = substr( $str, pos( $str ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 51 | ▶ | return ( undef, "missing connect target after \@" ) if $target eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 49 | ▶ | if( $target =~ /^\(/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 7 | my ( $tree, $err ) = tns_parse( $target ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 7 | ▶ | return ( undef, "descriptor: $err" ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | $conn->{ TNS } = $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | elsif( $target =~ /^$ALIAS_RE$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 19 | $conn->{ ALIAS } = $target; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | elsif( my ( $host6, $host, $port, $service, $server, $instance ) = $target =~ $EZCONNECT_RE ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 15 | ▶ | my %ez = ( HOST => defined $host6 ? $host6 : $host ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 15 | ▶ | $ez{ PORT } = $port if defined $port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 15 | ▶ | $ez{ SERVICE_NAME } = $service if defined $service; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 15 | ▶ | $ez{ SERVER } = $server if defined $server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 15 | ▶ | $ez{ INSTANCE_NAME } = $instance if defined $instance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 15 | $conn->{ EZCONNECT } = \%ez; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 8 | return ( undef, "bad connect target: $target" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | elsif( pos( $str ) < length( $str ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | return ( undef, "trailing data at offset " . pos( $str ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 46 | return ( $conn, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # builds connect string from { USER, PASS, TNS | ALIAS | EZCONNECT } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # $indent is passed to tns_build() for TNS, default single line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # returns ( $string, undef ) or ( undef, $error_message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | sub tns_build_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_build_connect: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 51 | my ( $conn, $indent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 51 | ▶ | return ( undef, "hashref expected" ) unless ref( $conn ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 49 | my %known = map { $_ => 1 } qw( USER PASS TNS ALIAS EZCONNECT ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 49 | my @bad = sort grep { ! $known{ $_ } } keys %$conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 49 | ▶ | return ( undef, "unknown key @bad" ) if @bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 48 | my @targets = grep { exists $conn->{ $_ } } qw( TNS ALIAS EZCONNECT ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 48 | ▶ | return ( undef, "only one of @targets expected" ) if @targets > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 47 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 47 | ▶ | if( exists $conn->{ USER } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 43 | my ( $user, $err ) = __connect_quote( USER => $conn->{ USER }, qr/[\/\@\s]/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 43 | ▶ | return ( undef, $err ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 40 | $out = $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 40 | ▶ | if( exists $conn->{ PASS } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 17 | my ( $pass, $err ) = __connect_quote( PASS => $conn->{ PASS }, qr/[\@\s]/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 17 | ▶ | return ( undef, $err ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 15 | $out .= "/$pass"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 4 | ▶ | return ( undef, "PASS without USER" ) if exists $conn->{ PASS }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | $out = '/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 41 | ▶ | return ( $out, undef ) unless @targets; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 37 | my $target; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 37 | ▶ | if( exists $conn->{ TNS } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 6 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 6 | ( $target, $err ) = tns_build( $conn->{ TNS }, $indent ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 6 | ▶ | return ( undef, "TNS: $err" ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | elsif( exists $conn->{ ALIAS } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 13 | $target = $conn->{ ALIAS }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 13 | ▶ | return ( undef, "bad ALIAS" ) unless defined $target and ! ref( $target ) and $target =~ /^$ALIAS_RE$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $target and not ref $target and $target =~ /^$ALIAS_RE$/
defined $target and not ref $target
MC/DC66%2/3
defined $target and not ref $target and $target =~ /^$ALIAS_RE$/
defined $target
not ref $target
$target =~ /^$ALIAS_RE$/
Truth table75%3/4
A and not(B) and C
A= defined $targetB= not ref $targetC= $target =~ /^$ALIAS_RE$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 18 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 18 | ( $target, $err ) = __build_ezconnect( $conn->{ EZCONNECT } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 18 | ▶ | return ( undef, "EZCONNECT: $err" ) if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 22 | return ( "$out\@$target", undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # replaces USER and PASS in connect string with $mask (default "***"), e.g. for logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # returns masked string, never fails: unparsable strings without quotes keep only the part after the last @ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | sub tns_mask_connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tns_mask_connect: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 14 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 14 | ▶ | my $mask = @_ ? shift : '***'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 14 | ▶ | return $str unless defined $str and $str =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $str and $str =~ /\S/
MC/DC100%2/2
defined $str and $str =~ /\S/
defined $str
$str =~ /\S/
Truth table100%3/3
A and B
A= defined $strB= $str =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 12 | my ( $conn, $err ) = tns_parse_connect( $str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 12 | ▶ | if( ! $err ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 9 | ▶ | $conn->{ USER } = $mask if exists $conn->{ USER }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 9 | ▶ | $conn->{ PASS } = $mask if exists $conn->{ PASS }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 9 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 9 | ( $out, $err ) = tns_build_connect( $conn ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 9 | ▶ | return $out unless $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # quoted user/pass may contain @, so nothing can be kept safely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | ▶ | return $str !~ /"/ && $str =~ /\@([^\@]*)$/ ? "$mask\@$1" : $mask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $str =~ /"/ and $str =~ /\@([^\@]*)$/
MC/DC50%1/2
not $str =~ /"/ and $str =~ /\@([^\@]*)$/
not $str =~ /"/
$str =~ /\@([^\@]*)$/
Truth table66%2/3
not(A) and B
A= not $str =~ /"/B= $str =~ /\@([^\@]*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # quotes user or password if empty or matching $re | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | sub __connect_quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 60 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__connect_quote: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 60 | my ( $name, $val, $re ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 60 | ▶ | return ( undef, "undefined $name" ) unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 58 | ▶ | return ( undef, "unsupported $name type " . ref( $val ) ) if ref( $val ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 57 | ▶ | return ( undef, "double quote in $name is not supported" ) if $val =~ /"/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 55 | ▶ | $val = qq["$val"] if $val eq '' or $val =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val eq "" or $val =~ /$re/
MC/DC100%2/2
$val eq "" or $val =~ /$re/
$val eq ""
$val =~ /$re/
Truth table100%3/3
A or B
A= $val eq ""B= $val =~ /$re/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 55 | return ( $val, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # builds [//]host[:port][/service[:server][/instance]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | sub __build_ezconnect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__build_ezconnect: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 18 | my $ez = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 18 | ▶ | return ( undef, "hashref expected" ) unless ref( $ez ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 17 | my %check = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | HOST => qr/^(?:[^:\/\[\]\s\@]+|[^\[\]\s\/\@]*:[^\[\]\s\/\@]*)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | PORT => qr/^\d+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | SERVICE_NAME => qr/^[^:\/\s\@]+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | SERVER => qr/^[A-Za-z]+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | INSTANCE_NAME => qr/^[^\/\s\@]+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 17 | for my $key ( sort keys %$ez ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 32 | ▶ | return ( undef, "unknown key $key" ) unless $check{ $key }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 31 | my $val = $ez->{ $key }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 31 | ▶ | return ( undef, "bad $key" ) unless defined $val and ! ref( $val ) and $val =~ $check{ $key }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $val and not ref $val and $val =~ /$check{$key}/
defined $val and not ref $val
MC/DC33%1/3
defined $val and not ref $val and $val =~ /$check{$key}/
defined $val
not ref $val
$val =~ /$check{$key}/
Truth table50%2/4
A and not(B) and C
A= defined $valB= not ref $valC= $val =~ /$check{$key}/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 10 | ▶ | return ( undef, "missing HOST" ) unless exists $ez->{ HOST }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | return ( undef, "SERVER and INSTANCE_NAME need SERVICE_NAME" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 9 | ▶ | if ! exists $ez->{ SERVICE_NAME } and ( exists $ez->{ SERVER } or exists $ez->{ INSTANCE_NAME } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not exists $ez->{"SERVICE_NAME"} and exists $ez->{"SERVER"} || exists $ez->{"INSTANCE_NAME"}
exists $ez->{"SERVER"} or exists $ez->{"INSTANCE_NAME"}
MC/DC100%3/3
not exists $ez->{"SERVICE_NAME"} and exists $ez->{"SERVER"} || exists $ez->{"INSTANCE_NAME"}
not exists $ez->{"SERVICE_NAME"}
exists $ez->{"SERVER"}
exists $ez->{"INSTANCE_NAME"}
Truth table100%4/4
not(A) and B or C
A= not exists $ez->{"SERVICE_NAME"}B= exists $ez->{"SERVER"}C= exists $ez->{"INSTANCE_NAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 7 | ▶ | my $out = $ez->{ HOST } =~ /:/ ? "[$ez->{ HOST }]" : $ez->{ HOST }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 7 | ▶ | $out .= ":$ez->{ PORT }" if exists $ez->{ PORT }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 7 | ▶ | if( exists $ez->{ SERVICE_NAME } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | $out .= "/$ez->{ SERVICE_NAME }"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 3 | ▶ | $out .= ":$ez->{ SERVER }" if exists $ez->{ SERVER }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 3 | ▶ | $out .= "/$ez->{ INSTANCE_NAME }" if exists $ez->{ INSTANCE_NAME }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # a lone host would be read back as alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 7 | ▶ | $out = "//$out" if $out =~ /^$ALIAS_RE$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 7 | return ( $out, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||