Add explicit return values for (almost) all native delegation mutating methods
[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
efa728b4 5our $VERSION = '1.15';
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
61This module provides a Hash attribute which provides a number of
8396a437 62hash-like operations.
96fd0bec 63
64=head1 PROVIDED METHODS
65
96fd0bec 66=over 4
67
85592815 68=item B<get($key, $key2, $key3...)>
96fd0bec 69
85592815 70Returns values from the hash.
96fd0bec 71
85592815 72In list context return a list of values in the hash for the given keys.
73In scalar context returns the value for the last key specified.
96fd0bec 74
9d010f57 75=item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
85592815 76
77Sets the elements in the hash to the given values.
96fd0bec 78
9d010f57 79=item B<delete($key, $key2, $key3...)>
96fd0bec 80
9d010f57 81Removes the elements with the given keys.
96fd0bec 82
8396a437 83=item B<keys>
96fd0bec 84
8396a437 85Returns the list of keys in the hash.
96fd0bec 86
8396a437 87=item B<exists($key)>
96fd0bec 88
8396a437 89Returns true if the given key is present in the hash.
96fd0bec 90
8396a437 91=item B<defined($key)>
96fd0bec 92
8396a437 93Returns true if the value of a given key is defined.
96fd0bec 94
95=item B<values>
96
97Returns the list of values in the hash.
98
99=item B<kv>
100
8396a437 101Returns the key/value pairs in the hash as an array of array references.
102
103 for my $pair ( $object->options->pairs ) {
104 print "$pair->[0] = $pair->[1]\n";
105 }
96fd0bec 106
107=item B<elements>
108
8396a437 109Returns the key/value pairs in the hash as a flattened list..
96fd0bec 110
8396a437 111=item B<clear>
96fd0bec 112
8396a437 113Resets the hash to an empty value, like C<%hash = ()>.
96fd0bec 114
8396a437 115=item B<count>
96fd0bec 116
39e17fef 117Returns the number of elements in the hash. Also useful for not empty:
118C<< has_options => 'count' >>.
96fd0bec 119
bb023e15 120=item B<is_empty>
96fd0bec 121
8396a437 122If the hash is populated, returns false. Otherwise, returns true.
96fd0bec 123
124=item B<accessor>
125
8396a437 126If passed one argument, returns the value of the specified key. If passed two
127arguments, sets the value of the specified key.
96fd0bec 128
129=back
e3c07b19 130
131=head1 METHODS
132
133=over 4
134
135=item B<meta>
136
e3c07b19 137=back
138
139=head1 BUGS
140
d4048ef3 141See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 142
143=head1 AUTHOR
144
145Stevan Little E<lt>stevan@iinteractive.comE<gt>
146
147=head1 COPYRIGHT AND LICENSE
148
149Copyright 2007-2009 by Infinity Interactive, Inc.
150
151L<http://www.iinteractive.com>
152
153This library is free software; you can redistribute it and/or modify
154it under the same terms as Perl itself.
155
156=cut