blib/lib/dbgp-helper/DB/Data/Dump.pm

filter: Statementstmt 0.0% 0 / 244 Branchbran 0.0% 0 / 140 Conditioncond 0.0% 0 / 75 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 512 CC 107 SCAR 77.7
CC
107
Cov
0%
_dump
4032.0
dump
306.0
quote
182.0
CRAP 2375.7
« blib/lib/dbgp-helper/perl5db.pl ↑ Summary blib/lib/dbgp-helper/DB/DbgrProperties.pm »
1 package DB::Data::Dump;
2  
3 # Based on Data::Dump
4  
5 use strict;
6 use vars qw(@EXPORT_OK $VERSION $DEBUG);
7  
8 require Exporter;
9 *import = \&Exporter::import;
10 @EXPORT_OK=qw(dump pp);
11  
12 $VERSION = "1.03"; # $Date: 2004/04/13 12:59:07 $
13 $DEBUG = 0;
14  
15 use overload ();
16 use vars qw(%seen %refcnt @dump @fixup %require $TRY_BASE64);
17 use vars qw($maxDataSize $amountWritten);
18 $maxDataSize = 0;
19  
20 $TRY_BASE64 = 50 unless defined $TRY_BASE64;
21  
22 my %is_perl_keyword = map { $_ => 1 }
23 qw( __FILE__ __LINE__ __PACKAGE__ __DATA__ __END__ AUTOLOAD BEGIN CORE
24 DESTROY END EQ GE GT INIT LE LT NE abs accept alarm and atan2 bind
25 binmode bless caller chdir chmod chomp chop chown chr chroot close
26 closedir cmp connect continue cos crypt dbmclose dbmopen defined
27 delete die do dump each else elsif endgrent endhostent endnetent
28 endprotoent endpwent endservent eof eq eval exec exists exit exp fcntl
29 fileno flock for foreach fork format formline ge getc getgrent
30 getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin
31 getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid
32 getpriority getprotobyname getprotobynumber getprotoent getpwent
33 getpwnam getpwuid getservbyname getservbyport getservent getsockname
34 getsockopt glob gmtime goto grep gt hex if index int ioctl join keys
35 kill last lc lcfirst le length link listen local localtime lock log
36 lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no not oct
37 open opendir or ord pack package pipe pop pos print printf prototype
38 push q qq qr quotemeta qw qx rand read readdir readline readlink
39 readpipe recv redo ref rename require reset return reverse rewinddir
40 rindex rmdir s scalar seek seekdir select semctl semget semop send
41 setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent
42 setservent setsockopt shift shmctl shmget shmread shmwrite shutdown
43 sin sleep socket socketpair sort splice split sprintf sqrt srand stat
44 study sub substr symlink syscall sysopen sysread sysseek system
45 syswrite tell telldir tie tied time times tr truncate uc ucfirst umask
46 undef unless unlink unpack unshift untie until use utime values vec
47 wait waitpid wantarray warn while write x xor y);
48  
49  
50 sub dump
51 {
52 0 ▶ local %seen;
Subroutine dump: not called CC=17 SCAR=57.2
Pod undocumented
53 0 local %refcnt;
54 0 local %require;
55 0 local @fixup;
56  
57 0 my $name = "a";
58 0 my @dump;
59  
60 0 $amountWritten = 0;
61 0 for (@_) {
62 0 my $val = _dump($_, $name, []);
63 0 push(@dump, [$name, $val]);
64 0 ▶ if ($maxDataSize > 0 && $amountWritten > $maxDataSize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize) 0 0 0
Condition0%0/3
$DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
!ll&&!rl&&r
000
MC/DC0%0/2
$DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
$DB::Data::Dump::maxDataSize > 0 $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
Truth table0%0/3
A and B
A= $DB::Data::Dump::maxDataSize > 0B= $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
ABresult
0X0
100
111
65 0 ▶ if ($_ != $_[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ != $_[-1]) 0 0 0
66 0 push(@dump, [$name, "..."]);
67 }
68 0 last;
69 }
70 } continue {
71 0 $name++;
72 }
73  
74 0 my $out = "";
75 0 ▶ if (%require) {
Branch: 1 branch
BranchTrueFalseTotal
if (%DB::Data::Dump::require) 0 0 0
76 0 for (sort keys %require) {
77 0 $out .= "require $_;\n";
78 }
79 }
80 0 ▶ if (%refcnt) {
Branch: 1 branch
BranchTrueFalseTotal
if (%DB::Data::Dump::refcnt) 0 0 0
81 # output all those with refcounts first
82 0 for (@dump) {
83 0 my $name = $_->[0];
84 0 ▶ if ($refcnt{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::refcnt{$name}) 0 0 0
85 0 $out .= "my \$$name = $_->[1];\n";
86 0 undef $_->[1];
87 }
88 }
89 0 for (@fixup) {
90 0 $out .= "$_;\n";
91 }
92 }
93  
94 0 my $paren = (@dump != 1);
95 0 ▶ $out .= "(" if $paren;
Branch: 1 branch
BranchTrueFalseTotal
if $paren 0 0 0
96 $out .= format_list($paren,
97 0 ▶ map {defined($_->[1]) ? $_->[1] : "\$".$_->[0]}
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[1] ? : 0 0 0
98 @dump
99 );
100 0 ▶ $out .= ")" if $paren;
Branch: 1 branch
BranchTrueFalseTotal
if $paren 0 0 0
101  
102 0 ▶ if (%refcnt || %require) {
Branch: 1 branch
BranchTrueFalseTotal
if (%DB::Data::Dump::refcnt or %DB::Data::Dump::require) 0 0 0
Condition0%0/3
%DB::Data::Dump::refcnt or %DB::Data::Dump::require
l!l&&r!l&&!r
000
MC/DC0%0/2
%DB::Data::Dump::refcnt or %DB::Data::Dump::require
%DB::Data::Dump::refcnt %DB::Data::Dump::require
Truth table0%0/3
A or B
A= %DB::Data::Dump::refcntB= %DB::Data::Dump::require
ABresult
1X1
011
000
103 0 $out .= ";\n";
104 0 $out =~ s/^/ /gm; # indent
105 0 $out = "do {\n$out}";
106 }
107  
108 #use DB::Data::Dumper; print Dumper(\%refcnt);
109 #use DB::Data::Dumper; print Dumper(\%seen);
110  
111 0 ▶ print STDERR "$out\n" unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
112 0 $out;
113 }
114  
115 *pp = \&dump;
116  
117 sub _dump
118 {
119 0 ▶ my $ref = ref $_[0];
Subroutine _dump: not called CC=63 SCAR=83.0
120 0 ▶ my $rval = $ref ? $_[0] : \$_[0];
Branch: 1 branch
BranchTrueFalseTotal
$ref ? : 0 0 0
121 0 shift;
122  
123 0 my($name, $idx) = @_;
124  
125 0 my($class, $type, $id);
126 0 ▶ if (overload::StrVal($rval) =~ /^(?:([^=]+)=)?([A-Z]+)\(0x([^\)]+)\)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::StrVal($rval) =~ /^(?:([^=]+)=)?([A-Z]+)\(0x([^\)]+)\)$/) { } 0 0 0
127 0 $class = $1;
128 0 $type = $2;
129 0 $id = $3;
130 } else {
131 0 die "Can't parse " . overload::StrVal($rval);
132 }
133 0 ▶ warn "$name-(@$idx) $class $type $id ($ref)" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DB::Data::Dump::DEBUG 0 0 0
134  
135 0 ▶ if (my $s = $seen{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $DB::Data::Dump::seen{$id}) 0 0 0
136 0 my($sname, $sidx) = @$s;
137 0 $refcnt{$sname}++;
138 0 ▶ my $sref = fullname($sname, $sidx,
Condition0%0/3
$ref && $type eq 'SCALAR'
!ll&&!rl&&r
000
MC/DC0%0/2
$ref && $type eq 'SCALAR'
$ref $type eq 'SCALAR'
Truth table0%0/3
A && B
A= $refB= $type eq 'SCALAR'
ABresult
0X0
100
111
139 ($ref && $type eq "SCALAR"));
140 0 ▶ warn "SEEN: [$name/@$idx] => [$sname/@$sidx] ($ref,$sref)" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DB::Data::Dump::DEBUG 0 0 0
141 0 ▶ return $sref unless $sname eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $sname eq $name 0 0 0
142 0 $refcnt{$name}++;
143 0 push(@fixup, fullname($name,$idx)." = $sref");
144 0 return "'fix'";
145 }
146 0 $seen{$id} = [$name, $idx];
147  
148 0 my $out;
149 0 ▶ if ($type eq "SCALAR" || $type eq "REF") {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'SCALAR' or $type eq 'REF') { } 0 0 0
elsif ($type eq 'GLOB') { } 0 0 0
elsif ($type eq 'ARRAY') { } 0 0 0
elsif ($type eq 'HASH') { } 0 0 0
elsif ($type eq 'CODE') { } 0 0 0
Condition0%0/3
$type eq "SCALAR" or $type eq "REF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "SCALAR" or $type eq "REF"
$type eq "SCALAR" $type eq "REF"
Truth table0%0/3
A or B
A= $type eq "SCALAR"B= $type eq "REF"
ABresult
1X1
011
000
150 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
151 0 ▶ if ($class && $class eq "Regexp") {
Branch: 1 branch
BranchTrueFalseTotal
if ($class and $class eq 'Regexp') { } 0 0 0
Condition0%0/3
$class and $class eq "Regexp"
!ll&&!rl&&r
000
MC/DC0%0/2
$class and $class eq "Regexp"
$class $class eq "Regexp"
Truth table0%0/3
A and B
A= $classB= $class eq "Regexp"
ABresult
0X0
100
111
152 0 my $v = "$rval";
153  
154 0 my $mod = "";
155 0 ▶ if ($v =~ /^\(\?([msix-]+):([\x00-\xFF]*)\)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^\(\?([msix-]+):([\x00-\xFF]*)\)\z/) 0 0 0
156 0 $mod = $1;
157 0 $v = $2;
158 0 $mod =~ s/-.*//;
159 }
160
161 0 my $sep = '/';
162 0 my $sep_count = ($v =~ tr/\///);
163 0 ▶ if ($sep_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep_count) 0 0 0
164 # see if we can find a better one
165 0 for ('|', ',', ':', '#') {
166 0 my $c = eval "\$v =~ tr/\Q$_\E//";
167 #print "SEP $_ $c $sep_count\n";
168 0 ▶ if ($c < $sep_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < $sep_count) 0 0 0
169 0 $sep = $_;
170 0 $sep_count = $c;
171 0 ▶ last if $sep_count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sep_count == 0 0 0 0
172 }
173 }
174 }
175 0 $v =~ s/\Q$sep\E/\\$sep/g;
176  
177 0 $out = "qr$sep$v$sep$mod";
178 0 undef($class);
179 }
180 else {
181 0 delete $seen{$id}; # will be seen again shortly
182 0 my $val = _dump($$rval, $name, [@$idx, "\$"]);
183 0 ▶ $out = $class ? "do{\\(my \$o = $val)}" : "\\$val";
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 0 0 0
184 }
185 } else {
186 0 ▶ if (!defined $$rval) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $$rval) { } 0 0 0
elsif ($$rval =~ /^-?[1-9]\d{0,8}$/ or $$rval eq '0') { } 0 0 0
187 0 $out = "undef";
188 }
189 ▶ elsif ($$rval =~ /^-?[1-9]\d{0,8}$/ || $$rval eq "0") {
Condition0%0/3
$$rval =~ /^-?[1-9]\d{0,8}$/ or $$rval eq 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$$rval =~ /^-?[1-9]\d{0,8}$/ or $$rval eq 0
$$rval =~ /^-?[1-9]\d{0,8}$/ $$rval eq 0
Truth table0%0/3
A or B
A= $$rval =~ /^-?[1-9]\d{0,8}$/B= $$rval eq 0
ABresult
1X1
011
000
190 0 ▶ if (length $$rval > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$rval > 4) { } 0 0 0
191 # Separate thousands by _ to make it more readable
192 0 $out = reverse $$rval;
193 0 $out =~ s/(\d\d\d)(?=\d)/$1_/g;
194 0 $out = reverse $out;
195 } else {
196 0 $out = $$rval;
197 }
198 }
199 else {
200 0 $out = quote($$rval);
201 }
202 0 ▶ if ($class && !@$idx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class and not @$idx) 0 0 0
Condition0%0/3
$class and not @$idx
!ll&&!rl&&r
000
MC/DC0%0/2
$class and not @$idx
$class not @$idx
Truth table0%0/3
A and not(B)
A= $classB= not @$idx
ABresult
0X0
100
111
203 # Top is an object, not a reference to one as perl needs
204 0 $refcnt{$name}++;
205 0 my $obj = fullname($name, $idx);
206 0 my $cl = quote($class);
207 0 push(@fixup, "bless \\$obj, $cl");
208 }
209 }
210 0 $amountWritten += length($out);
211 }
212 elsif ($type eq "GLOB") {
213 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
214 0 delete $seen{$id};
215 0 my $val = _dump($$rval, $name, [@$idx, "*"]);
216 0 $out = "\\$val";
217 0 ▶ if ($out =~ /^\\\*Symbol::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out =~ /^\\\*Symbol::/) 0 0 0
218 0 $require{Symbol}++;
219 0 $out = "Symbol::gensym()";
220 }
221 } else {
222 0 my $val = "$$rval";
223 0 $out = "$$rval";
224  
225 0 for my $k (qw(SCALAR ARRAY HASH)) {
226 0 my $gval = *$$rval{$k};
227 0 ▶ next unless defined $gval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gval 0 0 0
228 0 ▶ next if $k eq "SCALAR" && ! defined $$gval; # always there
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "SCALAR" and not defined $$gval 0 0 0
Condition0%0/3
$k eq "SCALAR" and not defined $$gval
!ll&&!rl&&r
000
MC/DC0%0/2
$k eq "SCALAR" and not defined $$gval
$k eq "SCALAR" not defined $$gval
Truth table0%0/3
A and not(B)
A= $k eq "SCALAR"B= not defined $$gval
ABresult
0X0
100
111
229 0 my $f = scalar @fixup;
230 0 push(@fixup, "RESERVED"); # overwritten after _dump() below
231 0 $gval = _dump($gval, $name, [@$idx, "*{$k}"]);
232 0 $refcnt{$name}++;
233 0 my $gname = fullname($name, $idx);
234 0 $fixup[$f] = "$gname = $gval"; #XXX indent $gval
235 }
236 }
237 0 $amountWritten += length($out);
238 }
239 elsif ($type eq "ARRAY") {
240 0 my @vals;
241 0 my $i = 0;
242 0 for (@$rval) {
243 0 ▶ if ($i >= 30 || $maxDataSize > 0 && $amountWritten > $maxDataSize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 30 or $DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize) 0 0 0
Condition0%0/6
$i >= 30 or $DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
l!l&&r!l&&!r
000
$DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
!ll&&!rl&&r
000
MC/DC0%0/3
$i >= 30 or $DB::Data::Dump::maxDataSize > 0 and $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
$i >= 30 $DB::Data::Dump::maxDataSize > 0 $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
Truth table0%0/4
A or B and C
A= $i >= 30B= $DB::Data::Dump::maxDataSize > 0C= $DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize
ABCresult
1XX1
0111
00X0
0100
244 0 ▶ if ($_ != $rval->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ != $rval->[-1]) 0 0 0
245 0 push(@vals, "...");
246 }
247 0 last;
248 }
249 0 push(@vals, _dump($_, $name, [@$idx, "[$i]"]));
250 0 $i++;
251 }
252 0 $out = "[" . format_list(1, @vals) . "]";
253 }
254 elsif ($type eq "HASH") {
255 0 my(@keys, @vals);
256  
257 # statistics to determine variation in key lengths
258 0 my $kstat_max = 0;
259 0 my $kstat_sum = 0;
260 0 my $kstat_sum2 = 0;
261  
262 0 my @orig_keys = keys %$rval;
263 0 my $text_keys = 0;
264 0 for (@orig_keys) {
265 0 ▶ $text_keys++, last unless $_ eq "0" || /^[-+]?[1-9]\d*(?:.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ eq 0 or /^[-+]?[1-9]\d*(?:.\d+)?\z/ 0 0 0
Condition0%0/3
$_ eq 0 or /^[-+]?[1-9]\d*(?:.\d+)?\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq 0 or /^[-+]?[1-9]\d*(?:.\d+)?\z/
$_ eq 0 /^[-+]?[1-9]\d*(?:.\d+)?\z/
Truth table0%0/3
A or B
A= $_ eq 0B= /^[-+]?[1-9]\d*(?:.\d+)?\z/
ABresult
1X1
011
000
266 }
267  
268 0 ▶ if ($text_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text_keys) { } 0 0 0
269 0 @orig_keys = sort @orig_keys;
270 }
271 else {
272 0 @orig_keys = sort { $a <=> $b } @orig_keys;
273 }
274  
275 0 for my $key (@orig_keys) {
276 0 my $val = \$rval->{$key};
277 0 ▶ $key = quote($key) if $is_perl_keyword{$key} ||
Branch: 1 branch
BranchTrueFalseTotal
if $is_perl_keyword{$key} or not $key =~ /^[a-zA-Z_]\w{0,19}\z/ || $key =~ /^-?[1-9]\d{0,8}\z/ 0 0 0
Condition0%0/6
$is_perl_keyword{$key} or not $key =~ /^[a-zA-Z_]\w{0,19}\z/ || $key =~ /^-?[1-9]\d{0,8}\z/
l!l&&r!l&&!r
000
$key =~ /^[a-zA-Z_]\w{0,19}\z/ || $key =~ /^-?[1-9]\d{0,8}\z/
l!l&&r!l&&!r
000
MC/DC0%0/3
$is_perl_keyword{$key} or not $key =~ /^[a-zA-Z_]\w{0,19}\z/ || $key =~ /^-?[1-9]\d{0,8}\z/
$is_perl_keyword{$key} $key =~ /^[a-zA-Z_]\w{0,19}\z/ $key =~ /^-?[1-9]\d{0,8}\z/
Truth table0%0/4
A or not(B || C)
A= $is_perl_keyword{$key}B= $key =~ /^[a-zA-Z_]\w{0,19}\z/C= $key =~ /^-?[1-9]\d{0,8}\z/
ABCresult
1XX1
0001
01X0
0010
278 !($key =~ /^[a-zA-Z_]\w{0,19}\z/ ||
279 $key =~ /^-?[1-9]\d{0,8}\z/
280 );
281  
282 0 ▶ $kstat_max = length($key) if length($key) > $kstat_max;
Branch: 1 branch
BranchTrueFalseTotal
if length $key > $kstat_max 0 0 0
283 0 $kstat_sum += length($key);
284 0 $kstat_sum2 += length($key)*length($key);
285  
286 0 push(@keys, $key);
287 0 push(@vals, _dump($$val, $name, [@$idx, "{$key}"]));
288 0 ▶ if ($maxDataSize > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::maxDataSize > 0) 0 0 0
289 0 $amountWritten += length($keys[-1]);
290 0 ▶ if ($amountWritten > $maxDataSize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::amountWritten > $DB::Data::Dump::maxDataSize) 0 0 0
291 0 ▶ if ($key ne $orig_keys[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key ne $orig_keys[-1]) 0 0 0
292 0 push(@keys, '...');
293 0 push(@vals, '');
294 }
295 0 last;
296 }
297 }
298 }
299 0 my $nl = "";
300 0 my $klen_pad = 0;
301 0 my $tmp = "@keys @vals";
302 0 ▶ if (length($tmp) > 60 || $tmp =~ /\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tmp > 60 or $tmp =~ /\n/) 0 0 0
Condition0%0/3
length $tmp > 60 or $tmp =~ /\n/
l!l&&r!l&&!r
000
MC/DC0%0/2
length $tmp > 60 or $tmp =~ /\n/
length $tmp > 60 $tmp =~ /\n/
Truth table0%0/3
A or B
A= length $tmp > 60B= $tmp =~ /\n/
ABresult
1X1
011
000
303 0 $nl = "\n";
304  
305 # Determine what padding to add
306 0 ▶ if ($kstat_max < 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kstat_max < 4) { } 0 0 0
elsif (@keys >= 2) { } 0 0 0
307 0 $klen_pad = $kstat_max;
308 }
309 elsif (@keys >= 2) {
310 0 my $n = @keys;
311 0 my $avg = $kstat_sum/$n;
312 0 my $stddev = sqrt(($kstat_sum2 - $n * $avg * $avg) / ($n - 1));
313  
314 # I am not actually very happy with this heuristics
315 0 ▶ if ($stddev / $kstat_max < 0.25) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stddev / $kstat_max < "0.25") 0 0 0
316 0 $klen_pad = $kstat_max;
317 }
318 0 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::DEBUG) 0 0 0
319 0 push(@keys, "__S");
320 0 push(@vals, sprintf("%.2f (%d/%.1f/%.1f)",
321 $stddev / $kstat_max,
322 $kstat_max, $avg, $stddev));
323 }
324 }
325 }
326 0 $out = "{$nl";
327 0 ▶ while (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 0 0 0
328 0 my $key = shift @keys;
329 0 my $val = shift @vals;
330 0 my $pad = " " x ($klen_pad + 6);
331 0 $val =~ s/\n/\n$pad/gm;
332 0 ▶ $key = " $key" . " " x ($klen_pad - length($key)) if $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $nl 0 0 0
333 0 $out .= " $key => $val,$nl";
334 }
335 0 ▶ $out =~ s/,$/ / unless $nl;
Branch: 1 branch
BranchTrueFalseTotal
unless $nl 0 0 0
336 0 $out .= "}";
337 }
338 elsif ($type eq "CODE") {
339 0 $out = 'sub { "???" }';
340 }
341 else {
342 0 warn "Can't handle $type data";
343 0 $out = "'#$type#'";
344 }
345  
346 0 ▶ if ($class && $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class and $ref) 0 0 0
Condition0%0/3
$class and $ref
!ll&&!rl&&r
000
MC/DC0%0/2
$class and $ref
$class $ref
Truth table0%0/3
A and B
A= $classB= $ref
ABresult
0X0
100
111
347 0 $out = "bless($out, " . quote($class) . ")";
348 }
349 0 return $out;
350 }
351  
352 sub fullname
353 {
354 0 ▶ my($name, $idx, $ref) = @_;
Subroutine fullname: not called CC=12 SCAR=50.5
Pod undocumented
355 0 substr($name, 0, 0) = "\$";
356  
357 0 my @i = @$idx; # need copy in order to not modify @$idx
358 0 ▶ if ($ref && @i && $i[0] eq "\$") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and @i and $i[0] eq "\$") 0 0 0
Condition0%0/6
$ref and @i and $i[0] eq "\$"
!ll&&!rl&&r
000
$ref and @i
!ll&&!rl&&r
000
MC/DC0%0/3
$ref and @i and $i[0] eq "\$"
$ref @i $i[0] eq "\$"
Truth table0%0/4
A and B and C
A= $refB= @iC= $i[0] eq "\$"
ABCresult
0XX0
10X0
1100
1111
359 0 shift(@i); # remove one deref
360 0 $ref = 0;
361 }
362 0 ▶ while (@i && $i[0] eq "\$") {
Branch: 1 branch
BranchTrueFalseTotal
if (@i and $i[0] eq "\$") 0 0 0
Condition0%0/3
@i and $i[0] eq "\$"
!ll&&!rl&&r
000
MC/DC0%0/2
@i and $i[0] eq "\$"
@i $i[0] eq "\$"
Truth table0%0/3
A and B
A= @iB= $i[0] eq "\$"
ABresult
0X0
100
111
363 0 shift @i;
364 0 $name = "\$$name";
365 }
366  
367 0 my $last_was_index;
368 0 for my $i (@i) {
369 0 ▶ if ($i eq "*" || $i eq "\$") {
Branch: 2 branches
BranchTrueFalseTotal
if ($i eq '*' or $i eq '$') { } 0 0 0
elsif ($i =~ s/^\*//) { } 0 0 0
Condition0%0/3
$i eq "*" or $i eq "\$"
l!l&&r!l&&!r
000
MC/DC0%0/2
$i eq "*" or $i eq "\$"
$i eq "*" $i eq "\$"
Truth table0%0/3
A or B
A= $i eq "*"B= $i eq "\$"
ABresult
1X1
011
000
370 0 $last_was_index = 0;
371 0 $name = "$i\{$name}";
372 } elsif ($i =~ s/^\*//) {
373 0 $name .= $i;
374 0 $last_was_index++;
375 } else {
376 0 ▶ $name .= "->" unless $last_was_index++;
Branch: 1 branch
BranchTrueFalseTotal
unless $last_was_index++ 0 0 0
377 0 $name .= $i;
378 }
379 }
380 0 ▶ $name = "\\$name" if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
381 0 $name;
382 }
383  
384 sub format_list
385 {
386 0 ▶ my $paren = shift;
Subroutine format_list: not called CC=6 SCAR=37.4
Pod undocumented
387 0 ▶ my $indent_lim = $paren ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$paren ? : 0 0 0
388 0 my $tmp = "@_";
389 0 ▶ if (@_ > $indent_lim && (length($tmp) > 60 || $tmp =~ /\n/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > $indent_lim and length $tmp > 60 || $tmp =~ /\n/) { } 0 0 0
Condition0%0/6
@_ > $indent_lim and length $tmp > 60 || $tmp =~ /\n/
!ll&&!rl&&r
000
length $tmp > 60 or $tmp =~ /\n/
l!l&&r!l&&!r
000
MC/DC0%0/3
@_ > $indent_lim and length $tmp > 60 || $tmp =~ /\n/
@_ > $indent_lim length $tmp > 60 $tmp =~ /\n/
Truth table0%0/4
A and B or C
A= @_ > $indent_limB= length $tmp > 60C= $tmp =~ /\n/
ABCresult
0XX0
1000
11X1
1011
390 0 my @elem = @_;
391 0 for (@elem) { s/^/ /gm; } # indent
392 0 return "\n" . join(",\n", @elem, "");
393 } else {
394 0 return join(", ", @_)
395 }
396 }
397  
398 my %esc = (
399 "\a" => "\\a",
400 "\b" => "\\b",
401 "\t" => "\\t",
402 "\n" => "\\n",
403 "\f" => "\\f",
404 "\r" => "\\r",
405 "\e" => "\\e",
406 );
407  
408 # put a string value in double quotes
409 sub quote {
410 0 ▶ local($_) = $_[0];
Subroutine quote: not called CC=13 SCAR=52.0
Pod undocumented
411 0 ▶ if (length($_) > 20) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ > 20) 0 0 0
412 # Check for repeated string
413 0 ▶ if (/^(.{1,5}?)(\1*)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(.{1,5}?)(\1*)$/s) 0 0 0
414 0 my $base = quote($1);
415 0 my $repeat = length($2)/length($1) + 1;
416 0 return "($base x $repeat)";
417 }
418 }
419 # If there are many '"' we might want to use qq() instead
420 0 s/([\\\"\@\$])/\\$1/g;
421 0 ▶ return qq("$_") unless /[^\040-\176]/; # fast exit
Branch: 1 branch
BranchTrueFalseTotal
unless /[^\040-\176]/ 0 0 0
422  
423 0 my $high = $_[1];
424 0 s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
425  
426 # no need for 3 digits in escape for these
427 0 s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
428  
429 0 ▶ if ($high) {
Branch: 1 branch
BranchTrueFalseTotal
if ($high) { } 0 0 0
430 0 s/([\0-\037\177])/sprintf('\\%03o',ord($1))/eg;
431 0 ▶ if ($high eq "iso8859") {
Branch: 2 branches
BranchTrueFalseTotal
if ($high eq 'iso8859') { } 0 0 0
elsif ($high eq 'utf8') { } 0 0 0
432 0 s/[\200-\240]/sprintf('\\%o',ord($1))/eg;
433 } elsif ($high eq "utf8") {
434 # use utf8;
435 # $str =~ s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;
436 }
437 } else {
438 0 s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
439 0 s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
440 }
441  
442 0 ▶ if (length($_) > 40 && !/\\x\{/ && length($_) > (length($_[0]) * 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ > 40 and not /\\x\{/ and length $_ > length($_[0]) * 2) 0 0 0
Condition0%0/6
length $_ > 40 and not /\\x\{/ and length $_ > length($_[0]) * 2
!ll&&!rl&&r
000
length $_ > 40 and not /\\x\{/
!ll&&!rl&&r
000
MC/DC0%0/3
length $_ > 40 and not /\\x\{/ and length $_ > length($_[0]) * 2
length $_ > 40 not /\\x\{/ length $_ > length($_[0]) * 2
Truth table0%0/4
A and not(B) and C
A= length $_ > 40B= not /\\x\{/C= length $_ > length($_[0]) * 2
ABCresult
0XX0
10X0
1100
1111
443 # too much binary data, better to represent as a hex/base64 string
444  
445 # Base64 is more compact than hex when string is longer than
446 # 17 bytes (not counting any require statement needed).
447 # But on the other hand, hex is much more readable.
448 0 ▶ if ($TRY_BASE64 && length($_[0]) > $TRY_BASE64 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Data::Dump::TRY_BASE64 and length $_[0] > $DB::Data::Dump::TRY_BASE64 and eval { do { require MIME::Base64 } }) 0 0 0
Condition0%0/6
$DB::Data::Dump::TRY_BASE64 and length $_[0] > $DB::Data::Dump::TRY_BASE64 and eval { do { require MIME::Base64 } }
!ll&&!rl&&r
000
$DB::Data::Dump::TRY_BASE64 and length $_[0] > $DB::Data::Dump::TRY_BASE64
!ll&&!rl&&r
000
MC/DC0%0/3
$DB::Data::Dump::TRY_BASE64 and length $_[0] > $DB::Data::Dump::TRY_BASE64 and eval { do { require MIME::Base64 } }
$DB::Data::Dump::TRY_BASE64 length $_[0] > $DB::Data::Dump::TRY_BASE64 eval { do { require MIME::Base64 } }
Truth table0%0/4
A and B and C
A= $DB::Data::Dump::TRY_BASE64B= length $_[0] > $DB::Data::Dump::TRY_BASE64C= eval { do { require MIME::Base64 } }
ABCresult
0XX0
10X0
1100
1111
449 0 eval { require MIME::Base64 })
450 {
451 0 $require{"MIME::Base64"}++;
452 0 return "MIME::Base64::decode(\"" .
453 MIME::Base64::encode($_[0],"") .
454 "\")";
455 }
456 0 return "pack(\"H*\",\"" . unpack("H*", $_[0]) . "\")";
457 }
458  
459 0 return qq("$_");
460 }
461  
462 1;
463  
464 __END__
« blib/lib/dbgp-helper/perl5db.pl ↑ Summary blib/lib/dbgp-helper/DB/DbgrProperties.pm »