Change documention for get and get to reflect actual behavior.
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Hash.pm
1
2 package Moose::Meta::Attribute::Native::Trait::Hash;
3 use Moose::Role;
4
5 our $VERSION   = '0.89_01';
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
8
9 use Moose::Meta::Attribute::Native::MethodProvider::Hash;
10
11 with 'Moose::Meta::Attribute::Native::Trait';
12
13 has 'method_provider' => (
14     is        => 'ro',
15     isa       => 'ClassName',
16     predicate => 'has_method_provider',
17     default   => 'Moose::Meta::Attribute::Native::MethodProvider::Hash'
18 );
19
20 sub _helper_type { 'HashRef' }
21
22 no Moose::Role;
23
24 1;
25
26 __END__
27
28 =pod
29
30 =head1 NAME
31
32 Moose::Meta::Attribute::Native::Trait::Hash
33
34 =head1 SYNOPSIS
35
36   package Stuff;
37   use Moose;
38
39   has 'options' => (
40       traits    => ['Hash'],
41       is        => 'ro',
42       isa       => 'HashRef[Str]',
43       default   => sub { {} },
44       handles   => {
45           set_option     => 'set',
46           get_option     => 'get',
47           has_no_options => 'is_empty',
48           num_options    => 'count',
49           delete_option  => 'delete',
50           pairs          => 'kv',
51       },
52   );
53
54 =head1 DESCRIPTION
55
56 This module provides a Hash attribute which provides a number of
57 hash-like operations.
58
59 =head1 PROVIDED METHODS
60
61 These methods are implemented in
62 L<Moose::Meta::Attribute::Native::MethodProvider::Hash>.
63
64 =over 4
65
66 =item B<get($key, $key2, $key3...)>
67
68 Returns values from the hash.
69
70 In list context return a list of values in the hash for the given keys.
71 In scalar context returns the value for the last key specified.
72
73 =item B<set($key => $value, $key2 => $value2 ...)>
74
75 Sets the elements in the hash to the given values.
76
77 =item B<delete($key)>
78
79 Removes the element with the given key.
80
81 =item B<keys>
82
83 Returns the list of keys in the hash.
84
85 =item B<exists($key)>
86
87 Returns true if the given key is present in the hash.
88
89 =item B<defined($key)>
90
91 Returns true if the value of a given key is defined.
92
93 =item B<values>
94
95 Returns the list of values in the hash.
96
97 =item B<kv>
98
99 Returns the key/value pairs in the hash as an array of array references.
100
101   for my $pair ( $object->options->pairs ) {
102       print "$pair->[0] = $pair->[1]\n";
103   }
104
105 =item B<elements>
106
107 Returns the key/value pairs in the hash as a flattened list..
108
109 =item B<clear>
110
111 Resets the hash to an empty value, like C<%hash = ()>.
112
113 =item B<count>
114
115 Returns the number of elements in the hash.
116
117 =item B<is_empty>
118
119 If the hash is populated, returns false. Otherwise, returns true.
120
121 =item B<accessor>
122
123 If passed one argument, returns the value of the specified key. If passed two
124 arguments, sets the value of the specified key.
125
126 =back
127
128 =head1 METHODS
129
130 =over 4
131
132 =item B<meta>
133
134 =item B<method_provider>
135
136 =item B<has_method_provider>
137
138 =back
139
140 =head1 BUGS
141
142 All complex software has bugs lurking in it, and this module is no
143 exception. If you find a bug please either email me, or add the bug
144 to cpan-RT.
145
146 =head1 AUTHOR
147
148 Stevan Little E<lt>stevan@iinteractive.comE<gt>
149
150 =head1 COPYRIGHT AND LICENSE
151
152 Copyright 2007-2009 by Infinity Interactive, Inc.
153
154 L<http://www.iinteractive.com>
155
156 This library is free software; you can redistribute it and/or modify
157 it under the same terms as Perl itself.
158
159 =cut