bump version to 1.18
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Hash.pm
CommitLineData
e3c07b19 1
c466e58f 2package Moose::Meta::Attribute::Native::Trait::Hash;
e3c07b19 3use Moose::Role;
4
aff6aafc 5our $VERSION = '1.18';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
7cba2d27 9use Moose::Meta::Method::Accessor::Native::Hash::accessor;
44babf1f 10use Moose::Meta::Method::Accessor::Native::Hash::clear;
11use Moose::Meta::Method::Accessor::Native::Hash::count;
12use Moose::Meta::Method::Accessor::Native::Hash::defined;
13use Moose::Meta::Method::Accessor::Native::Hash::delete;
14use Moose::Meta::Method::Accessor::Native::Hash::elements;
15use Moose::Meta::Method::Accessor::Native::Hash::exists;
16use Moose::Meta::Method::Accessor::Native::Hash::get;
17use Moose::Meta::Method::Accessor::Native::Hash::is_empty;
18use Moose::Meta::Method::Accessor::Native::Hash::keys;
19use Moose::Meta::Method::Accessor::Native::Hash::kv;
20use Moose::Meta::Method::Accessor::Native::Hash::set;
21use Moose::Meta::Method::Accessor::Native::Hash::values;
22
c466e58f 23with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 24
2e069f5a 25sub _helper_type { 'HashRef' }
e3c07b19 26
27no Moose::Role;
28
e3c07b19 291;
30
31__END__
32
33=pod
34
35=head1 NAME
36
2420461c 37Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
e3c07b19 38
39=head1 SYNOPSIS
40
41 package Stuff;
42 use Moose;
e3c07b19 43
44 has 'options' => (
96fd0bec 45 traits => ['Hash'],
e3c07b19 46 is => 'ro',
47 isa => 'HashRef[Str]',
48 default => sub { {} },
5f3663b2 49 handles => {
af44c00c 50 set_option => 'set',
51 get_option => 'get',
bb023e15 52 has_no_options => 'is_empty',
af44c00c 53 num_options => 'count',
54 delete_option => 'delete',
43852ddb 55 option_pairs => 'kv',
9610c1d2 56 },
e3c07b19 57 );
58
59=head1 DESCRIPTION
60
7795e4de 61This trait provides native delegation methods for array references.
96fd0bec 62
63=head1 PROVIDED METHODS
64
96fd0bec 65=over 4
66
85592815 67=item B<get($key, $key2, $key3...)>
96fd0bec 68
85592815 69Returns values from the hash.
96fd0bec 70
e132fd56 71In list context it returns a list of values in the hash for the given keys. In
72scalar context it returns the value for the last key specified.
73
74This method requires at least one argument.
96fd0bec 75
9d010f57 76=item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
85592815 77
e132fd56 78Sets the elements in the hash to the given values. It returns the new values
79set for each key, in the same order as the keys passed to the method.
80
81This method requires at least two arguments, and expects an even number of
82arguments.
96fd0bec 83
9d010f57 84=item B<delete($key, $key2, $key3...)>
96fd0bec 85
9d010f57 86Removes the elements with the given keys.
96fd0bec 87
e132fd56 88In list context it returns a list of values in the hash for the deleted
89keys. In scalar context it returns the value for the last key specified.
90
8396a437 91=item B<keys>
96fd0bec 92
8396a437 93Returns the list of keys in the hash.
96fd0bec 94
e132fd56 95This method does not accept any arguments.
96
8396a437 97=item B<exists($key)>
96fd0bec 98
8396a437 99Returns true if the given key is present in the hash.
96fd0bec 100
e132fd56 101This method requires a single argument.
102
8396a437 103=item B<defined($key)>
96fd0bec 104
8396a437 105Returns true if the value of a given key is defined.
96fd0bec 106
e132fd56 107This method requires a single argument.
108
96fd0bec 109=item B<values>
110
111Returns the list of values in the hash.
112
e132fd56 113This method does not accept any arguments.
114
96fd0bec 115=item B<kv>
116
8396a437 117Returns the key/value pairs in the hash as an array of array references.
118
119 for my $pair ( $object->options->pairs ) {
120 print "$pair->[0] = $pair->[1]\n";
121 }
96fd0bec 122
e132fd56 123This method does not accept any arguments.
124
96fd0bec 125=item B<elements>
126
8396a437 127Returns the key/value pairs in the hash as a flattened list..
96fd0bec 128
e132fd56 129This method does not accept any arguments.
130
8396a437 131=item B<clear>
96fd0bec 132
8396a437 133Resets the hash to an empty value, like C<%hash = ()>.
96fd0bec 134
e132fd56 135This method does not accept any arguments.
136
8396a437 137=item B<count>
96fd0bec 138
39e17fef 139Returns the number of elements in the hash. Also useful for not empty:
140C<< has_options => 'count' >>.
96fd0bec 141
e132fd56 142This method does not accept any arguments.
143
bb023e15 144=item B<is_empty>
96fd0bec 145
8396a437 146If the hash is populated, returns false. Otherwise, returns true.
96fd0bec 147
e132fd56 148This method does not accept any arguments.
149
150=item B<accessor($key)>
151
152=item B<accessor($key, $value)>
96fd0bec 153
8396a437 154If passed one argument, returns the value of the specified key. If passed two
155arguments, sets the value of the specified key.
96fd0bec 156
e132fd56 157When called as a setter, this method returns the value that was set.
158
96fd0bec 159=back
e3c07b19 160
161=head1 METHODS
162
163=over 4
164
165=item B<meta>
166
e3c07b19 167=back
168
169=head1 BUGS
170
d4048ef3 171See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 172
173=head1 AUTHOR
174
175Stevan Little E<lt>stevan@iinteractive.comE<gt>
176
177=head1 COPYRIGHT AND LICENSE
178
179Copyright 2007-2009 by Infinity Interactive, Inc.
180
181L<http://www.iinteractive.com>
182
183This library is free software; you can redistribute it and/or modify
184it under the same terms as Perl itself.
185
186=cut