line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Object::Role::Errable; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33119
|
use 5.014; |
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
10
|
use registry 'Data::Object::Types'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
232328
|
use routines; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
2354
|
use Data::Object::Role; |
|
1
|
|
|
|
|
11231
|
|
|
1
|
|
|
|
|
14
|
|
12
|
1
|
|
|
1
|
|
1027
|
use Data::Object::RoleHas; |
|
1
|
|
|
|
|
10795
|
|
|
1
|
|
|
|
|
11
|
|
13
|
1
|
|
|
1
|
|
597
|
use Data::Object::Exception; |
|
1
|
|
|
|
|
4866
|
|
|
1
|
|
|
|
|
130
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Data::Object::Role::Tryable'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ATTRIBUTES |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'error' => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
isa => 'ExceptionObject | HashRef | Str', |
24
|
|
|
|
|
|
|
opt => 1, |
25
|
|
|
|
|
|
|
tgr => method($value) { |
26
|
|
|
|
|
|
|
$value = { message => $value } if !ref $value; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
die $self->{error} = Data::Object::Exception->new( |
29
|
|
|
|
|
|
|
%$value, context => $self |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
clr => 'error_reset' |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Data::Object::Role::Errable |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 ABSTRACT |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Errable Role for Perl 5 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package Example; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Moo; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
with 'Data::Object::Role::Errable'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package main; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $example = Example->new; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# $example->error('Oops!') |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This package provides a mechanism for handling errors (exceptions). It's a more |
72
|
|
|
|
|
|
|
structured approach to being L<"throwable"|Data::Object::Role::Throwable>. The |
73
|
|
|
|
|
|
|
idea is that any object that consumes this role can set an error which |
74
|
|
|
|
|
|
|
automatically throws an exception which if trapped includes the state (object |
75
|
|
|
|
|
|
|
as thrown) in the exception context. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 INTEGRATES |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This package integrates behaviors from: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<Data::Object::Role::Tryable> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 LIBRARIES |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This package uses type constraints from: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L<Data::Object::Types> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This package has the following attributes: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 error |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
error(ExceptionObject) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This attribute is read-write, accepts C<(ExceptionObject)> values, and is optional. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This package implements the following methods: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 error |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
error(ExceptionObject $exception | HashRef $options | Str $message) : ExceptionObject |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The error method takes an error message (string) or hashref of exception object |
120
|
|
|
|
|
|
|
constructor attributes and throws an L<"exception"|Data::Object::Exception>. If |
121
|
|
|
|
|
|
|
the exception is trapped the exception object will contain the object as the |
122
|
|
|
|
|
|
|
exception context. The original object will also have the exception set as the |
123
|
|
|
|
|
|
|
error attribute. The error attribute can be cleared using the C<error_reset> |
124
|
|
|
|
|
|
|
method. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item error example #1 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
package main; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $example = Example->new; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$example->error('Oops!'); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# throws exception |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 4 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item error example #2 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
package main; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $example = Example->new; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$example->error({ message => 'Oops!'}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# throws exception |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over 4 |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item error example #3 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
package main; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $example = Example->new; |
161
|
|
|
|
|
|
|
my $exception = Data::Object::Exception->new('Oops!'); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$example->error($exception); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# throws exception |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 error_reset |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
error_reset() : Any |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The error_reset method clears any exception object set on the object. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item error_reset example #1 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
package main; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $example = Example->new; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
eval { $example->error('Oops!') }; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$example->error_reset |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Al Newkirk, C<awncorp@cpan.org> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 LICENSE |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Copyright (C) 2011-2019, Al Newkirk, et al. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the terms |
202
|
|
|
|
|
|
|
of the The Apache License, Version 2.0, as elucidated in the L<"license |
203
|
|
|
|
|
|
|
file"|https://github.com/iamalnewkirk/data-object-role-errable/blob/master/LICENSE>. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 PROJECT |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L<Wiki|https://github.com/iamalnewkirk/data-object-role-errable/wiki> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L<Project|https://github.com/iamalnewkirk/data-object-role-errable> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L<Initiatives|https://github.com/iamalnewkirk/data-object-role-errable/projects> |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L<Milestones|https://github.com/iamalnewkirk/data-object-role-errable/milestones> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L<Contributing|https://github.com/iamalnewkirk/data-object-role-errable/blob/master/CONTRIBUTE.md> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L<Issues|https://github.com/iamalnewkirk/data-object-role-errable/issues> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |