line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NiceDump; |
2
|
1
|
|
|
1
|
|
55769
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use Exporter "import"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Test::Builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
384
|
use Safe::Isa 1.000010; |
|
1
|
|
|
|
|
440
|
|
|
1
|
|
|
|
|
108
|
|
9
|
1
|
|
|
1
|
|
947
|
use overload (); |
|
1
|
|
|
|
|
796
|
|
|
1
|
|
|
|
|
22
|
|
10
|
1
|
|
|
1
|
|
389
|
use Data::Dump; |
|
1
|
|
|
|
|
4115
|
|
|
1
|
|
|
|
|
51
|
|
11
|
1
|
|
|
1
|
|
390
|
use Data::Dump::Filtered; |
|
1
|
|
|
|
|
323
|
|
|
1
|
|
|
|
|
602
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = ("nice_explain", "nice_dump"); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
16
|
|
|
|
|
|
|
# ABSTRACT: let's have a nice and human readable dump of our objects! |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _dd_recurse { |
20
|
11
|
|
|
11
|
|
16
|
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
|
|
|
|
|
25
|
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
|
|
3878
|
my ($ctx, $object) = @_; |
66
|
|
|
|
|
|
|
|
67
|
34
|
|
|
|
|
146
|
for my $filter_name (sort keys %filters) { |
68
|
298
|
|
|
|
|
383
|
my $filter_code = $filters{$filter_name}; |
69
|
298
|
|
|
|
|
371
|
my @filtered_object = $filter_code->($object); |
70
|
298
|
100
|
|
|
|
2111
|
if (@filtered_object) { |
71
|
|
|
|
|
|
|
return { |
72
|
11
|
|
|
|
|
22
|
dump => _dd_recurse($filtered_object[0]), |
73
|
|
|
|
|
|
|
comment => $ctx->class, |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
23
|
|
|
|
|
42
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub nice_dump { |
83
|
3
|
|
|
3
|
1
|
4697
|
my ($data) = @_; |
84
|
3
|
|
|
|
|
12
|
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
|
622
|
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__ |