File Coverage

blib/lib/Data/Hash/Diff/Smart/Renderer/Text.pm
Criterion Covered Total %
statement 17 18 94.4
branch 7 8 87.5
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 27 30 90.0


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