line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ryu::Exception; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
85813
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '3.002'; # VERSION |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Ryu::Exception - support for L-style failure information |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Ryu::Exception; |
16
|
|
|
|
|
|
|
my $exception = Ryu::Exception->new( |
17
|
|
|
|
|
|
|
type => 'http', |
18
|
|
|
|
|
|
|
message => '404 response' |
19
|
|
|
|
|
|
|
details => [ $response, $request ] |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
Future->fail($exception->failure); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Generic exceptions interface, implements the 3-part failure codes as described in L. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
701
|
use Future; |
|
1
|
|
|
|
|
12518
|
|
|
1
|
|
|
|
|
32
|
|
30
|
1
|
|
|
1
|
|
13
|
use Scalar::Util; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
313
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 new |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Instantiate from named parameters. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
3
|
1
|
4935
|
sub new { bless { @_[1..$#_] }, $_[0] } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 throw |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Throws this exception. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$exception->throw; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
1
|
0
|
sub throw { die shift } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 type |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Returns the type, which should be a string such as C. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
5
|
1
|
753
|
sub type { shift->{type} } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 message |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns the message, which is a freeform string. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
5
|
1
|
3424
|
sub message { shift->{message} } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 details |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns the list of details, the specifics of which are specific to the type. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
4
|
50
|
|
4
|
1
|
758
|
sub details { @{ shift->{details} || [] } } |
|
4
|
|
|
|
|
28
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 fail |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Fails the given L with this exception. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub fail { |
81
|
1
|
|
|
1
|
1
|
607
|
my ($self, $f) = @_; |
82
|
1
|
50
|
33
|
|
|
15
|
die "expects a Future" unless Scalar::Util::blessed($f) && $f->isa('Future'); |
83
|
1
|
|
|
|
|
14
|
$self->as_future->on_ready($f); |
84
|
1
|
|
|
|
|
148
|
$f; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 as_future |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns a failed L containing the message, type and details from |
90
|
|
|
|
|
|
|
this exception. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub as_future { |
95
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
96
|
1
|
|
|
|
|
4
|
return Future->fail($self->message, $self->type, $self->details); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 from_future |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Extracts failure information from a L and instantiates accordingly. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub from_future { |
106
|
1
|
|
|
1
|
1
|
3
|
my ($class, $f) = @_; |
107
|
1
|
50
|
33
|
|
|
11
|
die "expects a Future" unless Scalar::Util::blessed($f) && $f->isa('Future'); |
108
|
1
|
50
|
|
|
|
5
|
die "Future is not ready" unless $f->is_ready; |
109
|
1
|
50
|
|
|
|
8
|
my ($msg, $type, @details) = $f->failure or die "Future is not failed?"; |
110
|
1
|
|
|
|
|
18
|
$class->new( |
111
|
|
|
|
|
|
|
message => $msg, |
112
|
|
|
|
|
|
|
type => $type, |
113
|
|
|
|
|
|
|
details => \@details |
114
|
|
|
|
|
|
|
) |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |