line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Attribute::Native::Trait::Hash; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
8166
|
use Moose::Role; |
|
10
|
|
|
|
|
35
|
|
|
10
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
with 'Moose::Meta::Attribute::Native::Trait'; |
6
|
|
|
|
|
|
|
|
7
|
191
|
|
|
191
|
|
1237
|
sub _helper_type { 'HashRef' } |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
97
|
no Moose::Role; |
|
10
|
|
|
|
|
47
|
|
|
10
|
|
|
|
|
56
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Helper trait for HashRef attributes |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__END__ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=pod |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=encoding UTF-8 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 VERSION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
version 2.2206 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package Stuff; |
32
|
|
|
|
|
|
|
use Moose; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'options' => ( |
35
|
|
|
|
|
|
|
traits => ['Hash'], |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => 'HashRef[Str]', |
38
|
|
|
|
|
|
|
default => sub { {} }, |
39
|
|
|
|
|
|
|
handles => { |
40
|
|
|
|
|
|
|
set_option => 'set', |
41
|
|
|
|
|
|
|
get_option => 'get', |
42
|
|
|
|
|
|
|
has_no_options => 'is_empty', |
43
|
|
|
|
|
|
|
num_options => 'count', |
44
|
|
|
|
|
|
|
delete_option => 'delete', |
45
|
|
|
|
|
|
|
option_pairs => 'kv', |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This trait provides native delegation methods for hash references. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 get($key, $key2, $key3...) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Returns values from the hash. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
In list context it returns a list of values in the hash for the given keys. In |
60
|
|
|
|
|
|
|
scalar context it returns the value for the last key specified. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This method requires at least one argument. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 set($key =E<gt> $value, $key2 =E<gt> $value2...) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Sets the elements in the hash to the given values. It returns the new values |
67
|
|
|
|
|
|
|
set for each key, in the same order as the keys passed to the method. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This method requires at least two arguments, and expects an even number of |
70
|
|
|
|
|
|
|
arguments. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 delete($key, $key2, $key3...) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Removes the elements with the given keys. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
In list context it returns a list of values in the hash for the deleted |
77
|
|
|
|
|
|
|
keys. In scalar context it returns the value for the last key specified. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 keys |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Returns the list of keys in the hash. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This method does not accept any arguments. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 exists($key) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Returns true if the given key is present in the hash. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This method requires a single argument. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 defined($key) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Returns true if the value of a given key is defined. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This method requires a single argument. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 values |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the list of values in the hash. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This method does not accept any arguments. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 kv |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Returns the key/value pairs in the hash as an array of array references. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
for my $pair ( $object->option_pairs ) { |
108
|
|
|
|
|
|
|
print "$pair->[0] = $pair->[1]\n"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This method does not accept any arguments. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 elements |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
In list context, this returns the key/value pairs in the hash. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
In scalar context, this returns the count of keys plus values. In other words, |
118
|
|
|
|
|
|
|
it's the same as L<keys> times two. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This method does not accept any arguments. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 clear |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Resets the hash to an empty value, like C<%hash = ()>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This method does not accept any arguments. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 count |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns the number of elements in the hash. Also useful to check for a nonempty hash, because C<count> returns a true (nonzero) value if there is something in the hash: |
131
|
|
|
|
|
|
|
C<< has_options => 'count' >>. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This method does not accept any arguments. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 is_empty |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
If the hash is populated, returns false. Otherwise, returns true. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This method does not accept any arguments. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 accessor($key) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 accessor($key, $value) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
If passed one argument, returns the value of the specified key. If passed two |
146
|
|
|
|
|
|
|
arguments, sets the value of the specified key. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
When called as a setter, this method returns the value that was set. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 shallow_clone |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This method returns a shallow clone of the hash reference. The return value |
153
|
|
|
|
|
|
|
is a reference to a new hash with the same keys and values. It is I<shallow> |
154
|
|
|
|
|
|
|
because any values that were references in the original will be the I<same> |
155
|
|
|
|
|
|
|
references in the clone. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 Why no C<each>? |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
We have deliberately omitted a method for C<each>, due to its stateful |
160
|
|
|
|
|
|
|
interaction with the hash iterator. Using C<keys> or C<kv> is much safer. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 Moose::Meta::Attribute->meta |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This will return a L<Class::MOP::Class> instance for this class. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
It should also be noted that L<Class::MOP> will actually bootstrap |
167
|
|
|
|
|
|
|
this module by installing a number of attribute meta-objects into its |
168
|
|
|
|
|
|
|
metaclass. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 BUGS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHORS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=over 4 |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
225
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |