rename Hash->empty => is_empty
[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)>
67
68 Returns an element of the hash by its key.
69
70 =item B<set($key)>
71
72 Sets the element in the hash at the given key to the given value.
73
74 =item B<delete($key)>
75
76 Removes the element with the given key.
77
78 =item B<keys>
79
80 Returns the list of keys in the hash.
81
82 =item B<exists($key)>
83
84 Returns true if the given key is present in the hash.
85
86 =item B<defined($key)>
87
88 Returns true if the value of a given key is defined.
89
90 =item B<values>
91
92 Returns the list of values in the hash.
93
94 =item B<kv>
95
96 Returns the key/value pairs in the hash as an array of array references.
97
98   for my $pair ( $object->options->pairs ) {
99       print "$pair->[0] = $pair->[1]\n";
100   }
101
102 =item B<elements>
103
104 Returns the key/value pairs in the hash as a flattened list..
105
106 =item B<clear>
107
108 Resets the hash to an empty value, like C<%hash = ()>.
109
110 =item B<count>
111
112 Returns the number of elements in the hash.
113
114 =item B<is_empty>
115
116 If the hash is populated, returns false. Otherwise, returns true.
117
118 =item B<accessor>
119
120 If passed one argument, returns the value of the specified key. If passed two
121 arguments, sets the value of the specified key.
122
123 =back
124
125 =head1 METHODS
126
127 =over 4
128
129 =item B<meta>
130
131 =item B<method_provider>
132
133 =item B<has_method_provider>
134
135 =back
136
137 =head1 BUGS
138
139 All complex software has bugs lurking in it, and this module is no
140 exception. If you find a bug please either email me, or add the bug
141 to cpan-RT.
142
143 =head1 AUTHOR
144
145 Stevan Little E<lt>stevan@iinteractive.comE<gt>
146
147 =head1 COPYRIGHT AND LICENSE
148
149 Copyright 2007-2009 by Infinity Interactive, Inc.
150
151 L<http://www.iinteractive.com>
152
153 This library is free software; you can redistribute it and/or modify
154 it under the same terms as Perl itself.
155
156 =cut