Sybase/Util.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 100% 6 / 6 Conditioncond 100% 19 / 19 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 98.7% 78 / 79 CC 12 SCAR 17.1
CC
12
Cov
98%
mask_error_details
7.0
_mask_sentences
6.0
BEGIN
1.0
CRAP 5.5
« Sybase/Diff/Table.pm ↑ Summary Sybase/Introspect/ForeignKeys.pm »
1 package DBIO::Sybase::Util;
2 # ABSTRACT: Shared Sybase ASE-specific helper functions for DBIO
3  
4 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 our $VERSION = '0.900007';
8  
9 35 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 35 our @EXPORT_OK = qw(mask_error_details);
12  
13 # What stands in for a value in an error text.
14 35 my $MASK = '***';
15  
16 # The shortest bound value that is looked for verbatim in an error text. A
17 # shorter one is a letter or a number, which is part of any text; the sentences
18 # known below catch those.
19 35 my $MIN_BOUND_LENGTH = 4;
20  
21  
22 # The sentences of the server and of its client library that hold a value, one
23 # rule each. A rule keeps the words around the value -- the type, the column,
24 # the constraint -- and replaces the value. Every rule gives the same text
25 # again when it is applied to its own result.
26 120 ▶sub _mask_sentences {
Subroutine _mask_sentences: called CC=6 SCAR=17.9
27 120 my ($text, $binds) = @_;
28  
29 # ... during implicit conversion of CHAR value 'x' to a DATE field .
30 # The value is quoted but not escaped: it ends at the last "' to a".
31 120 my $conversion = qr/\bconversion of [A-Z][A-Z0-9_ ()]*? value /;
32 120 ▶ $text =~ s/($conversion)'.*' to a ([A-Z][A-Z0-9_ ()]* field)/$1'$MASK' to a $2/s
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/($conversion)'.*' to a ([A-Z][A-Z0-9_ ()]* field)/$1'${MASK}' to a $2/s or $text =~ s/($conversion)'(?!\Q$MASK\E'(?: to a |\z)).*\z/$1'${MASK}'/s 46 74 120
33 or $text =~ s/($conversion)'(?!\Q$MASK\E'(?: to a |\z)).*\z/$1'$MASK'/s;
34  
35 # Syntax error converting the varchar value 'x' to a column of data type int
36 120 $text =~ s/(\bconverting the \w+ value )'.*'( to a column of data type )/$1'$MASK'$2/s;
37  
38 # ... to_numeric() failed for '99999.9' (the end of the text)
39 120 $text =~ s/(\bfailed for )'.*'/$1'$MASK'/s;
40  
41 # cs_convert failed (to_money(x))
42 120 $text =~ s/(\bcs_convert failed \(to_\w+\().*(\)\))/$1$MASK$2/s;
43  
44 # Create unique index aborted on duplicate key. Primary key is '"x"'
45 # The key is quoted as '"x"' and may hold line breaks: it ends at the first
46 # "' that closes a line.
47 120 $text =~ s/(\bPrimary key is )'".*?"'(?=\n|\z)/$1'$MASK'/sg;
48 # Any other form of the key goes to the end of its line; a bound value with a
49 # line break carries the key over its line: all that follows goes.
50 120 ▶ my $multiline = grep { defined && !ref && /[\r\n]/ } @{ $binds // [] };
Condition100%8/8
defined $_ && !ref($_) && /[\r\n]/
!ll&&!rl&&r
241
defined $_ and not ref $_
!ll&&!rl&&r
115
$binds // []
l!l
5115
MC/DC100%3/3
defined $_ && !ref($_) && /[\r\n]/
defined $_ not ref $_ /[\r\n]/
MC/DC100%1/1
$binds // []
$binds
Truth table100%4/4
A and not(B) && C
A= defined $_B= not ref $_C= /[\r\n]/
ABCresult
0XX0
10X0
1100
1111
Truth table100%2/2
A
A= $binds
Aresult
11
00
51 120 ▶ if ($multiline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline) { } 1 119 120
52 1 $text =~ s/(\bPrimary key is )(?=').*\z/$1'$MASK'/s;
53 }
54 else {
55 119 $text =~ s/(\bPrimary key is )(?=').*$/$1'$MASK'/mg;
56 }
57  
58 120 return $text;
59 }
60  
61  
62 122 ▶sub mask_error_details {
Subroutine mask_error_details: called CC=7 SCAR=19.5
Pod documented
63 122 my ($message, $binds) = @_;
64 122 ▶ return $message unless defined $message && length $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message and length $message 2 120 122
Condition100%3/3
defined $message and length $message
!ll&&!rl&&r
11120
MC/DC100%2/2
defined $message and length $message
defined $message length $message
Truth table100%3/3
A and B
A= defined $messageB= length $message
ABresult
0X0
100
111
65  
66 120 $message = _mask_sentences($message, $binds);
67  
68 0 my @bound = sort { length $b <=> length $a }
69 120 ▶ grep { defined && !ref && length >= $MIN_BOUND_LENGTH } @{ $binds // [] };
Condition100%8/8
defined $_ && !ref($_) && length $_ >= $MIN_BOUND_LENGTH
!ll&&!rl&&r
241
defined $_ and not ref $_
!ll&&!rl&&r
115
$binds // []
l!l
5115
MC/DC100%3/3
defined $_ && !ref($_) && length $_ >= $MIN_BOUND_LENGTH
defined $_ not ref $_ length $_ >= $MIN_BOUND_LENGTH
MC/DC100%1/1
$binds // []
$binds
Truth table100%4/4
A and not(B) && C
A= defined $_B= not ref $_C= length $_ >= $MIN_BOUND_LENGTH
ABCresult
0XX0
10X0
1100
1111
Truth table100%2/2
A
A= $binds
Aresult
11
00
70 120 for my $bound (@bound) {
71 1 $message =~ s/\Q$bound\E/$MASK/g;
72 }
73  
74 120 return $message;
75 }
76  
77 35 1;
78  
79 __END__
« Sybase/Diff/Table.pm ↑ Summary Sybase/Introspect/ForeignKeys.pm »