| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Venus::Role::Assertable; |
|
2
|
|
|
|
|
|
|
|
|
3
|
96
|
|
|
96
|
|
1701
|
use 5.018; |
|
|
96
|
|
|
|
|
361
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
96
|
|
|
96
|
|
649
|
use strict; |
|
|
96
|
|
|
|
|
206
|
|
|
|
96
|
|
|
|
|
2094
|
|
|
6
|
96
|
|
|
96
|
|
483
|
use warnings; |
|
|
96
|
|
|
|
|
232
|
|
|
|
96
|
|
|
|
|
2502
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
96
|
|
|
96
|
|
483
|
use Venus::Role 'fault'; |
|
|
96
|
|
|
|
|
226
|
|
|
|
96
|
|
|
|
|
647
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# METHODS |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub assert { |
|
13
|
51
|
|
|
51
|
1
|
181
|
my ($self, $data) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
51
|
|
|
|
|
235
|
return $self->assertion->result($data); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub assertion { |
|
19
|
47
|
|
|
47
|
1
|
95
|
my ($self) = @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
47
|
|
|
|
|
2631
|
require Venus::Assert; |
|
22
|
|
|
|
|
|
|
|
|
23
|
47
|
|
66
|
|
|
188
|
my $class = ref $self || $self; |
|
24
|
|
|
|
|
|
|
|
|
25
|
47
|
|
|
|
|
206
|
my $assert = Venus::Assert->new($class); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$assert->match('hashref')->format(sub{ |
|
28
|
0
|
|
|
0
|
|
0
|
$class->new($_) |
|
29
|
47
|
|
|
|
|
194
|
}); |
|
30
|
|
|
|
|
|
|
|
|
31
|
47
|
|
|
|
|
169
|
$assert->accept($class); |
|
32
|
|
|
|
|
|
|
|
|
33
|
47
|
|
|
|
|
124
|
return $assert; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub check { |
|
37
|
3
|
|
|
3
|
1
|
9
|
my ($self, $data) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
50
|
return $self->assertion->valid($data); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub coerce { |
|
43
|
0
|
|
|
0
|
1
|
0
|
my ($self, $data) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
return $self->assertion->coerce($data); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make { |
|
49
|
52
|
|
|
52
|
1
|
128
|
my ($self, $data) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
52
|
100
|
66
|
|
|
496
|
return UNIVERSAL::isa($data, ref $self || $self) |
|
52
|
|
|
|
|
|
|
? $data |
|
53
|
|
|
|
|
|
|
: $self->assert($data); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# EXPORTS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub EXPORT { |
|
59
|
109
|
|
|
109
|
0
|
464
|
['assert', 'assertion', 'check', 'coerce', 'make'] |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Venus::Role::Assertable - Assertable Role |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 ABSTRACT |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Assertable Role for Perl 5 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
package Example; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Venus::Class; |
|
83
|
|
|
|
|
|
|
use Venus::Assert; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
with 'Venus::Role::Assertable'; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub assertion { |
|
88
|
|
|
|
|
|
|
Venus::Assert->new('Example')->accept('Example') |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
package main; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $example = Example->new; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# $example->check; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This package modifies the consuming package and requires methods for making the |
|
102
|
|
|
|
|
|
|
object assertable. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 METHODS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This package provides the following methods: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 assert |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
assert(any $data) (any) |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The assert method returns the data provided if it passes the registered type |
|
117
|
|
|
|
|
|
|
constraints, or throws an exception. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
I> |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 4 |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item assert example 1 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# given: synopsis |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
package main; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $assert = $example->assert; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Exception! (isa Venus::Check::Error) |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item assert example 2 |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# given: synopsis |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
package main; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $assert = $example->assert({}); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Exception! (isa Venus::Check::Error) |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item assert example 3 |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# given: synopsis |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
package main; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $assert = $example->assert($example); |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# bless({}, "Example") |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 assertion |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
assertion() (Venus::Assert) |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The assertion method receives no arguments and should returns a |
|
170
|
|
|
|
|
|
|
L object. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
I> |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item assertion example 1 |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
package main; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $example = Example->new; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $assertion = $example->assertion; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# bless({name => "Example"}, "Venus::Assert") |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 check |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
check(any $data) (boolean) |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
The check method returns true if the data provided passes the registered type |
|
195
|
|
|
|
|
|
|
constraints, or returns false. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
I> |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over 4 |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item check example 1 |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# given: synopsis |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
package main; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my $check = $example->check; |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# 0 |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=back |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over 4 |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item check example 2 |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# given: synopsis |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
package main; |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $check = $example->check({}); |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# 0 |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=back |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over 4 |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item check example 3 |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# given: synopsis |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
package main; |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
my $check = $example->check($example); |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# 1 |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 coerce |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
coerce(any $data) (any) |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The coerce method returns a coerced value if the data provided matches any of |
|
248
|
|
|
|
|
|
|
the registered type coercions, or returns the data provided. |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
I> |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over 4 |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item coerce example 1 |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# given: synopsis |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
package main; |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my $assertion = $example->assertion; |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$assertion->match('string')->format(sub{ucfirst(lc($_))}); |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
my $coerce = $assertion->coerce; |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
# undef |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=back |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=over 4 |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item coerce example 2 |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# given: synopsis |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
package main; |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
my $assertion = $example->assertion; |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$assertion->match('string')->format(sub{ucfirst(lc($_))}); |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
my $coerce = $assertion->coerce({}); |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# {} |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=back |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=over 4 |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=item coerce example 3 |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# given: synopsis |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
package main; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
my $assertion = $example->assertion; |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
$assertion->match('string')->format(sub{ucfirst(lc($_))}); |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
my $coerce = $assertion->coerce('hello'); |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
# "Hello" |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=back |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head2 make |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
make(any $data) (object) |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
The make method returns an instance of the invocant, if the data provided |
|
313
|
|
|
|
|
|
|
passes the registered type constraints, allowing for any coercion, or throws an |
|
314
|
|
|
|
|
|
|
exception. If the data provided is itself an instance of the invocant it will |
|
315
|
|
|
|
|
|
|
be returned unaltered. |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
I> |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=over 4 |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=item make example 1 |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
# given: synopsis |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
package main; |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
my $make = $example->make; |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
# Exception! (isa Venus::Check::Error) |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=back |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=over 4 |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=item make example 2 |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# given: synopsis |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
package main; |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
my $make = $example->make($example); |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
# bless({}, "Example") |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=back |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=over 4 |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=item make example 3 |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# given: synopsis |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
package main; |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
my $make = $example->make({}); |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# Exception! (isa Venus::Check::Error) |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=back |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=cut |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
=head1 AUTHORS |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
Awncorp, C |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=cut |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=head1 LICENSE |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
Copyright (C) 2000, Awncorp, C. |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
|
374
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=cut |