DebugScreen/Dumper.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 81.5% 31 / 38 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 86.0% 105 / 122 CC 24 SCAR 28.3
CC
24
Cov
88%
_dump
22.4
_escape
4.0
BEGIN
1.0
CRAP 16.9
↑ Summary DebugScreen.pm »
1 package CGI::Carp::DebugScreen::Dumper;
2
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 3 our $VERSION = '0.15';
7
8 3 my $IgnoreOverload;
9
10 6 ▶sub ignore_overload { shift; $IgnoreOverload = shift; }
Subroutine ignore_overload: called CC=1 SCAR=0.0
Pod documented
11
12 22 ▶sub dump {
Subroutine dump: called CC=1 SCAR=0.0
Pod documented
13 22 my ($pkg, $thingy) = @_;
14
15 22 return _dump($thingy);
16 }
17
18 31 ▶sub _dump {
Subroutine _dump: called CC=21 SCAR=31.1
19 31 my $thingy = shift;
20
21 31 my $res = '';
22
23 31 ▶ require overload if $IgnoreOverload;
Branch: 1 branch
BranchTrueFalseTotal
if $IgnoreOverload 0 31 31
24
25 31 ▶ if (!defined $thingy) {
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $thingy) { } 1 30 31
elsif (ref $thingy eq 'HASH') { } 3 27 30
elsif (ref $thingy eq 'ARRAY') { } 3 24 27
elsif (ref $thingy eq 'SCALAR') { } 1 23 24
elsif (ref $thingy eq 'CODE') { } 2 21 23
elsif (ref $thingy eq 'GLOB') { } 1 20 21
elsif (my $name = ref $thingy) { } 3 17 20
26 1 $res .= 'undef';
27 }
28 elsif (ref $thingy eq 'HASH') {
29 3 ▶ if (%{ $thingy }) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$thingy;}) { } 2 1 3
30 2 $res = qq{<table class="watch" border="1">\n};
31 0 foreach my $key (sort {$a cmp $b} keys %{ $thingy }) {
32 2 $res .= q{<tr><th>}._escape($key).q{</th><td>}._dump($thingy->{$key}).qq{</td></tr>\n};
33 }
34 2 $res .= qq{</table>\n};
35 }
36 else {
37 1 $res .= '*EMPTY_HASH*';
38 }
39 }
40 elsif (ref $thingy eq 'ARRAY') {
41 3 ▶ if (@{ $thingy }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$thingy;}) { } 2 1 3
42 2 $res .= join ', ', map { _dump($_) } @{ $thingy };
43 }
44 else {
45 1 $res .= '*EMPTY_ARRAY*';
46 }
47 }
48 elsif (ref $thingy eq 'SCALAR') {
49 1 $res .= _escape(${ $thingy });
50 }
51 elsif (ref $thingy eq 'CODE') {
52 2 $res .= '*CODE*';
53 }
54 elsif (ref $thingy eq 'GLOB') {
55 1 $res .= '*GLOB*';
56 }
57 elsif (my $name = ref $thingy) {
58 3 my $blessed;
59 3 ▶ my $strval = $IgnoreOverload ? overload::StrVal($thingy) : '';
Branch: 1 branch
BranchTrueFalseTotal
$IgnoreOverload ? : 0 3 3
60 3 ▶ if ($thingy =~ /=HASH/ or $strval =~ /=HASH/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($thingy =~ /=HASH/ or $strval =~ /=HASH/) { } 1 2 3
elsif ($thingy =~ /=ARRAY/ or $strval =~ /=ARRAY/) { } 1 1 2
elsif ($thingy =~ /=SCALAR/ or $strval =~ /=SCALAR/) { } 1 0 1
elsif ($name eq 'REF') { } 0 0 0
Condition66%2/3
$thingy =~ /=HASH/ or $strval =~ /=HASH/
l!l&&r!l&&!r
102
MC/DC50%1/2
$thingy =~ /=HASH/ or $strval =~ /=HASH/
$thingy =~ /=HASH/ $strval =~ /=HASH/
Truth table66%2/3
A or B
A= $thingy =~ /=HASH/B= $strval =~ /=HASH/
ABresult
1X1
011
000
61 1 my %hash = %{ $thingy };
62 1 $blessed = \%hash;
63 }
64 ▶ elsif ($thingy =~ /=ARRAY/ or $strval =~ /=ARRAY/) {
Condition66%2/3
$thingy =~ /=ARRAY/ or $strval =~ /=ARRAY/
l!l&&r!l&&!r
101
MC/DC50%1/2
$thingy =~ /=ARRAY/ or $strval =~ /=ARRAY/
$thingy =~ /=ARRAY/ $strval =~ /=ARRAY/
Truth table66%2/3
A or B
A= $thingy =~ /=ARRAY/B= $strval =~ /=ARRAY/
ABresult
1X1
011
000
65 1 my @array = @{ $thingy };
66 1 $blessed = \@array;
67 }
68 ▶ elsif ($thingy =~ /=SCALAR/ or $strval =~ /=SCALAR/) {
Condition33%1/3
$thingy =~ /=SCALAR/ or $strval =~ /=SCALAR/
l!l&&r!l&&!r
100
MC/DC0%0/2
$thingy =~ /=SCALAR/ or $strval =~ /=SCALAR/
$thingy =~ /=SCALAR/ $strval =~ /=SCALAR/
Truth table33%1/3
A or B
A= $thingy =~ /=SCALAR/B= $strval =~ /=SCALAR/
ABresult
1X1
011
000
69 1 $blessed = $$thingy;
70 }
71 elsif ($name eq 'REF') {
72 0 $blessed = $$thingy;
73 }
74
75 3 $res .= qq{<table class="watch" border="1">\n};
76 3 ▶ $res .= q{<tr><th>}._escape($name).q{ (blessed)</th><td>}.($blessed ? _dump($blessed) : _escape($thingy)).qq{</td></tr>\n};
Branch: 1 branch
BranchTrueFalseTotal
$blessed ? : 3 0 3
77 3 $res .= qq{</table>\n};
78 }
79 else {
80 17 $res .= _escape($thingy);
81 }
82 31 return $res;
83 }
84
85 23 ▶sub _escape {
Subroutine _escape: called CC=4 SCAR=13.9
86 23 my $str = shift;
87
88 23 ▶ return 'undef' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 23 23
89 23 ▶ return '*BINARY*' if $str =~ /[\x00-\x08\x0b\x0c\x0e-\x1f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /[\x00-\x08\x0b\x0c\x0e-\x1f]/ 1 22 23
90
91 22 $str =~ s/&/&amp;/g;
92 22 $str =~ s/"/&quot;/g;
93 22 $str =~ s/>/&gt;/g;
94 22 $str =~ s/</&lt;/g;
95
96 22 ▶ $str eq '' ? '*BLANK*' : $str;
Branch: 1 branch
BranchTrueFalseTotal
$str eq '' ? : 1 21 22
97 }
98
99 3 1;
100
101 __END__
↑ Summary DebugScreen.pm »