line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Role::Throwable; |
2
|
|
|
|
|
|
|
|
3
|
87
|
|
|
87
|
|
1495
|
use 5.018; |
|
87
|
|
|
|
|
306
|
|
4
|
|
|
|
|
|
|
|
5
|
87
|
|
|
87
|
|
454
|
use strict; |
|
87
|
|
|
|
|
186
|
|
|
87
|
|
|
|
|
1698
|
|
6
|
87
|
|
|
87
|
|
404
|
use warnings; |
|
87
|
|
|
|
|
176
|
|
|
87
|
|
|
|
|
2430
|
|
7
|
|
|
|
|
|
|
|
8
|
87
|
|
|
87
|
|
507
|
use Venus::Role 'with'; |
|
87
|
|
|
|
|
199
|
|
|
87
|
|
|
|
|
606
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# METHODS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub throw { |
13
|
108
|
|
|
108
|
1
|
946
|
my ($self, $data, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
108
|
|
|
|
|
12221
|
require Venus::Throw; |
16
|
|
|
|
|
|
|
|
17
|
108
|
|
|
|
|
1587
|
my $throw = Venus::Throw->new(context => (caller(1))[3])->do( |
18
|
|
|
|
|
|
|
frame => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
108
|
100
|
|
|
|
534
|
if (!$data) { |
22
|
19
|
|
|
|
|
167
|
return $throw->do( |
23
|
|
|
|
|
|
|
'package', join('::', map ucfirst, ref($self), 'error') |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
89
|
100
|
|
|
|
410
|
if (ref $data ne 'HASH') { |
27
|
88
|
100
|
66
|
|
|
1120
|
if ($data =~ /^\w+$/ && $self->can($data)) { |
28
|
87
|
|
|
|
|
548
|
$data = $self->$data(@args); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
1
|
|
|
|
|
5
|
return $throw->do( |
32
|
|
|
|
|
|
|
'package', $data, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
88
|
50
|
|
|
|
432
|
if (exists $data->{as}) { |
38
|
0
|
|
|
|
|
0
|
$throw->as($data->{as}); |
39
|
|
|
|
|
|
|
} |
40
|
88
|
100
|
|
|
|
320
|
if (exists $data->{capture}) { |
41
|
2
|
|
|
|
|
3
|
$throw->capture(@{$data->{capture}}); |
|
2
|
|
|
|
|
11
|
|
42
|
|
|
|
|
|
|
} |
43
|
88
|
50
|
|
|
|
344
|
if (exists $data->{context}) { |
44
|
0
|
|
|
|
|
0
|
$throw->context($data->{context}); |
45
|
|
|
|
|
|
|
} |
46
|
88
|
50
|
|
|
|
345
|
if (exists $data->{error}) { |
47
|
0
|
|
|
|
|
0
|
$throw->error($data->{error}); |
48
|
|
|
|
|
|
|
} |
49
|
88
|
50
|
|
|
|
282
|
if (exists $data->{frame}) { |
50
|
0
|
|
|
|
|
0
|
$throw->frame($data->{frame}); |
51
|
|
|
|
|
|
|
} |
52
|
88
|
100
|
|
|
|
272
|
if (exists $data->{message}) { |
53
|
86
|
|
|
|
|
432
|
$throw->message($data->{message}); |
54
|
|
|
|
|
|
|
} |
55
|
88
|
50
|
|
|
|
443
|
if (exists $data->{name}) { |
56
|
88
|
|
|
|
|
444
|
$throw->name($data->{name}); |
57
|
|
|
|
|
|
|
} |
58
|
88
|
50
|
|
|
|
454
|
if (exists $data->{package}) { |
59
|
0
|
|
|
|
|
0
|
$throw->package($data->{package}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
88
|
|
|
|
|
962
|
$throw->package(join('::', map ucfirst, ref($self), 'error')); |
63
|
|
|
|
|
|
|
} |
64
|
88
|
50
|
|
|
|
510
|
if (exists $data->{parent}) { |
65
|
0
|
|
|
|
|
0
|
$throw->parent($data->{parent}); |
66
|
|
|
|
|
|
|
} |
67
|
88
|
100
|
|
|
|
359
|
if (exists $data->{stash}) { |
68
|
81
|
|
|
|
|
165
|
$throw->stash($_, $data->{stash}->{$_}) for keys %{$data->{stash}}; |
|
81
|
|
|
|
|
655
|
|
69
|
|
|
|
|
|
|
} |
70
|
88
|
50
|
|
|
|
367
|
if (exists $data->{on}) { |
71
|
0
|
|
|
|
|
0
|
$throw->on($data->{on}); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
88
|
|
|
|
|
758
|
return $throw; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# EXPORTS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub EXPORT { |
80
|
176
|
|
|
176
|
0
|
589
|
['throw'] |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Venus::Role::Throwable - Throwable Role |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 ABSTRACT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Throwable Role for Perl 5 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
package Example; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Venus::Class; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
with 'Venus::Role::Throwable'; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
package main; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $example = Example->new; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# $example->throw; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This package modifies the consuming package and provides a mechanism for |
118
|
|
|
|
|
|
|
throwing context-aware errors (exceptions). |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This package provides the following methods: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 throw |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
throw(Maybe[Str | HashRef] $data, Any @args) (Throw) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The throw method builds a L object, which can raise errors |
133
|
|
|
|
|
|
|
(exceptions). If passed a string representing a package name, the throw object |
134
|
|
|
|
|
|
|
will be configured to throw an exception using that package name. If passed a |
135
|
|
|
|
|
|
|
string representing a method name, the throw object will call that method |
136
|
|
|
|
|
|
|
expecting a hashref of L method names and arguments which will be |
137
|
|
|
|
|
|
|
called to configure the thrower. If passed a hashref, the keys and values are |
138
|
|
|
|
|
|
|
expected to be method names and arguments which will be called to configure the |
139
|
|
|
|
|
|
|
L object returned. If passed additional arguments, assuming they |
140
|
|
|
|
|
|
|
are preceeded by a string representing a method name, the additional arguments |
141
|
|
|
|
|
|
|
will be supplied to the method when called. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
I> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 4 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item throw example 1 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
package main; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $example = Example->new; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $throw = $example->throw; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# bless({ "package" => "Example::Error", ..., }, "Venus::Throw") |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# $throw->error; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over 4 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item throw example 2 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
package main; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $example = Example->new; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my $throw = $example->throw('Example::Error::Unknown'); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# bless({ "package" => "Example::Error::Unknown", ..., }, "Venus::Throw") |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# $throw->error; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item throw example 3 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
package main; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $example = Example->new; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $throw = $example->throw({ |
186
|
|
|
|
|
|
|
name => 'on.example', |
187
|
|
|
|
|
|
|
capture => [$example], |
188
|
|
|
|
|
|
|
stash => { |
189
|
|
|
|
|
|
|
time => time, |
190
|
|
|
|
|
|
|
}, |
191
|
|
|
|
|
|
|
}); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# bless({ "package" => "Example::Error", ..., }, "Venus::Throw") |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# $throw->error; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over 4 |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item throw example 4 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# given: synopsis |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
package Example; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# ... |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub error_on_example { |
210
|
|
|
|
|
|
|
my ($self) = @_; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
return { |
213
|
|
|
|
|
|
|
name => 'on.example', |
214
|
|
|
|
|
|
|
capture => [$example], |
215
|
|
|
|
|
|
|
stash => { |
216
|
|
|
|
|
|
|
time => time, |
217
|
|
|
|
|
|
|
}, |
218
|
|
|
|
|
|
|
}; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
package main; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
my $throw = $example->throw('error_on_example'); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# bless({ "package" => "Example::Error", ..., }, "Venus::Throw") |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# $throw->error; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=back |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 AUTHORS |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Awncorp, C |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 LICENSE |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
244
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |