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   193 use 5.10.1;
  19         68  
2 19     19   98 use strict;
  19         34  
  19         441  
3 19     19   96 use warnings;
  19         30  
  19         907  
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   19014 use overload ('""' => \&stringify);
  19         16498  
  19         153  
10              
11             sub new {
12 40     40 0 55 my $class = shift;
13 40         102 my $self = { @_ };
14 40         106 my %keys = ( map { $_ => 1 } keys %$self );
  80         161  
15 40         80 for (qw (message path)){
16 80         116 delete $keys{$_};
17 80   50     173 $self->{$_} // die "$_ missing";
18             }
19 40 50       83 die "Unknown keys ". join (",",keys %keys) if keys %keys;
20              
21             # keeping the array and store the message at its location
22 40         64 $self->{path_array} = $self->{path};
23 40         43 $self->{path} = join '->', @{$self->{path}};
  40         100  
24              
25              
26 40         227 my (undef, undef, $line) = caller(2);
27 40         161 my (undef, undef, undef, $sub) = caller(3);
28 40         113 $self->{caller} = "$sub line $line";
29              
30 40         57 bless ($self, $class);
31 40         87 return $self;
32             }
33              
34             sub stringify {
35 15     15 0 1149 my $self = shift;
36 15         475 return $self->{path}. ": " . $self->{message};
37             }
38              
39             1;