Skip to content

Commit e77a3c8

Browse files
authored
Merge pull request #6 from iamalnewkirk/release-202
Release v2.02
2 parents 669b9b8 + 48ff640 commit e77a3c8

File tree

8 files changed

+206
-14
lines changed

8 files changed

+206
-14
lines changed

CHANGES

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog for Data-Object-Exception
22

3-
2.01 2020-02-17T05:23:10
3+
2.02 2020-03-14T23:15:07
4+
- Added release updates
5+
- Support setting all attributes using "throw"
6+
- Document attributes
7+
8+
2.01 2020-02-17T05:23:11
9+
- Built release version 2.01
410
- Added release updates
511
- Re-releasing to the CPAN
612

Makefile.PL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ my %WriteMakefileArgs = (
2929
"strict" => 0,
3030
"warnings" => 0
3131
},
32-
"VERSION" => "2.01",
32+
"VERSION" => "2.02",
3333
"test" => {
3434
"TESTS" => "t/*.t"
3535
}

README

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ SCENARIOS
4343

4444
The package allows objects to be instantiated with key-value arguments.
4545

46+
ATTRIBUTES
47+
48+
This package has the following attributes:
49+
50+
context
51+
52+
context(Any)
53+
54+
This attribute is read-only, accepts (Any) values, and is optional.
55+
56+
id
57+
58+
id(Str)
59+
60+
This attribute is read-only, accepts (Str) values, and is optional.
61+
62+
message
63+
64+
message(Str)
65+
66+
This attribute is read-only, accepts (Str) values, and is optional.
67+
4668
METHODS
4769

4870
This package implements the following methods:
@@ -63,18 +85,34 @@ METHODS
6385

6486
throw
6587

66-
throw(Str $class, Any $context, Maybe[Number] $offset) : Any
88+
throw(Tuple[Str, Str] | Str $message, Any $context, Maybe[Number] $offset) : Any
6789

68-
The throw method throws an error with message.
90+
The throw method throws an error with message (and optionally, an ID).
6991

7092
throw example #1
7193

7294
use Data::Object::Exception;
7395

96+
my $exception = Data::Object::Exception->new;
97+
98+
$exception->throw('Oops!')
99+
100+
throw example #2
101+
102+
use Data::Object::Exception;
103+
74104
my $exception = Data::Object::Exception->new('Oops!');
75105

76106
$exception->throw
77107

108+
throw example #3
109+
110+
use Data::Object::Exception;
111+
112+
my $exception = Data::Object::Exception->new;
113+
114+
$exception->throw(['E001', 'Oops!'])
115+
78116
trace
79117

80118
trace(Int $offset, $Int $limit) : Object

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ The package allows objects to be instantiated with a single argument.
4343

4444
The package allows objects to be instantiated with key-value arguments.
4545

46+
# ATTRIBUTES
47+
48+
This package has the following attributes:
49+
50+
## context
51+
52+
context(Any)
53+
54+
This attribute is read-only, accepts `(Any)` values, and is optional.
55+
56+
## id
57+
58+
id(Str)
59+
60+
This attribute is read-only, accepts `(Str)` values, and is optional.
61+
62+
## message
63+
64+
message(Str)
65+
66+
This attribute is read-only, accepts `(Str)` values, and is optional.
67+
4668
# METHODS
4769

4870
This package implements the following methods:
@@ -63,18 +85,34 @@ The explain method returns an error message with stack trace.
6385

6486
## throw
6587

66-
throw(Str $class, Any $context, Maybe[Number] $offset) : Any
88+
throw(Tuple[Str, Str] | Str $message, Any $context, Maybe[Number] $offset) : Any
6789

68-
The throw method throws an error with message.
90+
The throw method throws an error with message (and optionally, an ID).
6991

7092
- throw example #1
7193

7294
use Data::Object::Exception;
7395

96+
my $exception = Data::Object::Exception->new;
97+
98+
$exception->throw('Oops!')
99+
100+
- throw example #2
101+
102+
use Data::Object::Exception;
103+
74104
my $exception = Data::Object::Exception->new('Oops!');
75105

76106
$exception->throw
77107

108+
- throw example #3
109+
110+
use Data::Object::Exception;
111+
112+
my $exception = Data::Object::Exception->new;
113+
114+
$exception->throw(['E001', 'Oops!'])
115+
78116
## trace
79117

80118
trace(Int $offset, $Int $limit) : Object

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.01
1+
2.02

