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   230 use 5.10.1;
  19         77  
2 19     19   90 use strict;
  19         35  
  19         420  
3 19     19   92 use warnings;
  19         36  
  19         940  
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   21761 use overload ('""' => \&stringify);
  19         18022  
  19         215  
10              
11             sub new {
12 39     39 0 75 my $class = shift;
13 39         109 my $self = { @_ };
14 39         169 my %keys = ( map { $_ => 1 } keys %$self );
  78         205  
15 39         104 for (qw (message path)){
16 78         127 delete $keys{$_};
17 78   50     190 $self->{$_} // die "$_ missing";
18             }
19 39 50       115 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         49 $self->{path} = join '->', @{$self->{path}};
  39         119  
24              
25              
26 39         243 my (undef, undef, $line) = caller(2);
27 39         188 my (undef, undef, undef, $sub) = caller(3);
28 39         163 $self->{caller} = "$sub line $line";
29              
30 39         77 bless ($self, $class);
31 39         105 return $self;
32             }
33              
34             sub stringify {
35 15     15 0 1369 my $self = shift;
36 15         562 return $self->{path}. ": " . $self->{message};
37             }
38              
39             1;