line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Autobox::Hash; |
2
|
|
|
|
|
|
|
# ABSTRACT: the Hash role |
3
|
14
|
|
|
14
|
|
63
|
use Moose::Role 'with'; |
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
100
|
|
4
|
14
|
|
|
14
|
|
40812
|
use List::MoreUtils 0.07 (); |
|
14
|
|
|
|
|
365
|
|
|
14
|
|
|
|
|
257
|
|
5
|
14
|
|
|
14
|
|
58
|
use namespace::autoclean; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
113
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Moose::Autobox::Ref', |
10
|
|
|
|
|
|
|
'Moose::Autobox::Indexed'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub delete { |
13
|
1
|
|
|
1
|
1
|
3
|
my ($hash, $key) = @_; |
14
|
1
|
|
|
|
|
4
|
CORE::delete $hash->{$key}; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub merge { |
18
|
1
|
|
|
1
|
1
|
3
|
my ($left, $right) = @_; |
19
|
1
|
50
|
|
|
|
7
|
Carp::confess "You must pass a hashref as argument to merge" |
20
|
|
|
|
|
|
|
unless ref $right eq 'HASH'; |
21
|
1
|
|
|
|
|
10
|
return { %$left, %$right }; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub hslice { |
25
|
1
|
|
|
1
|
1
|
4
|
my ($hash, $keys) = @_; |
26
|
1
|
|
|
|
|
3
|
return { map { $_ => $hash->{$_} } @$keys }; |
|
2
|
|
|
|
|
10
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub flatten { |
30
|
1
|
|
|
1
|
1
|
1
|
return %{$_[0]} |
|
1
|
|
|
|
|
15
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# ::Indexed implementation |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub at { |
36
|
1
|
|
|
1
|
1
|
3
|
my ($hash, $index) = @_; |
37
|
1
|
|
|
|
|
3
|
$hash->{$index}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub put { |
41
|
1
|
|
|
1
|
1
|
2
|
my ($hash, $index, $value) = @_; |
42
|
1
|
|
|
|
|
2
|
$hash->{$index} = $value; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub exists { |
46
|
2
|
|
|
2
|
1
|
634
|
my ($hash, $key) = @_; |
47
|
2
|
|
|
|
|
6
|
CORE::exists $hash->{$key}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub keys { |
51
|
1
|
|
|
1
|
1
|
1
|
my ($hash) = @_; |
52
|
1
|
|
|
|
|
7
|
[ CORE::keys %$hash ]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub values { |
56
|
1
|
|
|
1
|
1
|
2
|
my ($hash) = @_; |
57
|
1
|
|
|
|
|
5
|
[ CORE::values %$hash ]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub kv { |
61
|
1
|
|
|
1
|
1
|
2
|
my ($hash) = @_; |
62
|
1
|
|
|
|
|
3
|
[ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; |
|
3
|
|
|
|
|
12
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub slice { |
66
|
1
|
|
|
1
|
1
|
696
|
my ($hash, $keys) = @_; |
67
|
1
|
|
|
|
|
3
|
return [ @{$hash}{@$keys} ]; |
|
1
|
|
|
|
|
8
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub each { |
71
|
0
|
|
|
0
|
1
|
0
|
my ($hash, $sub) = @_; |
72
|
0
|
|
|
|
|
0
|
for my $key (CORE::keys %$hash) { |
73
|
0
|
|
|
|
|
0
|
$sub->($key, $hash->{$key}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub each_key { |
78
|
2
|
|
|
2
|
1
|
2551
|
my ($hash, $sub) = @_; |
79
|
2
|
|
|
|
|
11
|
$sub->($_) for CORE::keys %$hash; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub each_value { |
83
|
2
|
|
|
2
|
1
|
1281
|
my ($hash, $sub) = @_; |
84
|
2
|
|
|
|
|
10
|
$sub->($_) for CORE::values %$hash; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub each_n_values { |
88
|
2
|
|
|
2
|
1
|
1433
|
my ($hash, $n, $sub) = @_; |
89
|
2
|
|
|
|
|
8
|
my @keys = CORE::keys %$hash; |
90
|
2
|
|
|
|
|
11
|
my $it = List::MoreUtils::natatime($n, @keys); |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
10
|
while (my @vals = $it->()) { |
93
|
4
|
|
|
|
|
16
|
$sub->(@$hash{ @vals }); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
12
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# End Indexed |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
1
|
|
sub print { CORE::print %{$_[0]} } |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
0
|
1
|
|
sub say { CORE::print %{$_[0]}, "\n" } |
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Moose::Autobox::Hash - the Hash role |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 0.16 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use Moose::Autobox; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two' |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DESCRIPTION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This is a role to describes a Hash value. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item C<delete> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item C<merge> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Takes a hashref and returns a new hashref with right precedence |
140
|
|
|
|
|
|
|
shallow merging. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item C<hslice> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Slices a hash but returns the keys and values as a new hashref. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C<flatten> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 Indexed implementation |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item C<at> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item C<put> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item C<exists> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item C<keys> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item C<values> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item C<kv> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item C<slice> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item C<each> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item C<each_key> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item C<each_value> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item C<each_n_values> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item C<meta> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item C<print> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item C<say> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SUPPORT |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Moose-Autobox> |
191
|
|
|
|
|
|
|
(or L<bug-Moose-Autobox@rt.cpan.org|mailto:bug-Moose-Autobox@rt.cpan.org>). |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
194
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
197
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
208
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |