File Coverage

lib/REST/Cypher/Exception/Response.pm
Criterion Covered Total %
statement 7 8 87.5
branch 1 2 50.0
condition n/a
subroutine 3 4 75.0
pod 2 2 100.0
total 13 16 81.2


line stmt bran cond sub pod time code
1             package REST::Cypher::Exception::Response;
2             {
3             $REST::Cypher::Exception::Response::DIST = 'REST-Cypher';
4             }
5             # ABSTRACT handle REST API response exceptions
6             $REST::Cypher::Exception::Response::VERSION = '0.0.4';
7 3     3   16 use Moo;
  3         6  
  3         28  
8             extends 'REST::Cypher::Exception';
9              
10             has response => ( is => 'ro', required => 1 );
11              
12             has error => ( is => 'ro', required => 1, lazy => 1, builder => '_build_error' );
13              
14             sub message {
15             # TODO return something more helpful (to our end user)
16 0     0 1 0 return $_[0]->error->{message};
17             }
18              
19              
20             sub BUILD {
21 2     2 1 14201 my $self = shift;
22              
23             # force ->error to be built
24 2 50       46 warn "failed a lazy build"
25             unless $self->error;
26             }
27              
28             sub _build_error {
29 2     2   823 my $self = shift;
30             $self->{error} = {
31 2         20 code => $self->response->code,
32             message => $self->response->message,
33             as_string => $self->response->as_string,
34             };
35             }
36              
37             1;
38              
39             __END__
40              
41             =pod
42              
43             =encoding UTF-8
44              
45             =head1 NAME
46              
47             REST::Cypher::Exception::Response
48              
49             =head1 VERSION
50              
51             version 0.0.4
52              
53             =head1 CLASS ATTRIBUTES
54              
55             =head2 response
56              
57             Used to store the failed response.
58              
59             =head2 error
60              
61             Used to store the formatted data structure of error information from the
62             failed response.
63              
64             =head1 METHODS
65              
66             =head2 message
67              
68             The value to return if we get strigified.
69              
70             =head1 PRIVATE METHODS
71              
72             =head2 BUILD
73              
74             Make really certain that we have instantiated the C<error> attribute.
75              
76             =head1 AUTHOR
77              
78             Chisel <chisel@chizography.net>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is copyright (c) 2015 by Chisel Wright.
83              
84             This is free software; you can redistribute it and/or modify it under
85             the same terms as the Perl 5 programming language system itself.
86              
87             =cut