2 package Moose::Meta::Attribute::Native::Trait::Hash;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 use Moose::Meta::Method::Accessor::Native::Hash::accessor;
10 use Moose::Meta::Method::Accessor::Native::Hash::clear;
11 use Moose::Meta::Method::Accessor::Native::Hash::count;
12 use Moose::Meta::Method::Accessor::Native::Hash::defined;
13 use Moose::Meta::Method::Accessor::Native::Hash::delete;
14 use Moose::Meta::Method::Accessor::Native::Hash::elements;
15 use Moose::Meta::Method::Accessor::Native::Hash::exists;
16 use Moose::Meta::Method::Accessor::Native::Hash::get;
17 use Moose::Meta::Method::Accessor::Native::Hash::is_empty;
18 use Moose::Meta::Method::Accessor::Native::Hash::keys;
19 use Moose::Meta::Method::Accessor::Native::Hash::kv;
20 use Moose::Meta::Method::Accessor::Native::Hash::set;
21 use Moose::Meta::Method::Accessor::Native::Hash::values;
23 with 'Moose::Meta::Attribute::Native::Trait';
25 sub _helper_type { 'HashRef' }
37 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
47 isa => 'HashRef[Str]',
48 default => sub { {} },
52 has_no_options => 'is_empty',
53 num_options => 'count',
54 delete_option => 'delete',
61 This module provides a Hash attribute which provides a number of
64 =head1 PROVIDED METHODS
68 =item B<get($key, $key2, $key3...)>
70 Returns values from the hash.
72 In list context return a list of values in the hash for the given keys.
73 In scalar context returns the value for the last key specified.
75 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
77 Sets the elements in the hash to the given values.
79 =item B<delete($key, $key2, $key3...)>
81 Removes the elements with the given keys.
85 Returns the list of keys in the hash.
89 Returns true if the given key is present in the hash.
91 =item B<defined($key)>
93 Returns true if the value of a given key is defined.
97 Returns the list of values in the hash.
101 Returns the key/value pairs in the hash as an array of array references.
103 for my $pair ( $object->options->pairs ) {
104 print "$pair->[0] = $pair->[1]\n";
109 Returns the key/value pairs in the hash as a flattened list..
113 Resets the hash to an empty value, like C<%hash = ()>.
117 Returns the number of elements in the hash. Also useful for not empty:
118 C<< has_options => 'count' >>.
122 If the hash is populated, returns false. Otherwise, returns true.
126 If passed one argument, returns the value of the specified key. If passed two
127 arguments, sets the value of the specified key.
141 See L<Moose/BUGS> for details on reporting bugs.
145 Stevan Little E<lt>stevan@iinteractive.comE<gt>
147 =head1 COPYRIGHT AND LICENSE
149 Copyright 2007-2009 by Infinity Interactive, Inc.
151 L<http://www.iinteractive.com>
153 This library is free software; you can redistribute it and/or modify
154 it under the same terms as Perl itself.