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