line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Printer::Filter::ARRAY; |
2
|
34
|
|
|
34
|
|
267
|
use strict; |
|
34
|
|
|
|
|
71
|
|
|
34
|
|
|
|
|
984
|
|
3
|
34
|
|
|
34
|
|
176
|
use warnings; |
|
34
|
|
|
|
|
68
|
|
|
34
|
|
|
|
|
815
|
|
4
|
34
|
|
|
34
|
|
171
|
use Data::Printer::Filter; |
|
34
|
|
|
|
|
71
|
|
|
34
|
|
|
|
|
241
|
|
5
|
34
|
|
|
34
|
|
207
|
use Data::Printer::Common; |
|
34
|
|
|
|
|
77
|
|
|
34
|
|
|
|
|
891
|
|
6
|
34
|
|
|
34
|
|
226
|
use Scalar::Util (); |
|
34
|
|
|
|
|
89
|
|
|
34
|
|
|
|
|
19913
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
filter 'ARRAY' => \&parse; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub parse { |
12
|
51
|
|
|
51
|
0
|
112
|
my ($array_ref, $ddp) = @_; |
13
|
|
|
|
|
|
|
|
14
|
51
|
|
|
|
|
96
|
my $tied = ''; |
15
|
51
|
100
|
100
|
|
|
142
|
if ($ddp->show_tied and my $tie = ref tied @$array_ref) { |
16
|
1
|
|
|
|
|
7
|
$tied = " (tied to $tie)"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
51
|
100
|
|
|
|
183
|
return $ddp->maybe_colorize('[]', 'brackets') . $tied |
20
|
|
|
|
|
|
|
unless @$array_ref; |
21
|
46
|
100
|
100
|
|
|
148
|
return $ddp->maybe_colorize('[', 'brackets') |
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
|
|
|
|
|
146
|
my $string = $ddp->maybe_colorize('[', 'brackets'); |
29
|
|
|
|
|
|
|
|
30
|
45
|
|
|
|
|
171
|
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
|
|
|
|
|
167
|
my $has_index = $ddp->index; |
34
|
45
|
|
|
|
|
96
|
my $local_padding = 0; |
35
|
45
|
100
|
|
|
|
123
|
if ($has_index) { |
36
|
34
|
|
|
|
|
65
|
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
|
|
|
|
|
109
|
for (my $idx = $#i; $idx >= 0; $idx--) { |
41
|
37
|
100
|
|
|
|
99
|
next if ref $i[$idx]; |
42
|
33
|
|
|
|
|
60
|
$last_index = $i[$idx]; |
43
|
33
|
|
|
|
|
62
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
34
|
100
|
|
|
|
79
|
if (defined $last_index) { |
46
|
33
|
|
|
|
|
75
|
$local_padding = 3 + length($last_index); |
47
|
33
|
|
|
|
|
70
|
$ddp->{_array_padding} += $local_padding; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
45
|
|
|
|
|
149
|
$ddp->indent; |
52
|
45
|
|
|
|
|
104
|
foreach my $idx (@i) { |
53
|
160
|
|
|
|
|
367
|
$string .= $ddp->newline; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# $idx is a message to display, not a real index |
56
|
160
|
100
|
|
|
|
403
|
if (ref $idx) { |
57
|
7
|
|
|
|
|
16
|
$string .= $$idx; |
58
|
7
|
|
|
|
|
15
|
next; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
153
|
|
|
|
|
335
|
my $original_varname = $ddp->current_name; |
62
|
|
|
|
|
|
|
# if name was "var" it must become "var[0]", "var[1]", etc |
63
|
153
|
50
|
33
|
|
|
399
|
$ddp->current_name( |
64
|
|
|
|
|
|
|
$original_varname |
65
|
|
|
|
|
|
|
. ($ddp->arrows eq 'all' || ($ddp->arrows eq 'first' && $ddp->current_depth == 1) ? '->' : '') |
66
|
|
|
|
|
|
|
. "[$idx]" |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
153
|
100
|
|
|
|
355
|
if ($has_index) { |
70
|
105
|
|
|
|
|
239
|
substr($string, -$local_padding) = ''; # get rid of local padding |
71
|
105
|
|
|
|
|
568
|
$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
|
|
|
|
|
379
|
my $ref = ref $array_ref->[$idx]; |
80
|
153
|
100
|
|
|
|
325
|
if ($ref) { |
81
|
41
|
100
|
|
|
|
127
|
if ($ref eq 'SCALAR') { |
|
|
50
|
|
|
|
|
|
82
|
8
|
|
|
|
|
23
|
$string .= $ddp->parse(\$array_ref->[$idx]); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif ($ref eq 'REF') { |
85
|
0
|
|
|
|
|
0
|
$string .= $ddp->parse(\$array_ref->[$idx]); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
33
|
|
|
|
|
100
|
$string .= $ddp->parse($array_ref->[$idx]); |
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
|
|
|
|
|
387
|
$string .= $ddp->parse(\$array_ref->[$idx], seen_override => 1); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$string .= $ddp->maybe_colorize($ddp->separator, 'separator') |
98
|
153
|
100
|
100
|
|
|
353
|
if $idx < $#{$array_ref} || $ddp->end_separator; |
|
153
|
|
|
|
|
661
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# we're finished with "var[x]", turn it back to "var": |
101
|
153
|
|
|
|
|
408
|
$ddp->current_name( $original_varname ); |
102
|
|
|
|
|
|
|
} |
103
|
45
|
|
|
|
|
184
|
$ddp->outdent; |
104
|
45
|
100
|
|
|
|
126
|
$ddp->{_array_padding} -= $local_padding if $has_index; |
105
|
45
|
|
|
|
|
128
|
$string .= $ddp->newline; |
106
|
45
|
|
|
|
|
157
|
$string .= $ddp->maybe_colorize(']', 'brackets'); |
107
|
|
|
|
|
|
|
|
108
|
45
|
|
|
|
|
212
|
return $string . $tied; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
####################################### |
112
|
|
|
|
|
|
|
### Private auxiliary helpers below ### |
113
|
|
|
|
|
|
|
####################################### |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |