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