"accessor($key,$value?)"
Arguments: Str, Optional[Any].
Acts like "get" if given just a key, or "set" if given a key and a value.
all()
Returns the hash in list context.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
my %hash = $object->my_all;
clear()
Empties the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
$object->my_clear;
say exists $object->attr->{foo}; ## ==> false
say exists $object->attr->{bar}; ## ==> false
count()
Returns the number of keys in the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
say $object->my_count; ## ==> 2
defined($key)
Arguments: Str.
Indicates whether a value exists and is defined in the hashref by its key.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
say $object->my_defined( 'foo' ); ## ==> 1
delete($key)
Removes a value from the hashref by its key.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
$object->my_delete( 'foo' );
say exists $object->attr->{foo}; ## ==> false
delete_where($match)
Arguments: CodeRef|RegexpRef.
Removes values from the hashref by matching keys against a coderef or regexp.
my $object = My::Class->new( attr => { foo => 0, bar => 1, baz => 2 } );
$object->my_delete_where( sub { $_ eq 'foo' or $_ eq 'bar' } );
say Dumper( $object->attr ); ## ==> { baz => 2 }
my $object2 = My::Class->new( attr => { foo => 0, bar => 1, baz => 2 } );
$object2->my_delete_where( qr/^b/ );
say Dumper( $object2->attr ); ## ==> { foo => 0 }
elements()
Returns the hash in list context.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
my %hash = $object->my_elements;
exists($key)
Arguments: Str.
Indicates whether a value exists in the hashref by its key.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
say $object->my_exists( 'foo' ); ## ==> true
say $object->my_exists( 'baz' ); ## ==> false
for_each_key($coderef)
Arguments: CodeRef.
Chainable method which calls the coderef for each key in the hash, passing just the key to the coderef.
for_each_pair($coderef)
Arguments: CodeRef.
Chainable method which calls the coderef for each key in the hash, passing the key and value to the
coderef.
for_each_value($coderef)
Arguments: CodeRef.
Chainable method which calls the coderef for each value in the hash, passing just the value to the
coderef.
get($key)
Returns a value from the hashref by its key.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
say $object->my_get( 'bar' ); ## ==> 1
is_empty()
Returns true iff there are no keys in the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
say $object->my_is_empty; ## ==> false
$object->_set_attr( {} );
say $object->my_is_empty; ## ==> true
keys()
Returns the list of keys in the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
# says 'foo' and 'bar' in an unpredictable order
say for $object->my_keys;
kv()
Returns a list of arrayrefs, where each arrayref is a key-value pair.
reset()
Resets the attribute to its default value, or an empty hashref if it has no default.
"set($key,$value,...)"
Given a key and value, adds the key to the hashref with the given value.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
$object->my_set( bar => 2, baz => 1 );
say $object->attr->{foo}; ## ==> 0
say $object->attr->{baz}; ## ==> 1
say $object->attr->{bar}; ## ==> 2
shallow_clone()
Creates a new hashref with the same keys and values as the original.
sorted_keys()
Returns an alphabetically sorted list of keys in the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
# says 'bar' then 'foo'
say for $object->my_sorted_keys;
values()
Returns the list of values in the hash.
my $object = My::Class->new( attr => { foo => 0, bar => 1 } );
# says '0' and '1' in an unpredictable order
say for $object->my_values;