line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Objects::WithUtils::Hash::Typed; |
2
|
|
|
|
|
|
|
$List::Objects::WithUtils::Hash::Typed::VERSION = '2.027002'; |
3
|
99
|
|
|
99
|
|
1747
|
use strictures 2; |
|
99
|
|
|
|
|
592
|
|
|
99
|
|
|
|
|
4402
|
|
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
|
|
23442
|
use Exporter (); |
|
99
|
|
|
|
|
185
|
|
|
99
|
|
|
|
|
5447
|
|
14
|
|
|
|
|
|
|
our @EXPORT = 'hash_of'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
100
|
|
|
100
|
|
259
|
my $pkg = caller; |
18
|
99
|
|
|
99
|
|
586
|
{ no strict 'refs'; |
|
99
|
|
|
|
|
220
|
|
|
99
|
|
|
|
|
14976
|
|
|
100
|
|
|
|
|
181
|
|
19
|
100
|
|
|
|
|
279
|
${"${pkg}::a"} = ${"${pkg}::a"}; ${"${pkg}::b"} = ${"${pkg}::b"}; |
|
100
|
|
|
|
|
336
|
|
|
100
|
|
|
|
|
445
|
|
|
100
|
|
|
|
|
169
|
|
|
100
|
|
|
|
|
267
|
|
|
100
|
|
|
|
|
316
|
|
20
|
|
|
|
|
|
|
} |
21
|
100
|
|
|
|
|
6746
|
goto &Exporter::import |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
1
|
1571
|
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 |