lib/Data/Object/Exception.pm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ fun BUILDARGS($class, @args) {
6464
# FUNCTIONS
6565

6666
fun throw($self, $message, $context, $offset) {
67-
my $class = ref $self || $self;
68-
6967
my $id;
70-
my $frames;
68+
69+
my $class = ref $self || $self;
7170

7271
my $args = {};
7372

73+
if (ref $message eq 'ARRAY') {
74+
($id, $message) = @$message;
75+
}
76+
7477
if (ref $self) {
7578
for my $name (keys %$self) {
7679
$args->{$name} = $self->{$name};
7780
}
7881
}
7982

83+
$args->{id} = $id if $id;
8084
$args->{message} = $message if $message;
8185
$args->{context} = $context if $context;
8286

lib/Data/Object/Exception.pod

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ The package allows objects to be instantiated with key-value arguments.
6060

6161
=cut
6262

63+
=head1 ATTRIBUTES
64+
65+
This package has the following attributes:
66+
67+
=cut
68+
69+
=head2 context
70+
71+
context(Any)
72+
73+
This attribute is read-only, accepts C<(Any)> values, and is optional.
74+
75+
=cut
76+
77+
=head2 id
78+
79+
id(Str)
80+
81+
This attribute is read-only, accepts C<(Str)> values, and is optional.
82+
83+
=cut
84+
85+
=head2 message
86+
87+
message(Str)
88+
89+
This attribute is read-only, accepts C<(Str)> values, and is optional.
90+
91+
=cut
92+
6393
=head1 METHODS
6494

6595
This package implements the following methods:
@@ -88,22 +118,46 @@ The explain method returns an error message with stack trace.
88118

89119
=head2 throw
90120

91-
throw(Str $class, Any $context, Maybe[Number] $offset) : Any
121+
throw(Tuple[Str, Str] | Str $message, Any $context, Maybe[Number] $offset) : Any
92122

93-
The throw method throws an error with message.
123+
The throw method throws an error with message (and optionally, an ID).
94124

95125
=over 4
96126

97127
=item throw example #1
98128

99129
use Data::Object::Exception;
100130

131+
my $exception = Data::Object::Exception->new;
132+
133+
$exception->throw('Oops!')
134+
135+
=back
136+
137+
=over 4
138+
139+
=item throw example #2
140+
141+
use Data::Object::Exception;
142+
101143
my $exception = Data::Object::Exception->new('Oops!');
102144

103145
$exception->throw
104146

105147
=back
106148

149+
=over 4
150+
151+
=item throw example #3
152+
153+
use Data::Object::Exception;
154+
155+
my $exception = Data::Object::Exception->new;
156+
157+
$exception->throw(['E001', 'Oops!'])
158+
159+
=back
160+
107161
=cut
108162

109163
=head2 trace

t/Data_Object_Exception.t

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ method: trace
2727
2828
=cut
2929

30+
=attributes
31+
32+
id: ro, opt, Str
33+
context: ro, opt, Any
34+
message: ro, opt, Str
35+
36+
=cut
37+
3038
=synopsis
3139
3240
use Data::Object::Exception;
@@ -74,20 +82,36 @@ The package allows objects to be instantiated with key-value arguments.
7482

7583
=method throw
7684
77-
The throw method throws an error with message.
85+
The throw method throws an error with message (and optionally, an ID).
7886
7987
=signature throw
8088
81-
throw(Str $class, Any $context, Maybe[Number] $offset) : Any
89+
throw(Tuple[Str, Str] | Str $message, Any $context, Maybe[Number] $offset) : Any
8290
8391
=example-1 throw
8492
8593
use Data::Object::Exception;
8694
95+
my $exception = Data::Object::Exception->new;
96+
97+
$exception->throw('Oops!')
98+
99+
=example-2 throw
100+
101+
use Data::Object::Exception;
102+
87103
my $exception = Data::Object::Exception->new('Oops!');
88104
89105
$exception->throw
90106
107+
=example-3 throw
108+
109+
use Data::Object::Exception;
110+
111+
my $exception = Data::Object::Exception->new;
112+
113+
$exception->throw(['E001', 'Oops!'])
114+
91115
=cut
92116

93117
=method explain
@@ -196,6 +220,34 @@ $subs->example(-1, 'throw', 'method', fun($tryable) {
196220
$result
197221
});
198222

223+
$subs->example(-2, 'throw', 'method', fun($tryable) {
224+
$tryable->default(fun($caught) {
225+
$caught
226+
});
227+
ok my $result = $tryable->result;
228+
ok $result->isa('Data::Object::Exception');
229+
ok !length $result->id;
230+
ok !length $result->context;
231+
ok length $result->frames;
232+
is $result->message, 'Oops!';
233+
234+
$result
235+
});
236+
237+
$subs->example(-3, 'throw', 'method', fun($tryable) {
238+
$tryable->default(fun($caught) {
239+
$caught
240+
});
241+
ok my $result = $tryable->result;
242+
ok $result->isa('Data::Object::Exception');
243+
is $result->id, 'E001';
244+
ok !length $result->context;
245+
ok length $result->frames;
246+
is $result->message, 'Oops!';
247+
248+
$result
249+
});
250+
199251
$subs->example(-1, 'explain', 'method', fun($tryable) {
200252
ok my $result = $tryable->result;
201253

0 commit comments

Comments
 (0)