| 1 | package YATT::Lite::XHF::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | our $VERSION = "0.02"; | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | our @EXPORT_OK = qw(dump_xhf); | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | our @EXPORT = @EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use YATT::Lite::XHF qw($cc_name); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 714 | ▶ | if (@_ == 1 or not defined $_[0] or ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
@_ == 1 or not defined $_[0] or ref $_[0]
@_ == 1 or not defined $_[0]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
$YATT::Lite::XHF::Dumper::TRIM_TRAILING_NEWLINES and $str =~ s/\n\z//
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | or | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ($str =~ /^\s+|\s+$/s) | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 570 | my $sep = do { | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 570 | ▶ | if ($use_verbatim) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | } elsif (@$item % 2 == 0 and looks_like_hash($item)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@$item % 2 == 0 and looks_like_hash($item)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 51 | ▶ | return 0 if ref($item->[$i]) or $item->[$i] !~ m{^$cc_name+$}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $item->[$i] or not $item->[$i] =~ /^$YATT::Lite::XHF::Dumper::cc_name+$/
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+$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 226 | _dump_pairs(map {$_, $item->{$_}} sort keys %$item)."\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | }. "}"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||