line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
30
|
|
|
30
|
|
172
|
use warnings; |
|
30
|
|
|
|
|
45
|
|
|
30
|
|
|
|
|
740
|
|
4
|
30
|
|
|
30
|
|
128
|
|
|
30
|
|
|
|
|
50
|
|
|
30
|
|
|
|
|
1038
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.48'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Scalar::Util qw( looks_like_number reftype blessed ); |
8
|
30
|
|
|
30
|
|
144
|
|
|
30
|
|
|
|
|
68
|
|
|
30
|
|
|
|
|
1451
|
|
9
|
|
|
|
|
|
|
use Exporter qw( import ); |
10
|
30
|
|
|
30
|
|
147
|
|
|
30
|
|
|
|
|
55
|
|
|
30
|
|
|
|
|
28790
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( partial_dump ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $MaxLength = 100; |
14
|
|
|
|
|
|
|
my $MaxElements = 6; |
15
|
|
|
|
|
|
|
my $MaxDepth = 2; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my (@args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
2485
|
|
|
2485
|
0
|
5937
|
my $dump |
20
|
|
|
|
|
|
|
= _should_dump_as_pairs(@args) |
21
|
2485
|
50
|
|
|
|
5089
|
? _dump_as_pairs( 1, @args ) |
22
|
|
|
|
|
|
|
: _dump_as_list( 1, @args ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( length($dump) > $MaxLength ) { |
25
|
|
|
|
|
|
|
my $max_length = $MaxLength - 3; |
26
|
2485
|
100
|
|
|
|
10178
|
$max_length = 0 if $max_length < 0; |
27
|
2
|
|
|
|
|
5
|
substr( $dump, $max_length, length($dump) - $max_length ) = '...'; |
28
|
2
|
50
|
|
|
|
7
|
} |
29
|
2
|
|
|
|
|
6
|
|
30
|
|
|
|
|
|
|
return $dump; |
31
|
|
|
|
|
|
|
} |
32
|
2485
|
|
|
|
|
13220
|
|
33
|
|
|
|
|
|
|
my (@what) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return if @what % 2 != 0; # must be an even list |
36
|
2485
|
|
|
2485
|
|
4228
|
|
37
|
|
|
|
|
|
|
for ( my $i = 0; $i < @what; $i += 2 ) { |
38
|
2485
|
50
|
|
|
|
11882
|
return if ref $what[$i]; # plain strings are keys |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
0
|
|
41
|
0
|
0
|
|
|
|
0
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
my ( $depth, @what ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $truncated; |
47
|
|
|
|
|
|
|
if ( defined $MaxElements and ( @what / 2 ) > $MaxElements ) { |
48
|
316
|
|
|
316
|
|
672
|
$truncated = 1; |
49
|
|
|
|
|
|
|
@what = splice( @what, 0, $MaxElements * 2 ); |
50
|
316
|
|
|
|
|
420
|
} |
51
|
316
|
50
|
33
|
|
|
1567
|
|
52
|
0
|
|
|
|
|
0
|
return join( |
53
|
0
|
|
|
|
|
0
|
', ', _dump_as_pairs_recursive( $depth, @what ), |
54
|
|
|
|
|
|
|
( $truncated ? "..." : () ) |
55
|
|
|
|
|
|
|
); |
56
|
316
|
50
|
|
|
|
795
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my ( $depth, @what ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return unless @what; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my ( $key, $value, @rest ) = @what; |
63
|
508
|
|
|
508
|
|
948
|
|
64
|
|
|
|
|
|
|
return ( |
65
|
508
|
100
|
|
|
|
3135
|
( _format_key( $depth, $key ) . ': ' . _format( $depth, $value ) ), |
66
|
|
|
|
|
|
|
_dump_as_pairs_recursive( $depth, @rest ), |
67
|
192
|
|
|
|
|
382
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
192
|
|
|
|
|
365
|
my ( $depth, @what ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $truncated; |
73
|
|
|
|
|
|
|
if ( @what > $MaxElements ) { |
74
|
|
|
|
|
|
|
$truncated = 1; |
75
|
|
|
|
|
|
|
@what = splice( @what, 0, $MaxElements ); |
76
|
2751
|
|
|
2751
|
|
5196
|
} |
77
|
|
|
|
|
|
|
|
78
|
2751
|
|
|
|
|
3357
|
return join( |
79
|
2751
|
50
|
|
|
|
5675
|
', ', ( map { _format( $depth, $_ ) } @what ), |
80
|
0
|
|
|
|
|
0
|
( $truncated ? "..." : () ) |
81
|
0
|
|
|
|
|
0
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my ( $depth, $value ) = @_; |
85
|
2751
|
50
|
|
|
|
5561
|
|
|
2789
|
|
|
|
|
5218
|
|
86
|
|
|
|
|
|
|
defined($value) |
87
|
|
|
|
|
|
|
? ( |
88
|
|
|
|
|
|
|
ref($value) |
89
|
|
|
|
|
|
|
? ( |
90
|
|
|
|
|
|
|
blessed($value) |
91
|
3887
|
|
|
3887
|
|
5964
|
? _format_object( $depth, $value ) |
92
|
|
|
|
|
|
|
: _format_ref( $depth, $value ) |
93
|
3887
|
100
|
|
|
|
17358
|
) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
94
|
|
|
|
|
|
|
: ( |
95
|
|
|
|
|
|
|
looks_like_number($value) |
96
|
|
|
|
|
|
|
? _format_number( $depth, $value ) |
97
|
|
|
|
|
|
|
: _format_string( $depth, $value ) |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
) |
100
|
|
|
|
|
|
|
: _format_undef( $depth, $value ),; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ( undef, $key ) = @_; |
104
|
|
|
|
|
|
|
return $key; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my ( $depth, $ref ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if ( $depth > $MaxDepth ) { |
110
|
|
|
|
|
|
|
return overload::StrVal($ref); |
111
|
192
|
|
|
192
|
|
325
|
} |
112
|
192
|
|
|
|
|
459
|
else { |
113
|
|
|
|
|
|
|
my $reftype = reftype($ref); |
114
|
|
|
|
|
|
|
$reftype = 'SCALAR' |
115
|
|
|
|
|
|
|
if $reftype eq 'REF' || $reftype eq 'LVALUE'; |
116
|
2076
|
|
|
2076
|
|
3368
|
my $method = "_format_" . lc $reftype; |
117
|
|
|
|
|
|
|
|
118
|
2076
|
100
|
|
|
|
3907
|
if ( my $sub = __PACKAGE__->can($method) ) { |
119
|
22
|
|
|
|
|
60
|
return $sub->( $depth, $ref ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
2054
|
|
|
|
|
4383
|
return overload::StrVal($ref); |
123
|
2054
|
100
|
66
|
|
|
8032
|
} |
124
|
|
|
|
|
|
|
} |
125
|
2054
|
|
|
|
|
4394
|
} |
126
|
|
|
|
|
|
|
|
127
|
2054
|
100
|
|
|
|
9540
|
my ( $depth, $array ) = @_; |
128
|
1488
|
|
|
|
|
3144
|
|
129
|
|
|
|
|
|
|
my $class = blessed($array) || ''; |
130
|
|
|
|
|
|
|
$class .= "=" if $class; |
131
|
566
|
|
|
|
|
1761
|
|
132
|
|
|
|
|
|
|
return $class . "[ " . _dump_as_list( $depth + 1, @$array ) . " ]"; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my ( $depth, $hash ) = @_; |
136
|
|
|
|
|
|
|
|
137
|
266
|
|
|
266
|
|
480
|
my $class = blessed($hash) || ''; |
138
|
|
|
|
|
|
|
$class .= "=" if $class; |
139
|
266
|
|
100
|
|
|
934
|
|
140
|
266
|
100
|
|
|
|
620
|
return $class . "{ " . _dump_as_pairs( |
141
|
|
|
|
|
|
|
$depth + 1, |
142
|
266
|
|
|
|
|
1330
|
map { $_ => $hash->{$_} } sort keys %$hash |
143
|
|
|
|
|
|
|
) . " }"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
316
|
|
|
316
|
|
611
|
my ( $depth, $scalar ) = @_; |
147
|
|
|
|
|
|
|
|
148
|
316
|
|
100
|
|
|
1119
|
my $class = blessed($scalar) || ''; |
149
|
316
|
100
|
|
|
|
756
|
$class .= "=" if $class; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
return $class . "\\" . _format( $depth + 1, $$scalar ); |
152
|
|
|
|
|
|
|
} |
153
|
316
|
|
|
|
|
1600
|
|
|
192
|
|
|
|
|
621
|
|
154
|
|
|
|
|
|
|
my ( $depth, $object ) = @_; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return _format_ref( $depth, $object ); |
157
|
|
|
|
|
|
|
} |
158
|
906
|
|
|
906
|
|
1554
|
|
159
|
|
|
|
|
|
|
my ( undef, $str ) = @_; |
160
|
906
|
|
100
|
|
|
2728
|
|
161
|
906
|
100
|
|
|
|
2028
|
# FIXME use String::Escape ? |
162
|
|
|
|
|
|
|
|
163
|
906
|
|
|
|
|
3192
|
# remove vertical whitespace |
164
|
|
|
|
|
|
|
$str =~ s/\n/\\n/g; |
165
|
|
|
|
|
|
|
$str =~ s/\r/\\r/g; |
166
|
|
|
|
|
|
|
|
167
|
1159
|
|
|
1159
|
|
2154
|
# reformat nonprintables |
168
|
|
|
|
|
|
|
$str =~ s/(\P{IsPrint})/"\\x{" . sprintf("%x", ord($1)) . "}"/ge; |
169
|
1159
|
|
|
|
|
2271
|
|
170
|
|
|
|
|
|
|
_quote($str); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
505
|
|
|
505
|
|
1040
|
my ($str) = @_; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
qq{"$str"}; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
505
|
|
|
|
|
1131
|
|
179
|
505
|
|
|
|
|
809
|
my ( undef, $value ) = @_; |
180
|
|
|
|
|
|
|
return "$value"; |
181
|
|
|
|
|
|
|
} |
182
|
30
|
|
|
30
|
|
13536
|
|
|
30
|
|
|
|
|
370
|
|
|
30
|
|
|
|
|
420
|
|
|
505
|
|
|
|
|
1022
|
|
|
4
|
|
|
|
|
26
|
|
183
|
|
|
|
|
|
|
# ABSTRACT: A partially rear-ended copy of Devel::PartialDump without prereqs |
184
|
505
|
|
|
|
|
1179
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
505
|
|
|
505
|
|
903
|
=pod |
189
|
|
|
|
|
|
|
|
190
|
505
|
|
|
|
|
3240
|
=encoding UTF-8 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 NAME |
193
|
188
|
|
|
188
|
|
1220
|
|
194
|
|
|
|
|
|
|
Specio::PartialDump - A partially rear-ended copy of Devel::PartialDump without prereqs |
195
|
|
|
|
|
|
|
|
196
|
1118
|
|
|
1118
|
|
2143
|
=head1 VERSION |
197
|
1118
|
|
|
|
|
6750
|
|
198
|
|
|
|
|
|
|
version 0.48 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SYNOPSIS |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
use Specio::PartialDump qw( partial_dump ); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
partial_dump( { foo => 42 } ); |
205
|
|
|
|
|
|
|
partial_dump(qw( a b c d e f g )); |
206
|
|
|
|
|
|
|
partial_dump( foo => 42, bar => [ 1, 2, 3 ], ); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 DESCRIPTION |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This is a copy of Devel::PartialDump with all the OO bits and prereqs |
211
|
|
|
|
|
|
|
removed. You may want to use this module in your own code to generate nicely |
212
|
|
|
|
|
|
|
formatted messages when a type constraint fails. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This module optionally exports one sub, C<partial_dump>. This sub accepts any |
215
|
|
|
|
|
|
|
number of arguments. If given more than one, it will assume that it's either |
216
|
|
|
|
|
|
|
been given a list of key/value pairs (to build a hash) or a list of values (to |
217
|
|
|
|
|
|
|
build an array) and dump them appropriately. Objects and references are |
218
|
|
|
|
|
|
|
stringified in a sane way. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=for Pod::Coverage partial_dump |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 SUPPORT |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 SOURCE |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This software is copyright (c) 2008 by יובל קוג'מן (Yuval Kogman). |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
239
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |