File Coverage

blib/lib/WebService/Shutterstock/Exception.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition 3 5 60.0
subroutine 7 7 100.0
pod 1 2 50.0
total 37 42 88.1


line stmt bran cond sub pod time code
1             package WebService::Shutterstock::Exception;
2             {
3             $WebService::Shutterstock::Exception::VERSION = '0.006';
4             }
5              
6             # ABSTRACT: Exception object to allow for easy error handling on HTTP errors
7              
8 11     11   64 use strict;
  11         73  
  11         389  
9 11     11   57 use warnings;
  11         21  
  11         276  
10              
11 11     11   54 use Moo;
  11         19  
  11         63  
12 11     11   3540 use overload q("") => \&to_string;
  11         24  
  11         138  
13              
14              
15             has request => ( is => 'lazy', required => 0, handles => ['uri', 'method'] );
16             sub _build_request {
17 1     1   3579 my $self = shift;
18 1 50       17 return $self->response ? $self->response->request : undef;
19             }
20              
21              
22             has response => ( is => 'ro', required => 0, handles => ['code'] );
23              
24              
25             has error => ( is => 'ro', required => 1 );
26              
27              
28             has caller_info => ( is => 'ro', required => 1 );
29              
30              
31             sub BUILDARGS {
32 6     6 0 9708 my $class = shift;
33 6         57 my $args = $class->SUPER::BUILDARGS(@_);
34 6         70 my $level = 0;
35 6   66     38 while(!$args->{caller_info} || $args->{caller_info}->{package} =~ /^(Sub::Quote|WebService::Shutterstock)/){
36 6 50       78 my @info = caller($level++) or last;
37 6         94 $args->{caller_info} = { package => $info[0], file => $info[1], line => $info[2] };
38             }
39 6   50     29 $args->{caller_info} ||= { package => 'N/A', file => 'N/A', line => -1 };
40 6         150 return $args;
41             }
42              
43              
44             sub to_string {
45 6     6 1 3850 my $self = shift;
46 6         89 return sprintf("%s at %s line %s.\n", $self->error, $self->caller_info->{file}, $self->caller_info->{line});
47             }
48              
49             1;
50              
51             __END__