line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lim::Error; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
42
|
use common::sense; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
44
|
|
4
|
7
|
|
|
7
|
|
313
|
use Carp; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
453
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
41
|
use Scalar::Util qw(blessed); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
8768
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=encoding utf8 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Lim::Error - Encapsulate an error within Lim |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
See L for version. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = $Lim::VERSION; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over 4 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Lim::Error; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$error = Lim::Error->new('This is a simple error'); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=back |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item $error = Lim::Error->new(key => value...) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Create a new Lim::Error object. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item code => 500 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Specify the error code, used in HTTP responses as well as RPC protocols. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item message => $message |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Specify the error message. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item module => $module |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Specify the module that created this error, if its a blessed object the L[() ] |
53
|
|
|
|
|
|
|
of that object will be used. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
61
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
62
|
0
|
|
|
|
|
|
my %args = ( @_ ); |
63
|
0
|
|
|
|
|
|
my $self = { |
64
|
|
|
|
|
|
|
code => 500, |
65
|
|
|
|
|
|
|
message => 'Generic Error', |
66
|
|
|
|
|
|
|
module => 'UNKNOWN' |
67
|
|
|
|
|
|
|
}; |
68
|
0
|
|
|
|
|
|
bless $self, $class; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (defined $args{code}) { |
71
|
0
|
0
|
0
|
|
|
|
unless ($args{code} >= 300 and $args{code} < 600) { |
72
|
0
|
|
|
|
|
|
confess __PACKAGE__, ': Invalid code [', $args{code}, '] given in error'; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
$self->{code} = $args{code}; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
$self->{message} = $args{message}; |
77
|
0
|
0
|
|
|
|
|
if (defined $args{module}) { |
78
|
0
|
0
|
|
|
|
|
if (blessed($args{module})) { |
79
|
0
|
|
|
|
|
|
$self->{module} = ref($args{module}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
|
$self->{module} = $args{module}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
|
|
sub DESTROY { |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item $error->set($hash_ref) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Populate an error object from a hash reference. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub set { |
99
|
0
|
0
|
|
0
|
1
|
|
if (ref($_[1]) eq 'HASH') { |
100
|
0
|
0
|
|
|
|
|
if (exists $_[1]->{'Lim::Error'}) { |
101
|
0
|
|
|
|
|
|
foreach (qw(code message module)) { |
102
|
0
|
0
|
|
|
|
|
if (exists $_[1]->{'Lim::Error'}->{$_}) { |
103
|
0
|
|
|
|
|
|
$_[0]->{$_} = $_[1]->{'Lim::Error'}->{$_}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$_[0]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $error->code |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Return the code of the error. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub code { |
119
|
0
|
|
|
0
|
1
|
|
$_[0]->{code}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item $error->set_code($code) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Set the error code to C<$code>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub set_code { |
129
|
0
|
|
|
0
|
1
|
|
$_[0]->{code} = $_[1]; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$_[0]; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item $error->message |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Return the message of the error. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub message { |
141
|
0
|
|
|
0
|
1
|
|
$_[0]->{message}; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item $error->set_message($message) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Set the error message to C<$message> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub set_message { |
151
|
0
|
|
|
0
|
1
|
|
$_[0]->{message} = $_[1]; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$_[0]; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item $error->module |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Return the module name of the error. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub module { |
163
|
0
|
|
|
0
|
1
|
|
$_[0]->{module}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item $error->set_module($module_name) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Set the module name of the error, this can not take blessed objects. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub set_module { |
173
|
0
|
|
|
0
|
1
|
|
$_[0]->{module} = $_[1]; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
$_[0]; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item $hash_ref = $error->TO_JSON |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns a hash reference describing the error, this is to support passing |
181
|
|
|
|
|
|
|
objects to L. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub TO_JSON { |
186
|
|
|
|
|
|
|
{ |
187
|
0
|
|
|
0
|
1
|
|
'Lim::Error' => { |
188
|
|
|
|
|
|
|
code => $_[0]->{code}, |
189
|
|
|
|
|
|
|
message => $_[0]->{message}, |
190
|
|
|
|
|
|
|
module => $_[0]->{module} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item $string = $error->toString |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns a string that describes the error. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub toString { |
202
|
0
|
|
|
0
|
1
|
|
'Module: ', $_[0]->{module}, ' Code: ', $_[0]->{code}, ' Message: ', $_[0]->{message}; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 AUTHOR |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Jerry Lundström, C<< >> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 BUGS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Please report any bugs or feature requests to L. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SUPPORT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
perldoc Lim::Error |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
You can also look for information at: |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over 4 |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * Lim issue tracker (report bugs here) |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=back |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Copyright 2012-2013 Jerry Lundström. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
238
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
239
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
1; # End of Lim::Error |