File Coverage

lib/Data/Processor/Error/Instance.pm
Criterion Covered Total %
statement 29 29 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 0 2 0.0
total 37 41 90.2


line stmt bran cond sub pod time code
1 19     19   259 use 5.10.1;
  19         65  
2 19     19   160 use strict;
  19         50  
  19         557  
3 19     19   99 use warnings;
  19         28  
  19         1082  
4             package Data::Processor::Error::Instance;
5              
6             # An error.
7             # Always use throug Error::Collection to get correct caller info
8              
9 19     19   23791 use overload ('""' => \&stringify);
  19         19194  
  19         192  
10              
11             sub new {
12 39     39 0 102 my $class = shift;
13 39         102 my $self = { @_ };
14 39         131 my %keys = ( map { $_ => 1 } keys %$self );
  78         207  
15 39         104 for (qw (message path)){
16 78         131 delete $keys{$_};
17 78   50     184 $self->{$_} // die "$_ missing";
18             }
19 39 50       148 die "Unknown keys ". join (",",keys %keys) if keys %keys;
20              
21             # keeping the array and store the message at its location
22 39         84 $self->{path_array} = $self->{path};
23 39         80 $self->{path} = join '->', @{$self->{path}};
  39         140  
24              
25              
26 39         298 my (undef, undef, $line) = caller(2);
27 39         188 my (undef, undef, undef, $sub) = caller(3);
28 39         177 $self->{caller} = "$sub line $line";
29              
30 39         70 bless ($self, $class);
31 39         107 return $self;
32             }
33              
34             sub stringify {
35 15     15 0 1362 my $self = shift;
36 15         504 return $self->{path}. ": " . $self->{message};
37             }
38              
39             1;