line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CallBackery::Exception; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
CallBackery::Exception - a simple exception class |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use CallBackery::Exception qw(mkerror); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
eval { die error(22,'Bad Error'); } |
12
|
|
|
|
|
|
|
if ($@){ |
13
|
|
|
|
|
|
|
print "Code: '.$@->code()." Message: ".$@->message()."\n" |
14
|
|
|
|
|
|
|
print "$@\n"; #stringified error |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
An error object. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Maybe use L instead. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
28
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
31
|
1
|
|
|
1
|
|
6
|
use vars qw(@EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
32
|
|
|
|
|
|
|
@EXPORT_OK = qw(mkerror); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
7
|
use overload ('""' => 'stringify'); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
113
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
38
|
|
|
|
|
|
|
has 'code'; |
39
|
|
|
|
|
|
|
has 'message'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B(I,I) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Create an nq::Exception object, setting code and message properties in the process. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub mkerror { |
50
|
0
|
|
|
0
|
1
|
|
my $code = shift; |
51
|
0
|
|
|
|
|
|
my $message = shift; |
52
|
|
|
|
|
|
|
# use caller() to determin where this is happening |
53
|
|
|
|
|
|
|
# somehow construct the error code from the line number ....?? |
54
|
0
|
|
|
|
|
|
return (__PACKAGE__->new(code=>$code,message=>$message)); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item B |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
error stringification handler |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub stringify { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
return "ERROR ".$self->code().": ".$self->message()."\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
__END__ |