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';
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.
+hash-like operations.
=head1 PROVIDED METHODS
=over 4
-=item B<count>
+=item B<get($key)>
-Returns the number of elements in the list.
+Returns an element of the hash by its key.
-=item B<empty>
+=item B<set($key)>
-If the list is populated, returns true. Otherwise, returns false.
+Sets the element in the hash at the given key to the given value.
-=item B<exists>
+=item B<delete($key)>
-Returns true if the given key is present in the hash
+Removes the element with the given key.
-=item B<defined>
+=item B<keys>
-Returns true if the value of a given key is defined
+Returns the list of keys in the hash.
-=item B<get>
+=item B<exists($key)>
-Returns an element of the hash by its key.
+Returns true if the given key is present in the hash.
-=item B<keys>
+=item B<defined($key)>
-Returns the list of keys in the hash.
+Returns true if the value of a given key is defined.
=item B<values>
=item B<kv>
-Returns the key, value pairs in the hash as array references
+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
+Returns the key/value pairs in the hash as a flattened list..
-=item B<delete>
+=item B<clear>
-Removes the element with the given key
+Resets the hash to an empty value, like C<%hash = ()>.
-=item B<clear>
+=item B<count>
-Unsets the hash entirely.
+Returns the number of elements in the hash.
-=item B<set>
+=item B<empty>
-Sets the element in the hash at the given key to the given value.
+If the hash is populated, returns false. Otherwise, returns true.
=item B<accessor>
-If passed one argument, returns the value of the requested key. If passed two
-arguments, sets the value of the requested key.
+If passed one argument, returns the value of the specified key. If passed two
+arguments, sets the value of the specified key.
=back