line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NiceDump; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
111669
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Exporter "import"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Test::Builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
675
|
use Safe::Isa 1.000010; |
|
1
|
|
|
|
|
464
|
|
|
1
|
|
|
|
|
276
|
|
10
|
1
|
|
|
1
|
|
1618
|
use overload (); |
|
1
|
|
|
|
|
1428
|
|
|
1
|
|
|
|
|
94
|
|
11
|
1
|
|
|
1
|
|
518
|
use Data::Dump; |
|
1
|
|
|
|
|
6591
|
|
|
1
|
|
|
|
|
73
|
|
12
|
1
|
|
|
1
|
|
574
|
use Data::Dump::Filtered; |
|
1
|
|
|
|
|
552
|
|
|
1
|
|
|
|
|
862
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = ("nice_explain", "nice_dump"); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: let's have a nice and human readable dump of our objects! |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _dd_recurse { |
20
|
11
|
|
|
11
|
|
17
|
my ($object) = @_; |
21
|
|
|
|
|
|
|
# Data::Dump resets its filters when dumping the objects |
22
|
|
|
|
|
|
|
# we return; if we do it this way, we force it to keep |
23
|
|
|
|
|
|
|
# filtering, so (e.g.) datetime objects inside DBIC rows |
24
|
|
|
|
|
|
|
# will get dumped the way we want |
25
|
11
|
|
|
|
|
26
|
return Data::Dump::Filtered::dump_filtered( |
26
|
|
|
|
|
|
|
$object, |
27
|
|
|
|
|
|
|
\&_dd_filter, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# functions to modify this hash are at the bottom of this file |
32
|
|
|
|
|
|
|
my %filters = ( |
33
|
|
|
|
|
|
|
'Test::NiceDump::010_DateTime' => sub { |
34
|
|
|
|
|
|
|
$_[0]->$_isa('DateTime') |
35
|
|
|
|
|
|
|
? $_[0]->format_cldr("yyyy-MM-dd'T'HH:mm:ssZZZZZ") |
36
|
|
|
|
|
|
|
: (); |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
'Test::NiceDump::011_Test_Deep_Methods' => sub { |
39
|
|
|
|
|
|
|
$_[0]->$_isa('Test::Deep::Methods') |
40
|
|
|
|
|
|
|
? $_[0]->{methods} |
41
|
|
|
|
|
|
|
: (); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
'Test::NiceDump::012_Test_Deep' => sub { |
44
|
|
|
|
|
|
|
(ref($_[0]) || '') =~ /^Test::Deep::/ |
45
|
|
|
|
|
|
|
? $_[0]->{val} |
46
|
|
|
|
|
|
|
: (); |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
'Test::NiceDump::013_DBIC_Schema' => sub { |
49
|
|
|
|
|
|
|
$_[0]->$_isa('DBIx::Class::Schema') |
50
|
|
|
|
|
|
|
? 'DBIx::Class::Schema object' |
51
|
|
|
|
|
|
|
: (); |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
'Test::NiceDump::020_overload' => sub { overload::Method($_[0],q{""}) ? "$_[0]" : () }, |
54
|
|
|
|
|
|
|
'Test::NiceDump::021_as_string' => sub { shift->$_call_if_can('as_string') }, |
55
|
|
|
|
|
|
|
'Test::NiceDump::022_to_string' => sub { shift->$_call_if_can('to_string') }, |
56
|
|
|
|
|
|
|
'Test::NiceDump::023_toString' => sub { shift->$_call_if_can('toString') }, |
57
|
|
|
|
|
|
|
'Test::NiceDump::024_TO_JSON' => sub { shift->$_call_if_can('TO_JSON') }, |
58
|
|
|
|
|
|
|
'Test::NiceDump::030_get_inflated_columns' => sub { |
59
|
|
|
|
|
|
|
my %c = shift->$_call_if_can('get_inflated_columns'); |
60
|
|
|
|
|
|
|
%c ? \%c : (); |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _dd_filter { |
65
|
34
|
|
|
34
|
|
4526
|
my ($ctx, $object) = @_; |
66
|
|
|
|
|
|
|
|
67
|
34
|
|
|
|
|
239
|
for my $filter_name (sort keys %filters) { |
68
|
298
|
|
|
|
|
401
|
my $filter_code = $filters{$filter_name}; |
69
|
298
|
|
|
|
|
483
|
my @filtered_object = $filter_code->($object); |
70
|
298
|
100
|
|
|
|
2378
|
if (@filtered_object) { |
71
|
|
|
|
|
|
|
return { |
72
|
11
|
|
|
|
|
21
|
dump => _dd_recurse($filtered_object[0]), |
73
|
|
|
|
|
|
|
comment => $ctx->class, |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
23
|
|
|
|
|
48
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub nice_dump { |
83
|
3
|
|
|
3
|
1
|
4618
|
my ($data) = @_; |
84
|
3
|
|
|
|
|
14
|
return Data::Dump::Filtered::dump_filtered( $data, \&_dd_filter ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub nice_explain { |
89
|
0
|
|
|
0
|
1
|
0
|
my ($data, $comparator) = @_; |
90
|
0
|
|
|
|
|
0
|
my $tb = Test::Builder->new; # singleton |
91
|
0
|
|
|
|
|
0
|
$tb->diag("Got:" . nice_dump( $data )); |
92
|
0
|
0
|
|
|
|
0
|
$tb->diag("Expected: " . nice_dump( $comparator )) if defined $comparator; |
93
|
0
|
|
|
|
|
0
|
return 0; # like diag / explain do |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub add_filter { |
98
|
2
|
|
|
2
|
1
|
731
|
my ($filter_name, $filter_code) = @_; |
99
|
2
|
|
|
|
|
5
|
$filters{$filter_name} = $filter_code; |
100
|
2
|
|
|
|
|
3
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub remove_filter { |
104
|
0
|
|
|
0
|
1
|
|
my ($filter_name) = @_; |
105
|
0
|
|
|
|
|
|
delete $filters{$filter_name}; |
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |