File Coverage

blib/lib/Data/Hash/Diff/Smart/Renderer/Test2.pm
Criterion Covered Total %
statement 18 19 94.7
branch 7 8 87.5
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 28 31 90.3


line stmt bran cond sub pod time code
1             package Data::Hash::Diff::Smart::Renderer::Test2;
2              
3 1     1   8 use strict;
  1         2  
  1         47  
4 1     1   6 use warnings;
  1         2  
  1         453  
5              
6             sub render {
7 4     4 0 7 my ($changes) = @_;
8              
9 4 100       27 return '' unless @$changes;
10              
11 3         24 my @out;
12              
13 3         8 for my $c (@$changes) {
14 3         7 my $op = $c->{op};
15 3         7 my $path = $c->{path};
16              
17 3 100       11 if ($op eq 'change') {
    100          
    50          
18 1         7 push @out,
19             "Difference at $path",
20             " - $c->{from}",
21             " + $c->{to}",
22             "";
23             }
24             elsif ($op eq 'add') {
25 1         6 push @out,
26             "Added at $path",
27             " + $c->{value}",
28             "";
29             }
30             elsif ($op eq 'remove') {
31 1         5 push @out,
32             "Removed at $path",
33             " - $c->{from}",
34             "";
35             }
36             else {
37 0         0 push @out, "Unknown op '$op' at $path";
38             }
39             }
40              
41             # Prefix each line with '# ' so Test2::Diag displays it cleanly
42 3         8 return join("\n", map { "# $_" } @out) . "\n";
  10         46  
43             }
44              
45             1;