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 use Moose::Meta::Method::Accessor::Native::Hash::clear;
12 use Moose::Meta::Method::Accessor::Native::Hash::count;
13 use Moose::Meta::Method::Accessor::Native::Hash::defined;
14 use Moose::Meta::Method::Accessor::Native::Hash::delete;
15 use Moose::Meta::Method::Accessor::Native::Hash::elements;
16 use Moose::Meta::Method::Accessor::Native::Hash::exists;
17 use Moose::Meta::Method::Accessor::Native::Hash::get;
18 use Moose::Meta::Method::Accessor::Native::Hash::is_empty;
19 use Moose::Meta::Method::Accessor::Native::Hash::keys;
20 use Moose::Meta::Method::Accessor::Native::Hash::kv;
21 use Moose::Meta::Method::Accessor::Native::Hash::set;
22 use Moose::Meta::Method::Accessor::Native::Hash::values;
24 with 'Moose::Meta::Attribute::Native::Trait';
26 has 'method_provider' => (
29 predicate => 'has_method_provider',
30 default => 'Moose::Meta::Attribute::Native::MethodProvider::Hash'
33 sub _helper_type { 'HashRef' }
45 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
55 isa => 'HashRef[Str]',
56 default => sub { {} },
60 has_no_options => 'is_empty',
61 num_options => 'count',
62 delete_option => 'delete',
69 This module provides a Hash attribute which provides a number of
72 =head1 PROVIDED METHODS
74 These methods are implemented in
75 L<Moose::Meta::Attribute::Native::MethodProvider::Hash>.
79 =item B<get($key, $key2, $key3...)>
81 Returns values from the hash.
83 In list context return a list of values in the hash for the given keys.
84 In scalar context returns the value for the last key specified.
86 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
88 Sets the elements in the hash to the given values.
90 =item B<delete($key, $key2, $key3...)>
92 Removes the elements with the given keys.
96 Returns the list of keys in the hash.
100 Returns true if the given key is present in the hash.
102 =item B<defined($key)>
104 Returns true if the value of a given key is defined.
108 Returns the list of values in the hash.
112 Returns the key/value pairs in the hash as an array of array references.
114 for my $pair ( $object->options->pairs ) {
115 print "$pair->[0] = $pair->[1]\n";
120 Returns the key/value pairs in the hash as a flattened list..
124 Resets the hash to an empty value, like C<%hash = ()>.
128 Returns the number of elements in the hash. Also useful for not empty:
129 C<< has_options => 'count' >>.
133 If the hash is populated, returns false. Otherwise, returns true.
137 If passed one argument, returns the value of the specified key. If passed two
138 arguments, sets the value of the specified key.
148 =item B<method_provider>
150 =item B<has_method_provider>
156 See L<Moose/BUGS> for details on reporting bugs.
160 Stevan Little E<lt>stevan@iinteractive.comE<gt>
162 =head1 COPYRIGHT AND LICENSE
164 Copyright 2007-2009 by Infinity Interactive, Inc.
166 L<http://www.iinteractive.com>
168 This library is free software; you can redistribute it and/or modify
169 it under the same terms as Perl itself.