| line |
stmt |
bran |
cond |
sub |
code |
|
1
|
|
|
|
|
package List::Objects::WithUtils::Array::Typed; |
|
2
|
14
|
|
|
14
|
use strictures 1; |
|
|
14
|
|
|
|
|
|
|
14
|
|
|
|
|
|
3
|
|
|
|
|
|
|
4
|
|
|
|
|
require Role::Tiny; |
|
5
|
|
|
|
|
Role::Tiny->apply_roles_to_package( __PACKAGE__, |
|
6
|
|
|
|
|
qw/ |
|
7
|
|
|
|
|
List::Objects::WithUtils::Role::Array |
|
8
|
|
|
|
|
List::Objects::WithUtils::Role::Array::WithJunctions |
|
9
|
|
|
|
|
List::Objects::WithUtils::Role::Array::Typed |
|
10
|
|
|
|
|
/, |
|
11
|
|
|
|
|
); |
|
12
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
use Exporter 'import'; |
|
|
14
|
|
|
|
|
|
|
14
|
|
|
|
|
|
14
|
|
|
|
|
our @EXPORT = 'array_of'; |
|
15
|
3
|
|
|
3
|
sub array_of { __PACKAGE__->new(@_) } |
|
16
|
|
|
|
|
1; |
|
17
|
|
|
|
|
|
|
18
|
|
|
|
|
=pod |
|
19
|
|
|
|
|
|
|
20
|
|
|
|
|
=for Pod::Coverage array_of |
|
21
|
|
|
|
|
|
|
22
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
24
|
|
|
|
|
List::Objects::WithUtils::Array::Typed - Type-checking array objects |
|
25
|
|
|
|
|
|
|
26
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
28
|
|
|
|
|
use List::Objects::WithUtils 'array_of'; |
|
29
|
|
|
|
|
|
|
30
|
|
|
|
|
use Types::Standard -all; |
|
31
|
|
|
|
|
use List::Objects::Types -all; |
|
32
|
|
|
|
|
|
|
33
|
|
|
|
|
my $arr = array_of( Int() => 1 .. 10 ); |
|
34
|
|
|
|
|
$arr->push('foo'); # dies, failed type check |
|
35
|
|
|
|
|
$arr->push(11 .. 15); # ok |
|
36
|
|
|
|
|
|
|
37
|
|
|
|
|
my $arr_of_arrs = array_of( ArrayObj ); |
|
38
|
|
|
|
|
$arr_of_arrs->push([], []); # ok, coerces to ArrayObj |
|
39
|
|
|
|
|
|
|
40
|
|
|
|
|
=head1 DESCRIPTION |
|
41
|
|
|
|
|
|
|
42
|
|
|
|
|
These are type-checking array objects; elements are checked against the |
|
43
|
|
|
|
|
specified type when the object is constructed or new elements are added. |
|
44
|
|
|
|
|
|
|
45
|
|
|
|
|
The first argument passed to the constructor should be a L<Type::Tiny> type: |
|
46
|
|
|
|
|
|
|
47
|
|
|
|
|
use Types::Standard -all; |
|
48
|
|
|
|
|
my $arr = array_of Str() => qw/foo bar baz/; |
|
49
|
|
|
|
|
|
|
50
|
|
|
|
|
If the initial type-check fails, a coercion is attempted. |
|
51
|
|
|
|
|
|
|
52
|
|
|
|
|
This class consumes the following roles, which contain most of the relevant |
|
53
|
|
|
|
|
documentation: |
|
54
|
|
|
|
|
|
|
55
|
|
|
|
|
L<List::Objects::WithUtils::Role::Array> |
|
56
|
|
|
|
|
|
|
57
|
|
|
|
|
L<List::Objects::WithUtils::Role::Array::WithJunctions> |
|
58
|
|
|
|
|
|
|
59
|
|
|
|
|
L<List::Objects::WithUtils::Role::Array::Typed> |
|
60
|
|
|
|
|
|
|
61
|
|
|
|
|
Also see L<Types::Standard>, L<List::Objects::Types> |
|
62
|
|
|
|
|
|
|
63
|
|
|
|
|
=head1 AUTHOR |
|
64
|
|
|
|
|
|
|
65
|
|
|
|
|
Jon Portnoy <avenj@cobaltirc.org> with significant contributions from Toby |
|
66
|
|
|
|
|
Inkster (CPAN: TOBYINK) |
|
67
|
|
|
|
|
|
|
68
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|