File Coverage

lib/REST/Cypher/Exception.pm
Criterion Covered Total %
statement 19 22 86.3
branch 1 2 50.0
condition n/a
subroutine 7 9 77.7
pod 1 3 33.3
total 28 36 77.7


line stmt bran cond sub pod time code
1             package REST::Cypher::Exception {
2             $REST::Cypher::Exception::VERSION = '0.0.3';
3 3     3   36677 use strict;
  3         6  
  3         78  
4 3     3   15 use warnings;
  3         7  
  3         79  
5              
6 3     3   3632 use Moo;
  3         28135  
  3         24  
7             with 'Throwable';
8              
9             use overload
10 3         35 q{""} => 'as_string',
11 3     3   5702 fallback => 1;
  3         5  
12              
13             sub as_string {
14 0     0 1 0 my ($self) = @_;
15 0         0 return $self->message;
16             }
17             }
18              
19             package REST::Cypher::Exception::Response {
20 3     3   420 use Moo;
  3         5  
  3         16  
21             extends 'REST::Cypher::Exception';
22              
23             has response => ( is => 'ro', required => 1 );
24             has error => ( is => 'ro', required => 1, lazy => 1, builder => '_build_error' );
25              
26             sub BUILD {
27 2     2 0 7073 my $self = shift;
28              
29             # force ->error to be built
30 2 50       45 warn "failed a lazy build"
31             unless $self->error;
32             }
33              
34             sub _build_error {
35 2     2   825 my $self = shift;
36             $self->{error} = {
37 2         21 code => $self->response->code,
38             message => $self->response->message,
39             as_string => $self->response->as_string,
40             };
41             }
42              
43             sub message {
44 0     0 0   return $_[0]->error->{message};
45             }
46             }
47              
48             1;
49             {
50             $REST::Cypher::Exception::DIST = 'REST-Cypher';
51             }
52              
53             __END__
54              
55             =pod
56              
57             =encoding UTF-8
58              
59             =head1 NAME
60              
61             REST::Cypher::Exception
62              
63             =head1 VERSION
64              
65             version 0.0.3
66              
67             =head2 as_string
68              
69             This method in L<REST::Cypher::Exception> allows easy stringification of
70             thrown exceptions.
71              
72             It returns the current value of I<message>.
73              
74             =head1 AUTHOR
75              
76             Chisel <chisel@chizography.net>
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This software is copyright (c) 2015 by Chisel Wright.
81              
82             This is free software; you can redistribute it and/or modify it under
83             the same terms as the Perl 5 programming language system itself.
84              
85             =cut