File Coverage

blib/lib/Enbld/Exception.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 33 37 89.1


line stmt bran cond sub pod time code
1             package Enbld::Exception;
2              
3 25     25   748 use strict;
  25         35  
  25         952  
4 25     25   107 use warnings;
  25         34  
  25         704  
5              
6 25     25   101 use Carp;
  25         31  
  25         1852  
7              
8             use overload (
9 25         228 q{""} => \&to_string,
10             fallback => 1,
11 25     25   135 );
  25         43  
12              
13             sub throw {
14 32     32 0 610 my ( $class, $message, $param ) = @_;
15              
16 32         89 die $class->new( $message, $param );
17             }
18              
19             sub new {
20 79     79 0 1228 my ( $class, $message, $param ) = @_;
21              
22 79         170 chomp( $message );
23              
24 79 100       170 if ( $param ) { $message .= "\n" . $param . "\n" };
  25         59  
25              
26 79 50       1461 my $location = $ENV{HARNESS_ACTIVE} ? Carp::longmess() : Carp::shortmess();
27              
28 79         63444 my $self = {
29             message => $message,
30             caller_location => $location,
31             };
32              
33 79         791 return bless $self, $class;
34             }
35              
36             sub to_string {
37 79     79 0 5663 my $self = shift;
38              
39 79         625 return "ABORT:$self->{message}$self->{caller_location}";
40             }
41              
42             1;