File Coverage

lib/Data/Processor/Transformer.pm
Criterion Covered Total %
statement 27 27 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 2 0.0
total 38 43 88.3


line stmt bran cond sub pod time code
1 19     19   233 use 5.10.1;
  19         60  
2 19     19   96 use strict;
  19         32  
  19         404  
3 19     19   87 use warnings;
  19         29  
  19         4952  
4             package Data::Processor::Transformer;
5              
6             # XXX document this with pod. (if standalone)
7              
8             sub new {
9 194     194 0 362 my $class = shift;
10              
11 194         290 my $self = {};
12 194         294 bless ($self, $class);
13 194         1238 return $self;
14             }
15              
16             sub transform {
17 274     274 0 341 my $self = shift;
18 274         327 my $key = shift;
19 274         330 my $schema_key = shift;
20 274         305 my $section = shift;
21 274 100       613 if (exists $section->{schema}{$schema_key}{transformer}){
22 7         9 my $return_value;
23 7         13 eval {
24 7         24 local $SIG{__DIE__};
25             $return_value =
26 7         24 $section->{schema}{$schema_key}{transformer}($section->{data}{$key},$section->{data});
27             };
28 7 100       83 if (my $err = $@) {
29 2 50 33     22 if (ref $err eq 'HASH' && defined $err->{msg}){
30 2         6 $err = $err->{msg};
31             }
32 2         11 return "error transforming '$key': $err";
33             }
34 5         10 $section->{data}{$key} = $return_value;
35             }
36 272         521 return undef;
37             }
38              
39             1