Remove all references to method providers
[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
b6cca0d5 5our $VERSION = '1.14';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
44babf1f 9use Moose::Meta::Method::Accessor::Native::Hash::clear;
10use Moose::Meta::Method::Accessor::Native::Hash::count;
11use Moose::Meta::Method::Accessor::Native::Hash::defined;
12use Moose::Meta::Method::Accessor::Native::Hash::delete;
13use Moose::Meta::Method::Accessor::Native::Hash::elements;
14use Moose::Meta::Method::Accessor::Native::Hash::exists;
15use Moose::Meta::Method::Accessor::Native::Hash::get;
16use Moose::Meta::Method::Accessor::Native::Hash::is_empty;
17use Moose::Meta::Method::Accessor::Native::Hash::keys;
18use Moose::Meta::Method::Accessor::Native::Hash::kv;
19use Moose::Meta::Method::Accessor::Native::Hash::set;
20use Moose::Meta::Method::Accessor::Native::Hash::values;
21
c466e58f 22with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 23
2e069f5a 24sub _helper_type { 'HashRef' }
e3c07b19 25
26no Moose::Role;
27
e3c07b19 281;
29
30__END__
31
32=pod
33
34=head1 NAME
35
2420461c 36Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
e3c07b19 37
38=head1 SYNOPSIS
39
40 package Stuff;
41 use Moose;
e3c07b19 42
43 has 'options' => (
96fd0bec 44 traits => ['Hash'],
e3c07b19 45 is => 'ro',
46 isa => 'HashRef[Str]',
47 default => sub { {} },
5f3663b2 48 handles => {
af44c00c 49 set_option => 'set',
50 get_option => 'get',
bb023e15 51 has_no_options => 'is_empty',
af44c00c 52 num_options => 'count',
53 delete_option => 'delete',
43852ddb 54 option_pairs => 'kv',
9610c1d2 55 },
e3c07b19 56 );
57
58=head1 DESCRIPTION
59
60This module provides a Hash attribute which provides a number of
8396a437 61hash-like operations.
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
85592815 71In list context return a list of values in the hash for the given keys.
72In scalar context returns the value for the last key specified.
96fd0bec 73
9d010f57 74=item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
85592815 75
76Sets the elements in the hash to the given values.
96fd0bec 77
9d010f57 78=item B<delete($key, $key2, $key3...)>
96fd0bec 79
9d010f57 80Removes the elements with the given keys.
96fd0bec 81
8396a437 82=item B<keys>
96fd0bec 83
8396a437 84Returns the list of keys in the hash.
96fd0bec 85
8396a437 86=item B<exists($key)>
96fd0bec 87
8396a437 88Returns true if the given key is present in the hash.
96fd0bec 89
8396a437 90=item B<defined($key)>
96fd0bec 91
8396a437 92Returns true if the value of a given key is defined.
96fd0bec 93
94=item B<values>
95
96Returns the list of values in the hash.
97
98=item B<kv>
99
8396a437 100Returns the key/value pairs in the hash as an array of array references.
101
102 for my $pair ( $object->options->pairs ) {
103 print "$pair->[0] = $pair->[1]\n";
104 }
96fd0bec 105
106=item B<elements>
107
8396a437 108Returns the key/value pairs in the hash as a flattened list..
96fd0bec 109
8396a437 110=item B<clear>
96fd0bec 111
8396a437 112Resets the hash to an empty value, like C<%hash = ()>.
96fd0bec 113
8396a437 114=item B<count>
96fd0bec 115
39e17fef 116Returns the number of elements in the hash. Also useful for not empty:
117C<< has_options => 'count' >>.
96fd0bec 118
bb023e15 119=item B<is_empty>
96fd0bec 120
8396a437 121If the hash is populated, returns false. Otherwise, returns true.
96fd0bec 122
123=item B<accessor>
124
8396a437 125If passed one argument, returns the value of the specified key. If passed two
126arguments, sets the value of the specified key.
96fd0bec 127
128=back
e3c07b19 129
130=head1 METHODS
131
132=over 4
133
134=item B<meta>
135
e3c07b19 136=back
137
138=head1 BUGS
139
d4048ef3 140See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 141
142=head1 AUTHOR
143
144Stevan Little E<lt>stevan@iinteractive.comE<gt>
145
146=head1 COPYRIGHT AND LICENSE
147
148Copyright 2007-2009 by Infinity Interactive, Inc.
149
150L<http://www.iinteractive.com>
151
152This library is free software; you can redistribute it and/or modify
153it under the same terms as Perl itself.
154
155=cut