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