NAME

Sub::HandlesVia::HandlerLibrary::Hash - library of Hash-related methods

SYNOPSIS

package My::Class {
  use Moo;
  use Sub::HandlesVia;
  use Types::Standard 'HashRef';
  has my_hash => (
    is => 'ro',
    isa => HashRef,
    handles_via => 'Hash',
    handles => {
      'my_accessor' => 'accessor',
      'my_all' => 'all',
      'my_clear' => 'clear',
      'my_count' => 'count',
      'my_defined' => 'defined',
      'my_delete' => 'delete',
      'my_elements' => 'elements',
      'my_exists' => 'exists',
      'my_for_each_key' => 'for_each_key',
      'my_for_each_pair' => 'for_each_pair',
      'my_for_each_value' => 'for_each_value',
      'my_get' => 'get',
      'my_is_empty' => 'is_empty',
      'my_keys' => 'keys',
      'my_kv' => 'kv',
      'my_reset' => 'reset',
      'my_set' => 'set',
      'my_shallow_clone' => 'shallow_clone',
      'my_sorted_keys' => 'sorted_keys',
      'my_values' => 'values',
    },
  );
}

DESCRIPTION

This is a library of methods for Sub::HandlesVia.

DELEGATABLE METHODS

accessor( $key, $value? )

Arguments: Str, Optional[Any].

Acts like get if given one argument, or set if given two arguments.

all()

Returns the hash in list context.

clear()

Empties the hash.

count()

Returns the number of keys in the hash.

defined( $key )

Arguments: Str.

Indicates whether a value exists and is defined in the hashref by its key.

delete( $key )

Removes a value from the hashref by its key.

elements()

Returns the hash in list context.

exists( $key )

Arguments: Str.

Indicates whether a value exists in the hashref by its key.

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.

is_empty()

Returns true iff there are no keys in the hash.

keys()

Returns the list of keys in the hash.

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.

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.

values()

Returns the list of values in the hash.

BUGS

Please report any bugs to https://github.com/tobyink/p5-sub-handlesvia/issues.

SEE ALSO

Sub::HandlesVia.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2020, 2022 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.