blib/lib/Catmandu/Error.pm

filter: Statementstmt 99.4% 168 / 169 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 39 / 39 Podpod 0.0% 0 / 5 totaltotal 96.3% 213 / 221 CC 5 SCAR 2.1
CC
5
Cov
98%
log_message
3.1
BUILD
2.0
_headers_to_string
2.0
CRAP 1.2
« blib/lib/Catmandu/Fix/add_to_store.pm ↑ Summary blib/lib/Catmandu/Fix/retain.pm »
1 package Catmandu::Error;
2  
3 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 145 our $VERSION = '1.0201_02';
6  
7 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 145 extends 'Throwable::Error';
11  
12 145 with 'Catmandu::Logger';
13  
14 2 ▶has message => (is => 'ro', default => sub {""},);
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 sub BUILD {
17 46 ▶ my ($self) = @_;
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
18 46 my $msg = $self->log_message;
19 46 ▶ if ($self->log->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log->is_debug) 7 39 46
20 7 $msg .= "\n\n" . $self->stack_trace->as_string;
21 }
22 46 $self->log->error($msg);
23 }
24  
25 sub log_message {
26 37 ▶ my ($self) = @_;
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
27 37 $self->message;
28 }
29  
30 package Catmandu::BadVal;
31  
32 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 145 our $VERSION = '1.0201_02';
35  
36 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 145 extends 'Catmandu::Error';
40  
41 package Catmandu::BadArg;
42  
43 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 145 our $VERSION = '1.0201_02';
46  
47 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 145 extends 'Catmandu::BadVal';
51  
52 package Catmandu::NotImplemented;
53  
54 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 145 our $VERSION = '1.0201_02';
57  
58 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 145 extends 'Catmandu::Error';
62  
63 package Catmandu::NoSuchPackage;
64  
65 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 145 our $VERSION = '1.0201_02';
68  
69 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 145 extends 'Catmandu::Error';
73  
74 145 has package_name => (is => 'ro');
75  
76 sub log_message {
77 5 ▶ my ($self) = @_;
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
78 5 my $msg = $self->message;
79 5 $msg .= "\nPackage name: " . $self->package_name;
80 5 $msg;
81 }
82  
83 package Catmandu::FixParseError;
84  
85 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 145 our $VERSION = '1.0201_02';
88  
89 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 145 extends 'Catmandu::Error';
93  
94 145 has source => (is => 'ro');
95  
96 package Catmandu::NoSuchFixPackage;
97  
98 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 145 our $VERSION = '1.0201_02';
101  
102 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 145 extends 'Catmandu::NoSuchPackage';
106  
107 145 has fix_name => (is => 'ro');
108 145 has source => (is => 'rw', writer => 'set_source');
109  
110 sub log_message {
111 3 ▶ my ($self) = @_;
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
112 3 my $msg = $self->message;
113 3 $msg .= "\nFix name: " . $self->fix_name;
114 3 $msg .= "\nPackage name: " . $self->package_name;
115 3 $msg;
116 }
117  
118 package Catmandu::BadFixArg;
119  
120 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 145 our $VERSION = '1.0201_02';
123  
124 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 145 extends 'Catmandu::BadArg';
128  
129 145 has package_name => (is => 'ro');
130 145 has fix_name => (is => 'ro');
131 145 has source => (is => 'rw', writer => 'set_source');
132  
133 package Catmandu::FixError;
134  
135 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 145 our $VERSION = '1.0201_02';
138  
139 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
140 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
141  
142 145 extends 'Catmandu::Error';
143  
144 145 has data => (is => 'ro');
145 145 has fix => (is => 'ro');
146  
147 package Catmandu::HTTPError;
148  
149 145 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 145 our $VERSION = '1.0201_02';
152  
153 145 ▶use Catmandu::Util qw(is_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
154 145 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
155 145 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
156  
157 145 extends 'Catmandu::Error';
158  
159 145 has code => (is => 'ro');
160 145 has url => (is => 'ro');
161 145 has method => (is => 'ro');
162 145 has request_headers => (is => 'ro');
163 145 has request_body => (is => 'ro');
164 145 has response_headers => (is => 'ro');
165 145 has response_body => (is => 'ro');
166  
167 sub log_message {
168 1 ▶ my ($self) = @_;
Subroutine log_message: called CC=3 SCAR=11.2
Pod undocumented
169 1 my $msg = $self->message;
170 1 $msg .= "\nURL: " . $self->url;
171 1 $msg .= "\nMethod: " . $self->method;
172 1 $msg .= "\nRequest headers: "
173 . $self->_headers_to_string($self->request_headers);
174 1 ▶ if (is_string($self->request_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_string($self->request_body)) 1 0 1
175 1 $msg .= "\nRequest body: \n" . $self->_indent($self->request_body);
176 }
177 1 $msg .= "\nResponse code: " . $self->code;
178 1 $msg .= "\nResponse headers: "
179 . $self->_headers_to_string($self->response_headers);
180 1 ▶ if (is_string($self->response_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_string($self->response_body)) 0 1 1
181 0 $msg .= "\nResponse body: \n" . $self->_indent($self->response_body);
182 }
183 1 $msg;
184 }
185  
186 sub _headers_to_string {
187 2 ▶ my ($self, $headers) = @_;
Subroutine _headers_to_string: called CC=2 SCAR=6.9
188 2 my $str = "";
189 2 ▶ for (my $i = 0; $i < @$headers; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$headers) 1 2 3
190 1 $str .= "\n\t" . $headers->[$i++] . ": " . $headers->[$i];
191 }
192 2 $str;
193 }
194  
195 sub _indent {
196 1 ▶ my ($self, $str) = @_;
Subroutine _indent: called CC=1 SCAR=0.0
197 1 $str =~ s/([^\r\n]+)/\t$1/g;
198 1 $str;
199 }
200  
201 145 1;
202  
203 __END__
204  
205 =pod
206  
207 =head1 NAME
208  
209 Catmandu::Error - Catmandu error hierarchy
210  
211 =head1 SYNOPSIS
212  
213 use Catmandu::Sane;
214  
215 sub be_naughty {
216 Catmandu::BadArg->throw("very naughty") if shift;
217 }
218  
219 try {
220 be_naughty(1);
221 } catch_case [
222 'Catmandu::BadArg' => sub {
223 say "sorry";
224 }
225 ];
226  
227 =head1 CURRRENT ERROR HIERARCHY
228 Throwable::Error
229 Catmandu::Error
230 Catmandu::BadVal
231 Catmandu::BadArg
232 Catmandu::BadFixArg
233 Catmandu::NotImplemented
234 Catmandu::NoSuchPackage
235 Catmandu::NoSuchFixPackage
236 Catmandu::FixParseError
237 Catmandu::FixError
238 Catmandu::HTTPError
239  
240 =head1 SEE ALSO
241  
242 L<Throwable>
243  
244 =cut
« blib/lib/Catmandu/Fix/add_to_store.pm ↑ Summary blib/lib/Catmandu/Fix/retain.pm »