File Coverage

blib/lib/Test/Difflet.pm
Criterion Covered Total %
statement 44 48 91.6
branch 3 6 50.0
condition 1 3 33.3
subroutine 11 11 100.0
pod 0 1 0.0
total 59 69 85.5


line stmt bran cond sub pod time code
1             package Test::Difflet;
2 1     1   23196 use strict;
  1         3  
  1         49  
3 1     1   5 use warnings;
  1         2  
  1         33  
4 1     1   6 use utf8;
  1         3  
  1         8  
5 1     1   34 use Test::More;
  1         1  
  1         6  
6 1     1   982 use Data::Difflet;
  1         3  
  1         35  
7 1     1   6 use Data::Dumper;
  1         2  
  1         72  
8              
9             sub import {
10 1     1   7 my $class = shift;
11 1         3 my $pkg = caller(0);
12 1     1   5 no strict 'refs';
  1         2  
  1         50  
13 1         2 for (@_) {
14 1 50       5 if ($_ eq 'is_deeply') {
15 1     1   6 no warnings 'redefine';
  1         1  
  1         319  
16 1         1 *{"${pkg}::is_deeply"} = \&difflet_is_deeply;
  1         6  
17 1         3 *Test::More::is_deeply = \&difflet_is_deeply;
18             }
19             }
20 1         2 *{"${pkg}::difflet_is_deeply"} = \&difflet_is_deeply;
  1         1547  
21             }
22              
23             sub difflet_is_deeply {
24 1     1 0 16 my ($got, $expected, $msg) = @_;
25              
26 1         17 my $builder = Test::More->builder;
27 1         87 local $Test::Builder::Level = $Test::Builder::Level + 1;
28 1 50 33     20 if (-t *STDOUT || $ENV{HARNESS_ACTIVE}) {
29 1 50       5 if (_eq_deeply($got, $expected)) {
30 1         160 $builder->ok(1, $msg);
31             } else {
32 0         0 my $difflet = Data::Difflet->new();
33 0         0 $builder->ok(0, $msg);
34 0         0 $builder->diag($difflet->compare($got, $expected));
35             }
36             } else {
37 0         0 is_deeply($got, $expected, $msg);
38             }
39             }
40              
41             sub _eq_deeply {
42 1     1   2 my ($a, $b) = @_;
43 1         2 local $Data::Dumper::Terse = 1;
44 1         3 local $Data::Dumper::Indent = 0;
45 1         1 local $Data::Dumper::Sortkeys = 1;
46 1         6 return Dumper($a) eq Dumper($b);
47             }
48              
49             1;
50             __END__