package Moose::Meta::Attribute::Native::Trait::Hash;
use Moose::Role;
-our $VERSION = '0.87';
+our $VERSION = '0.89';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
package Stuff;
use Moose;
- use Moose::AttributeHelpers;
has 'options' => (
- metaclass => 'Hash',
+ traits => ['Hash'],
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
handles => {
- set_option => 'set',
- get_option => 'get',
- has_options => 'empty',
- num_options => 'count',
- delete_option => 'delete',
- }
+ set_option => 'set',
+ get_option => 'get',
+ has_no_options => 'empty',
+ num_options => 'count',
+ delete_option => 'delete',
+ pairs => 'kv',
+ },
);
=head1 DESCRIPTION
This module provides a Hash attribute which provides a number of
-hash-like operations. See L<Moose::Meta::Attribute::Native::MethodProvider::Hash>
-for more details.
+hash-like operations.
+
+=head1 PROVIDED METHODS
+
+These methods are implemented in
+L<Moose::Meta::Attribute::Native::MethodProvider::Hash>.
+
+=over 4
+
+=item B<get($key)>
+
+Returns an element of the hash by its key.
+
+=item B<set($key)>
+
+Sets the element in the hash at the given key to the given value.
+
+=item B<delete($key)>
+
+Removes the element with the given key.
+
+=item B<keys>
+
+Returns the list of keys in the hash.
+
+=item B<exists($key)>
+
+Returns true if the given key is present in the hash.
+
+=item B<defined($key)>
+
+Returns true if the value of a given key is defined.
+
+=item B<values>
+
+Returns the list of values in the hash.
+
+=item B<kv>
+
+Returns the key/value pairs in the hash as an array of array references.
+
+ for my $pair ( $object->options->pairs ) {
+ print "$pair->[0] = $pair->[1]\n";
+ }
+
+=item B<elements>
+
+Returns the key/value pairs in the hash as a flattened list..
+
+=item B<clear>
+
+Resets the hash to an empty value, like C<%hash = ()>.
+
+=item B<count>
+
+Returns the number of elements in the hash.
+
+=item B<empty>
+
+If the hash is populated, returns false. Otherwise, returns true.
+
+=item B<accessor>
+
+If passed one argument, returns the value of the specified key. If passed two
+arguments, sets the value of the specified key.
+
+=back
=head1 METHODS