File Coverage

blib/lib/Error/Pure/ErrorList.pm
Criterion Covered Total %
statement 30 31 96.7
branch 4 4 100.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 1 1 100.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Error::Pure::ErrorList;
2              
3 5     5   272909 use base qw(Exporter);
  5         12  
  5         798  
4 5     5   46 use strict;
  5         8  
  5         151  
5 5     5   25 use warnings;
  5         9  
  5         324  
6              
7 5     5   2672 use Error::Pure::Utils qw(err_helper);
  5         20  
  5         157  
8 5     5   4373 use Error::Pure::Output::Text qw(err_line_all);
  5         9104  
  5         162  
9 5     5   518 use List::Util qw(none);
  5         10  
  5         613  
10 5     5   28 use Readonly;
  5         9  
  5         1559  
11              
12             # Constants.
13             Readonly::Array our @EXPORT_OK => qw(err);
14             Readonly::Scalar my $EVAL => 'eval {...}';
15              
16             our $VERSION = 0.34;
17              
18             # Process error.
19             sub err {
20 7     7 1 657669 my @msg = @_;
21              
22             # Get errors structure.
23 7         38 my @errors = err_helper(@msg);
24              
25             # Finalize in main on last err.
26 7         21 my $stack_ar = $errors[-1]->{'stack'};
27 7 100 66     51 if ($stack_ar->[-1]->{'class'} eq 'main'
28 12 100   12   74 && none { $_ eq $EVAL || $_ =~ /^eval '/ms }
29 12         53 map { $_->{'sub'} } @{$stack_ar}) {
  7         20  
30              
31 2         22 die err_line_all(@errors);
32              
33             # Die for eval.
34             } else {
35 5         53 die "$errors[-1]->{'msg'}->[0]\n";
36             }
37              
38 0           return;
39             }
40              
41             1;
42              
43             __END__