2 package Moose::Meta::Attribute::Native::Trait::Hash;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Attribute::Native::MethodProvider::Hash;
11 with 'Moose::Meta::Attribute::Native::Trait';
13 has 'method_provider' => (
16 predicate => 'has_method_provider',
17 default => 'Moose::Meta::Attribute::Native::MethodProvider::Hash'
20 sub _helper_type { 'HashRef' }
32 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
42 isa => 'HashRef[Str]',
43 default => sub { {} },
47 has_no_options => 'is_empty',
48 num_options => 'count',
49 delete_option => 'delete',
56 This module provides a Hash attribute which provides a number of
59 =head1 PROVIDED METHODS
61 These methods are implemented in
62 L<Moose::Meta::Attribute::Native::MethodProvider::Hash>.
66 =item B<get($key, $key2, $key3...)>
68 Returns values from the hash.
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.
73 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
75 Sets the elements in the hash to the given values.
77 =item B<delete($key, $key2, $key3...)>
79 Removes the elements with the given keys.
83 Returns the list of keys in the hash.
87 Returns true if the given key is present in the hash.
89 =item B<defined($key)>
91 Returns true if the value of a given key is defined.
95 Returns the list of values in the hash.
99 Returns the key/value pairs in the hash as an array of array references.
101 for my $pair ( $object->options->pairs ) {
102 print "$pair->[0] = $pair->[1]\n";
107 Returns the key/value pairs in the hash as a flattened list..
111 Resets the hash to an empty value, like C<%hash = ()>.
115 Returns the number of elements in the hash. Also useful for not empty:
116 C<< has_options => 'count' >>.
120 If the hash is populated, returns false. Otherwise, returns true.
124 If passed one argument, returns the value of the specified key. If passed two
125 arguments, sets the value of the specified key.
135 =item B<method_provider>
137 =item B<has_method_provider>
143 See L<Moose/BUGS> for details on reporting bugs.
147 Stevan Little E<lt>stevan@iinteractive.comE<gt>
149 =head1 COPYRIGHT AND LICENSE
151 Copyright 2007-2009 by Infinity Interactive, Inc.
153 L<http://www.iinteractive.com>
155 This library is free software; you can redistribute it and/or modify
156 it under the same terms as Perl itself.