Data/Printer/Filter/ARRAY.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 93.3% 28 / 30 Conditioncond 80.0% 12 / 15 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 91.8% 113 / 123 CC 22 SCAR 29.0
CC
22
Cov
94%
parse
22.1
BEGIN
1.0
BEGIN
1.0
CRAP 18.2
« Data/Printer/Filter/HASH.pm ↑ Summary Data/Printer.pm »
1 package Data::Printer::Filter::ARRAY;
2 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use Data::Printer::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Data::Printer::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 filter 'ARRAY' => \&parse;
9  
10  
11 51 ▶sub parse {
Subroutine parse: called CC=22 SCAR=31.0
Pod undocumented
12 51 my ($array_ref, $ddp) = @_;
13  
14 51 my $tied = '';
15 51 ▶ if ($ddp->show_tied and my $tie = ref tied @$array_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->show_tied and my $tie = ref tied @$array_ref) 1 50 51
Condition100%3/3
$ddp->show_tied and my $tie = ref tied @$array_ref
!ll&&!rl&&r
3471
MC/DC100%2/2
$ddp->show_tied and my $tie = ref tied @$array_ref
$ddp->show_tied my $tie = ref tied @$array_ref
Truth table100%3/3
A and B
A= $ddp->show_tiedB= my $tie = ref tied @$array_ref
ABresult
0X0
100
111
16 1 $tied = " (tied to $tie)";
17 }
18  
19 51 ▶ return $ddp->maybe_colorize('[]', 'brackets') . $tied
Branch: 1 branch
BranchTrueFalseTotal
unless @$array_ref 5 46 51
20 unless @$array_ref;
21 46 ▶ return $ddp->maybe_colorize('[', 'brackets')
Branch: 1 branch
BranchTrueFalseTotal
if $ddp->max_depth and $ddp->current_depth >= $ddp->max_depth 1 45 46
Condition100%3/3
$ddp->max_depth and $ddp->current_depth >= $ddp->max_depth
!ll&&!rl&&r
4411
MC/DC100%2/2
$ddp->max_depth and $ddp->current_depth >= $ddp->max_depth
$ddp->max_depth $ddp->current_depth >= $ddp->max_depth
Truth table100%3/3
A and B
A= $ddp->max_depthB= $ddp->current_depth >= $ddp->max_depth
ABresult
0X0
100
111
22 . $ddp->maybe_colorize('...', 'array')
23 . $ddp->maybe_colorize(']', 'brackets')
24 . $tied
25 if $ddp->max_depth && $ddp->current_depth >= $ddp->max_depth;
26  
27 #Scalar::Util::weaken($array_ref);
28 45 my $string = $ddp->maybe_colorize('[', 'brackets');
29  
30 45 my @i = Data::Printer::Common::_fetch_indexes_for($array_ref, 'array', $ddp);
31  
32 # when showing array index, we must add the padding for newlines:
33 45 my $has_index = $ddp->index;
34 45 my $local_padding = 0;
35 45 ▶ if ($has_index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_index) 34 11 45
36 34 my $last_index;
37 # Get the last index shown to add the proper padding.
38 # If the array has 5000 elements but we're showing 4,
39 # the padding must be 3 + length(1), not 3 + length(5000):
40 34 ▶ for (my $idx = $#i; $idx >= 0; $idx--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= 0) 37 1 38
41 37 ▶ next if ref $i[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if ref $i[$idx] 4 33 37
42 33 $last_index = $i[$idx];
43 33 last;
44 }
45 34 ▶ if (defined $last_index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_index) 33 1 34
46 33 $local_padding = 3 + length($last_index);
47 33 $ddp->{_array_padding} += $local_padding;
48 }
49 }
50  
51 45 $ddp->indent;
52 45 foreach my $idx (@i) {
53 160 $string .= $ddp->newline;
54  
55 # $idx is a message to display, not a real index
56 160 ▶ if (ref $idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $idx) 7 153 160
57 7 $string .= $$idx;
58 7 next;
59 }
60  
61 153 my $original_varname = $ddp->current_name;
62 # if name was "var" it must become "var[0]", "var[1]", etc
63 153 ▶ $ddp->current_name(
Branch: 1 branch
BranchTrueFalseTotal
$ddp->arrows eq 'all' || $ddp->arrows eq 'first' && $ddp->current_depth == 1 ? : 0 153 153
Condition50%3/6
$ddp->arrows eq "all" or $ddp->arrows eq "first" and $ddp->current_depth == 1
l!l&&r!l&&!r
00153
$ddp->arrows eq "first" and $ddp->current_depth == 1
!ll&&!rl&&r
140130
MC/DC0%0/3
$ddp->arrows eq "all" or $ddp->arrows eq "first" and $ddp->current_depth == 1
$ddp->arrows eq "all" $ddp->arrows eq "first" $ddp->current_depth == 1
Truth table50%2/4
A or B and C
A= $ddp->arrows eq "all"B= $ddp->arrows eq "first"C= $ddp->current_depth == 1
ABCresult
1XX1
0111
00X0
0100
64 $original_varname
65 . ($ddp->arrows eq 'all' || ($ddp->arrows eq 'first' && $ddp->current_depth == 1) ? '->' : '')
66 . "[$idx]"
67 );
68  
69 153 ▶ if ($has_index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_index) 105 48 153
70 105 substr($string, -$local_padding) = ''; # get rid of local padding
71 105 $string .= $ddp->maybe_colorize(
72 sprintf("%-*s", $local_padding, "[$idx]"),
73 'array'
74 );
75 }
76  
77 # scalar references should be re-referenced to gain
78 # a '\' in front of them.
79 153 my $ref = ref $array_ref->[$idx];
80 153 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 41 112 153
81 41 ▶ if ($ref eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'SCALAR') { } 8 33 41
elsif ($ref eq 'REF') { } 0 33 33
82 8 $string .= $ddp->parse(\$array_ref->[$idx], tied_parent => !!$tied);
83 }
84 elsif ($ref eq 'REF') {
85 0 $string .= $ddp->parse(\$array_ref->[$idx], tied_parent => !!$tied);
86 }
87 else {
88 33 $string .= $ddp->parse($array_ref->[$idx], tied_parent => !!$tied);
89 }
90 }
91 else {
92 # not a reference, so we don't need to worry about refcounts.
93 # it helps to prevent cases where Perl reuses addresses:
94 112 $string .= $ddp->parse(\$array_ref->[$idx], seen_override => 1);
95 }
96  
97 $string .= $ddp->maybe_colorize($ddp->separator, 'separator')
98 153 ▶ if $idx < $#{$array_ref} || $ddp->end_separator;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < $#{$array_ref;} or $ddp->end_separator 114 39 153
Condition100%3/3
$idx < $#{$array_ref;} or $ddp->end_separator
l!l&&r!l&&!r
112239
MC/DC100%2/2
$idx < $#{$array_ref;} or $ddp->end_separator
$idx < $#{$array_ref;} $ddp->end_separator
Truth table100%3/3
A or B
A= $idx < $#{$array_ref;}B= $ddp->end_separator
ABresult
1X1
011
000
99  
100 # we're finished with "var[x]", turn it back to "var":
101 153 $ddp->current_name( $original_varname );
102 }
103 45 $ddp->outdent;
104 45 ▶ $ddp->{_array_padding} -= $local_padding if $has_index;
Branch: 1 branch
BranchTrueFalseTotal
if $has_index 34 11 45
105 45 $string .= $ddp->newline;
106 45 $string .= $ddp->maybe_colorize(']', 'brackets');
107  
108 45 return $string . $tied;
109 };
110  
111 #######################################
112 ### Private auxiliary helpers below ###
113 #######################################
114  
115 35 1;
« Data/Printer/Filter/HASH.pm ↑ Summary Data/Printer.pm »