blib/lib/Test/NiceDump.pm

filter: Statementstmt 86.8% 53 / 61 Branchbran 87.5% 14 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 91.6% 22 / 24 Podpod 100% 4 / 4 totaltotal 87.0% 94 / 108 CC 11 SCAR 6.8
CC
11
Cov
86%
nice_explain
6.0
__ANON__
3.1
_dd_filter
3.0
CRAP 2.0
↑ Summary
1 package Test::NiceDump;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Safe::Isa 1.000010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dump;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::Dump::Filtered;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our @EXPORT_OK = ("nice_explain", "nice_dump");
14  
15 1 our $VERSION = '1.0.1'; # VERSION
16 # ABSTRACT: let's have a nice and human readable dump of our objects!
17  
18  
19 11 ▶sub _dd_recurse {
Subroutine _dd_recurse: called CC=1 SCAR=0.0
20 11 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 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 34 ▶ 'Test::NiceDump::010_DateTime' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
34 34 ▶ $_[0]->$_isa('DateTime')
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->$Test::NiceDump::_isa('DateTime') ? : 1 33 34
35 ? $_[0]->format_cldr("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
36 : ();
37 },
38 33 ▶ 'Test::NiceDump::011_Test_Deep_Methods' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
39 $_[0]->$_isa('Test::Deep::Methods')
40 ? $_[0]->{methods}
41 33 ▶ : ();
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->$Test::NiceDump::_isa('Test::Deep::Methods') ? : 1 32 33
42 },
43 32 ▶ 'Test::NiceDump::012_Test_Deep' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
44 (ref($_[0]) || '') =~ /^Test::Deep::/
45 ? $_[0]->{val}
46 32 ▶ : ();
Branch: 1 branch
BranchTrueFalseTotal
(ref $_[0] || '') =~ /^Test::Deep::/ ? : 1 31 32
Condition50%1/2
ref $_[0] || ''
l!l
320
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table50%1/2
A
A= ref $_[0]
Aresult
11
00
47 },
48 31 ▶ 'Test::NiceDump::013_DBIC_Schema' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
49 31 ▶ $_[0]->$_isa('DBIx::Class::Schema')
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->$Test::NiceDump::_isa('DBIx::Class::Schema') ? : 1 30 31
50 ? 'DBIx::Class::Schema object'
51 : ();
52 },
53 30 ▶ 'Test::NiceDump::020_overload' => sub { overload::Method($_[0],q{""}) ? "$_[0]" : () },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
overload::Method($_[0], '""') ? : 1 29 30
54 29 ▶ 'Test::NiceDump::021_as_string' => sub { shift->$_call_if_can('as_string') },
Subroutine __ANON__: called CC=1 SCAR=0.0
55 28 ▶ 'Test::NiceDump::022_to_string' => sub { shift->$_call_if_can('to_string') },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 27 ▶ 'Test::NiceDump::023_toString' => sub { shift->$_call_if_can('toString') },
Subroutine __ANON__: called CC=1 SCAR=0.0
57 26 ▶ 'Test::NiceDump::024_TO_JSON' => sub { shift->$_call_if_can('TO_JSON') },
Subroutine __ANON__: called CC=1 SCAR=0.0
58 25 ▶ 'Test::NiceDump::030_get_inflated_columns' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
59 25 my %c = shift->$_call_if_can('get_inflated_columns');
60 25 ▶ %c ? \%c : ();
Branch: 1 branch
BranchTrueFalseTotal
%c ? : 1 24 25
61 },
62 1 );
63  
64 34 ▶sub _dd_filter {
Subroutine _dd_filter: called CC=3 SCAR=11.0
65 34 my ($ctx, $object) = @_;
66  
67 34 for my $filter_name (sort keys %filters) {
68 298 my $filter_code = $filters{$filter_name};
69 298 my @filtered_object = $filter_code->($object);
70 298 ▶ if (@filtered_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filtered_object) 11 287 298
71 return {
72 11 dump => _dd_recurse($filtered_object[0]),
73 comment => $ctx->class,
74 };
75 }
76 }
77  
78 23 return;
79 }
80  
81  
82 3 ▶sub nice_dump {
Subroutine nice_dump: called CC=1 SCAR=0.0
Pod documented
83 3 my ($data) = @_;
84 3 return Data::Dump::Filtered::dump_filtered( $data, \&_dd_filter );
85 }
86  
87  
88 0 ▶sub nice_explain {
Subroutine nice_explain: not called CC=2 SCAR=17.9
Pod documented
89 0 my ($data, $comparator) = @_;
90 0 my $tb = Test::Builder->new; # singleton
91 0 $tb->diag("Got:" . nice_dump( $data ));
92 0 ▶ $tb->diag("Expected: " . nice_dump( $comparator )) if defined $comparator;
Branch: 1 branch
BranchTrueFalseTotal
if defined $comparator 0 0 0
93 0 return 0; # like diag / explain do
94 }
95  
96  
97 2 ▶sub add_filter {
Subroutine add_filter: called CC=1 SCAR=0.0
Pod documented
98 2 my ($filter_name, $filter_code) = @_;
99 2 $filters{$filter_name} = $filter_code;
100 2 return;
101 }
102  
103 0 ▶sub remove_filter {
Subroutine remove_filter: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($filter_name) = @_;
105 0 delete $filters{$filter_name};
106 0 return;
107 }
108  
109 1 1;
110  
111 __END__
↑ Summary