line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Objects::WithUtils::Hash::Typed; |
2
|
|
|
|
|
|
|
$List::Objects::WithUtils::Hash::Typed::VERSION = '2.028002'; |
3
|
99
|
|
|
99
|
|
1103
|
use strictures 2; |
|
99
|
|
|
|
|
462
|
|
|
99
|
|
|
|
|
3285
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Role::Tiny; |
6
|
|
|
|
|
|
|
Role::Tiny->apply_roles_to_package( __PACKAGE__, |
7
|
|
|
|
|
|
|
qw/ |
8
|
|
|
|
|
|
|
List::Objects::WithUtils::Role::Hash |
9
|
|
|
|
|
|
|
List::Objects::WithUtils::Role::Hash::Typed |
10
|
|
|
|
|
|
|
/ |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
99
|
|
|
99
|
|
15416
|
use Exporter (); |
|
99
|
|
|
|
|
140
|
|
|
99
|
|
|
|
|
4229
|
|
14
|
|
|
|
|
|
|
our @EXPORT = 'hash_of'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
100
|
|
|
100
|
|
180
|
my $pkg = caller; |
18
|
99
|
|
|
99
|
|
511
|
{ no strict 'refs'; |
|
99
|
|
|
|
|
118
|
|
|
99
|
|
|
|
|
11265
|
|
|
100
|
|
|
|
|
114
|
|
19
|
100
|
|
|
|
|
106
|
${"${pkg}::a"} = ${"${pkg}::a"}; ${"${pkg}::b"} = ${"${pkg}::b"}; |
|
100
|
|
|
|
|
173
|
|
|
100
|
|
|
|
|
271
|
|
|
100
|
|
|
|
|
96
|
|
|
100
|
|
|
|
|
154
|
|
|
100
|
|
|
|
|
154
|
|
20
|
|
|
|
|
|
|
} |
21
|
100
|
|
|
|
|
5334
|
goto &Exporter::import |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
1
|
1114
|
sub hash_of { __PACKAGE__->new(@_) } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=pod |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
List::Objects::WithUtils::Hash::Typed - Type-checking hash objects |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use List::Objects::WithUtils 'hash_of'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Types::Standard -all; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $arr = hash_of Int() => ( foo => 1, bar => 2 ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
These are type-checking hash objects; values are checked against the specified |
46
|
|
|
|
|
|
|
type when the object is constructed or new elements are added. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The first argument passed to the constructor should be a L type: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Types::Standard -all; |
51
|
|
|
|
|
|
|
my $hash = hash_of Int() => ( foo => 1 ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
If the initial type-check fails, a coercion is attempted. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This class consumes the following roles, which contain most of the relevant |
56
|
|
|
|
|
|
|
documentation: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
L |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Also see L, L |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 hash_of |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Creates a new typed hash object. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 AUTHOR |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Jon Portnoy with significant contributions from Toby |
71
|
|
|
|
|
|
|
Inkster (CPAN: TOBYINK) |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |