Firebird/Util.pm

filter: Statementstmt 100% 41 / 41 Branchbran 86.3% 19 / 22 Conditioncond 64.7% 11 / 17 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 85.2% 81 / 95 CC 19 SCAR 23.3
CC
19
Cov
89%
_mask_key
14.3
mask_error_details
7.0
BEGIN
1.0
CRAP 10.3
« Firebird/Introspect/Uniques.pm ↑ Summary Firebird/Diff/Index.pm »
1 package DBIO::Firebird::Util;
2 # ABSTRACT: Shared Firebird-specific helper functions for DBIO
3  
4 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 21 our $VERSION = '0.900007';
8  
9 21 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 our @EXPORT_OK = qw(mask_error_details);
12  
13 # What stands in for a value in an error text.
14 21 my $MASK = '***';
15  
16  
17 # ("A" = 1, "B" = 'x') without the outer parentheses: the column names, kept,
18 # with the values replaced -- or undef when the text is not one reading.
19 19 ▶sub _mask_key {
Subroutine _mask_key: called CC=13 SCAR=26.6
20 19 my ($inner, $binds) = @_;
21  
22 19 ▶ for my $bound (@{ $binds // [] }) {
Condition100%2/2
$binds // []
l!l
415
MC/DC100%1/1
$binds // []
$binds
Truth table100%2/2
A
A= $binds
Aresult
11
00
23 7 ▶ return undef if defined $bound && !ref $bound && $bound =~ /, "|\)/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bound and not ref $bound and $bound =~ /, "|\)/ 1 6 7
Condition50%3/6
defined $bound and not ref $bound and $bound =~ /, "|\)/
!ll&&!rl&&r
061
defined $bound and not ref $bound
!ll&&!rl&&r
007
MC/DC33%1/3
defined $bound and not ref $bound and $bound =~ /, "|\)/
defined $bound not ref $bound $bound =~ /, "|\)/
Truth table50%2/4
A and not(B) and C
A= defined $boundB= not ref $boundC= $bound =~ /, "|\)/
ABCresult
0XX0
10X0
1100
1111
24 }
25  
26 # The server does not escape a quote in a value, so a value holding
27 # `" = ` would be read as one column more. The number of `" = ` must be the
28 # number of columns found.
29 18 my $equals = () = $inner =~ /" = /g;
30  
31 18 my @names;
32 18 my $rest = $inner;
33 18 ▶ while (length $rest) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $rest) 25 0 25
34 25 ▶ $rest =~ s/\A"((?:[^"]|"")+)" = //
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ s/\A"((?:[^"]|"")+)" = // or return undef 25 0 25
35 or return undef;
36 25 push @names, $1;
37 # The value reaches to the next `, "NAME" = ` or to the end (lazy).
38 25 ▶ $rest =~ s/\A.*?(?=, "(?:[^"]|"")+" = |\z)//s
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ s/\A.*?(?=, "(?:[^"]|"")+" = |\z)//s or return undef 25 0 25
39 or return undef;
40 25 ▶ $rest =~ s/\A, // or last;
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ s/\A, // or last 7 18 25
41 }
42 18 ▶ return undef unless @names && @names == $equals && !length $rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @names and @names == $equals and not length $rest 1 17 18
Condition66%4/6
@names and @names == $equals and not length $rest
!ll&&!rl&&r
1017
@names and @names == $equals
!ll&&!rl&&r
0117
MC/DC33%1/3
@names and @names == $equals and not length $rest
@names @names == $equals not length $rest
Truth table50%2/4
A and B and not(C)
A= @namesB= @names == $equalsC= not length $rest
ABCresult
0XX0
10X0
1100
1111
43  
44 17 return join ', ', map { qq{"$_" = $MASK} } @names;
45 }
46  
47 58 ▶sub mask_error_details {
Subroutine mask_error_details: called CC=7 SCAR=19.5
Pod documented
48 58 my ($text, $binds) = @_;
49  
50 58 ▶ return $text unless defined $text && !ref $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and not ref $text 1 57 58
Condition66%2/3
defined $text and not ref $text
!ll&&!rl&&r
1057
MC/DC50%1/2
defined $text and not ref $text
defined $text not ref $text
Truth table66%2/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
51  
52 # -Problematic key value is ("ID" = 1, "EMAIL" = 'x')
53 57 $text =~ s{(Problematic key value is )(.*)\z}{
54 24 my ($head, $tail) = ($1, $2);
55 24 my $masked;
56 24 ▶ if ($tail =~ /\A\((.*)\)\s*\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail =~ /\A\((.*)\)\s*\z/s) 19 5 24
57 19 my $keys = _mask_key($1, $binds);
58 19 ▶ $masked = "($keys)" if defined $keys;
Branch: 1 branch
BranchTrueFalseTotal
if defined $keys 17 2 19
59 }
60 24 ▶ $head . (defined $masked ? $masked : $MASK)
Branch: 1 branch
BranchTrueFalseTotal
defined $masked ? : 17 7 24
61 }se;
62  
63 # -conversion error from string "geheimdate"
64 57 $text =~ s/(conversion error from string )".*"/$1"$MASK"/s;
65  
66 # validation error for column "T"."C", value "x"
67 57 $text =~ s/(validation error for column [^\n]*?, value )"(.*)"/
68 4 ▶ $2 eq '*** null ***' ? qq{$1"$2"} : qq{$1"$MASK"}/se;
Branch: 1 branch
BranchTrueFalseTotal
$2 eq '*** null ***' ? : 2 2 4
69  
70 57 return $text;
71 }
72  
73 21 1;
74  
75 __END__
« Firebird/Introspect/Uniques.pm ↑ Summary Firebird/Diff/Index.pm »