File Coverage

lib/WebService/Intercom/Exception.pm
Criterion Covered Total %
statement 72 84 85.7
branch n/a
condition 0 3 0.0
subroutine 7 8 87.5
pod n/a
total 79 95 83.1


line stmt bran cond sub pod time code
1 2     2   10 use Moops -strict;
  2         3  
  2         23  
2 2     2   3434 use Throwable ();
  2         2281  
  2         58  
3             # ABSTRACT: exception class for WebService::Intercom
4              
5             =pod
6              
7             =head1 NAME
8              
9             WebService::Intercom::Exception - represent a exception or error
10              
11             =head1 SYNOPSIS
12              
13             Not useful to create on its own.
14              
15             =head2 ATTRIBUTES
16              
17             =over
18              
19             =item message - the error message
20              
21             =item stack - stack trace of the error.
22              
23             =item code - the code of the error if any
24              
25             =item request_id - the request id of the error if available
26              
27             =back
28              
29             =cut
30              
31 2     2   179442 class WebService::Intercom::Exception with ::Throwable {
  2     2   62  
  2     2   15  
  2         7  
  2         152  
  2         1295  
  2         4830  
  2         52  
  2         4619  
  2         4  
  2         19  
  2         161  
  2         4  
  2         151  
  2         14  
  2         3  
  2         312  
  2         111  
  2         15  
  2         2  
  2         34  
  2         10693  
  2         5  
  2         21  
  2         2677  
  2         9262  
  2         16  
  2         412  
  2         4  
  2         25  
  2         1637  
  2         22021  
  2         30  
  2         2281  
  2         7565  
  2         16  
  2         3844  
  2         7719  
  2         25  
  2         236813  
  2         12  
  2         79  
  2         12  
  2         3  
  2         74  
  2         9  
  2         3  
  2         78  
  2         8  
  2         3  
  2         326  
  2         21  
  2         6120  
  2         39  
  2         641  
32 2     2   752 use Devel::StackTrace;
  2         3  
  2         890  
33            
34 2         104 my %CarpInternal = ("WebService::Intercom::Exception" => 1,
35             "Throwable" => 1);
36            
37 2         11 has 'code' => (is => 'ro', isa => Maybe[Str]);
38 2         5675 has 'request_id' => (is => 'ro', isa => Maybe[Str]);
39 2         1016 has 'message' => (is => 'ro', isa => 'Maybe[Str]', required => 1);
40             has 'stack' => (is => 'ro', default => sub {
41 0           my ($level, @caller, %ctxt) = 0;
42 0   0       while (
43             defined scalar caller($level) and $CarpInternal{scalar caller($level)}
44             ) {
45 0           $level++;
46             }
47 0           @ctxt{qw/ package file line /} = caller($level);
48            
49 0           my $stack = undef;
50            
51 0           $stack = "Devel::StackTrace"->new(
52             ignore_package => [ keys %CarpInternal]
53             );
54 0           return $stack;
55 2         29799 });
56            
57             use overload fallback => 1,
58             '""' => sub {
59 0     0   0 my $e = shift;
60 0         0 my $msg = "WebService::Intercom::Exception: @{[$e->message]}\n";
  0         0  
61 0         0 $msg .= "Stack: " . $e->stack . "\n";
62 0         0 return $msg;
63 2     2   12 };
  2         3  
  2         25  
64             }
65              
66            
67             1;
68