blib/lib/YATT/Lite/XHF/Dumper.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 96.1% 25 / 26 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 6 totaltotal 93.5% 131 / 140 CC 20 SCAR 13.1
CC
20
Cov
97%
_dump_pairs
6.0
_dump_value
5.2
escape
4.0
CRAP 3.7
« misc/cpan/MyBuilder.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/Partial/Session2.pm »
1 package YATT::Lite::XHF::Dumper;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 our $VERSION = "0.02";
5  
6 11 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 our @EXPORT_OK = qw(dump_xhf);
8 11 our @EXPORT = @EXPORT_OK;
9  
10 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 ▶use YATT::Lite::XHF qw($cc_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 our $TRIM_TRAILING_NEWLINES = 1;
16  
17 19 ▶sub dump_xhf {
Subroutine dump_xhf: called CC=1 SCAR=0.0
Pod undocumented
18 19 shift;
19 19 _dump_pairs(@_);
20 }
21  
22 16 ▶sub dump_strict_xhf {
Subroutine dump_strict_xhf: called CC=1 SCAR=0.0
Pod undocumented
23 16 shift;
24 16 local $TRIM_TRAILING_NEWLINES = 0;
25 16 _dump_pairs(@_);
26 }
27  
28 283 ▶sub _dump_pairs {
Subroutine _dump_pairs: called CC=6 SCAR=17.9
29 283 my @buffer;
30 283 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 714 283 997
31 714 ▶ if (@_ == 1 or not defined $_[0] or ref $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 or not defined $_[0] or ref $_[0]) { } 29 685 714
elsif ($_[0] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/) { } 681 4 685
Condition100%6/6
@_ == 1 or not defined $_[0] or ref $_[0]
l!l&&r!l&&!r
263685
@_ == 1 or not defined $_[0]
l!l&&r!l&&!r
242688
MC/DC100%3/3
@_ == 1 or not defined $_[0] or ref $_[0]
@_ == 1 not defined $_[0] ref $_[0]
Truth table100%4/4
A or not(B) or C
A= @_ == 1B= not defined $_[0]C= ref $_[0]
ABCresult
1XX1
01X1
0011
0000
32 29 push @buffer, _dump_value(shift, '-');
33 } elsif ($_[0] =~ m{^$cc_name+$}) {
34 681 push @buffer, shift() . _dump_value(shift, ':');
35 } else {
36 # ('', undef) => "-\n= #null"
37 4 push @buffer, '-' . escape(shift), _dump_value(shift, '-');
38 }
39 }
40 283 join "\n", @buffer;
41 }
42  
43 912 ▶sub _dump_value {
Subroutine _dump_value: called CC=5 SCAR=16.5
44 # value part.
45 912 ▶ unless (defined $_[0]) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $_[0]) { } 884 28 912
if (do { not ref $_[0] }) { } 566 318 884
elsif (ref $_[0] eq 'ARRAY') { } 91 227 318
elsif (ref $_[0] eq 'HASH') { } 227 0 227
46 28 "= #null";
47 } elsif (not ref $_[0]) {
48 566 $_[1] . escape(shift);
49 } elsif (ref $_[0] eq 'ARRAY') {
50 91 dump_array(shift);
51 } elsif (ref $_[0] eq 'HASH') {
52 227 dump_hash(shift);
53 } else {
54 0 croak "Can't dump ref(@{[ref $_[0]]}) as XHF: $_[0]";
55 }
56 }
57  
58 570 ▶sub escape {
Subroutine escape: called CC=4 SCAR=13.9
Pod undocumented
59 570 my ($str) = @_;
60 570 my $use_verbatim = do {
61 570 ▶ ($TRIM_TRAILING_NEWLINES and $str =~ s/\n\z//)
Condition100%6/6
$YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINES && $str =~ s/\n\z// || $str =~ /^\s+|\s+$/s
l!l&&r!l&&!r
392475
$YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINES and $str =~ s/\n\z//
!ll&&!rl&&r
534333
MC/DC100%3/3
$YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINES && $str =~ s/\n\z// || $str =~ /^\s+|\s+$/s
$YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINES $str =~ s/\n\z// $str =~ /^\s+|\s+$/s
Truth table80%4/5
A and B || C
A= $YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINESB= $str =~ s/\n\z//C= $str =~ /^\s+|\s+$/s
ABCresult
11X1
0X11
1011
0X00
1000
62 or
63 ($str =~ /^\s+|\s+$/s)
64 };
65 570 my $sep = do {
66 570 ▶ if ($use_verbatim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_verbatim) { } 95 475 570
67 95 "\n "
68 } else {
69 475 " "
70 }
71 };
72 570 $str =~ s/\n/\n /g;
73 570 $sep . $str;
74 }
75  
76 91 ▶sub dump_array {
Subroutine dump_array: called CC=4 SCAR=13.9
Pod undocumented
77 91 my ($item) = @_;
78 91 "[\n" . do {
79 91 ▶ if (not @$item) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @$item) { } 2 89 91
elsif (@$item % 2 == 0 and looks_like_hash($item)) { } 22 67 89
80 2 "";
81 ▶ } elsif (@$item % 2 == 0 and looks_like_hash($item)) {
Condition100%3/3
@$item % 2 == 0 and looks_like_hash($item)
!ll&&!rl&&r
442322
MC/DC100%2/2
@$item % 2 == 0 and looks_like_hash($item)
@$item % 2 == 0 looks_like_hash($item)
Truth table100%3/3
A and B
A= @$item % 2 == 0B= looks_like_hash($item)
ABresult
0X0
100
111
82 22 _dump_pairs(@$item)."\n";
83 } else {
84 67 join("\n", map {_dump_value($_, '-')} @$item)."\n";
85 }
86 } . "]";
87 }
88  
89 45 ▶sub looks_like_hash {
Subroutine looks_like_hash: called CC=4 SCAR=13.9
Pod undocumented
90 45 my ($item) = @_;
91 45 ▶ for (my $i = 0; $i < @$item; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$item) 51 22 73
92 51 ▶ return 0 if ref($item->[$i]) or $item->[$i] !~ m{^$cc_name+$};
Branch: 1 branch
BranchTrueFalseTotal
if ref $item->[$i] or not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/ 23 28 51
Condition100%3/3
ref $item->[$i] or not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/
l!l&&r!l&&!r
14928
MC/DC100%2/2
ref $item->[$i] or not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/
ref $item->[$i] not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/
Truth table100%3/3
A or not(B)
A= ref $item->[$i]B= not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/
ABresult
1X1
011
000
93 }
94 22 return 1;
95 }
96  
97 227 ▶sub dump_hash {
Subroutine dump_hash: called CC=2 SCAR=6.9
Pod undocumented
98 227 my ($item) = @_;
99 227 "{\n" . do {
100 227 ▶ if (not %$item) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %$item) { } 1 226 227
101 1 "";
102 } else {
103 226 _dump_pairs(map {$_, $item->{$_}} sort keys %$item)."\n";
104 }
105 }. "}";
106 }
107  
108 __END__
« misc/cpan/MyBuilder.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/Partial/Session2.pm »