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::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;
22 with 'Moose::Meta::Attribute::Native::Trait';
24 sub _helper_type { 'HashRef' }
36 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
46 isa => 'HashRef[Str]',
47 default => sub { {} },
51 has_no_options => 'is_empty',
52 num_options => 'count',
53 delete_option => 'delete',
60 This module provides a Hash attribute which provides a number of
63 =head1 PROVIDED METHODS
67 =item B<get($key, $key2, $key3...)>
69 Returns values from the hash.
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.
74 =item B<set($key =E<gt> $value, $key2 =E<gt> $value2...)>
76 Sets the elements in the hash to the given values.
78 =item B<delete($key, $key2, $key3...)>
80 Removes the elements with the given keys.
84 Returns the list of keys in the hash.
88 Returns true if the given key is present in the hash.
90 =item B<defined($key)>
92 Returns true if the value of a given key is defined.
96 Returns the list of values in the hash.
100 Returns the key/value pairs in the hash as an array of array references.
102 for my $pair ( $object->options->pairs ) {
103 print "$pair->[0] = $pair->[1]\n";
108 Returns the key/value pairs in the hash as a flattened list..
112 Resets the hash to an empty value, like C<%hash = ()>.
116 Returns the number of elements in the hash. Also useful for not empty:
117 C<< has_options => 'count' >>.
121 If the hash is populated, returns false. Otherwise, returns true.
125 If passed one argument, returns the value of the specified key. If passed two
126 arguments, sets the value of the specified key.
140 See L<Moose/BUGS> for details on reporting bugs.
144 Stevan Little E<lt>stevan@iinteractive.comE<gt>
146 =head1 COPYRIGHT AND LICENSE
148 Copyright 2007-2009 by Infinity Interactive, Inc.
150 L<http://www.iinteractive.com>
152 This library is free software; you can redistribute it and/or modify
153 it under the same terms as Perl itself.