NAME

Hydrogen::HashRef - a standard library for hashrefs

VERSION

This documentation is for Hydrogen::HashRef 0.020000, which is based on Sub::HandlesVia::HandlerLibrary::Hash 0.046.

FUNCTIONS

Each function expects a reference to a hash as its first argument.

accessor( $hashref, $key, $value? )

Additional arguments: Str, Optional[Any].

Acts like get if given just a key, or set if given a key and a value.

all( $hashref )

Returns the hash in list context.

clear( $hashref )

Empties the hash.

count( $hashref )

Returns the number of keys in the hash.

defined( $hashref, $key )

Additional arguments: Str.

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

delete( $hashref, $key )

Removes a value from the hashref by its key.

delete_where( $hashref, $match )

Additional arguments: CodeRef|RegexpRef.

Removes values from the hashref by matching keys against a coderef or regexp.

elements( $hashref )

Returns the hash in list context.

exists( $hashref, $key )

Additional arguments: Str.

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

for_each_key( $hashref, $coderef )

Additional arguments: CodeRef.

Function which calls the coderef for each key in the hash, passing just the key to the coderef.

for_each_pair( $hashref, $coderef )

Additional arguments: CodeRef.

Function which calls the coderef for each key in the hash, passing the key and value to the coderef.

for_each_value( $hashref, $coderef )

Additional arguments: CodeRef.

Function which calls the coderef for each value in the hash, passing just the value to the coderef.

get( $hashref, $key )

Returns a value from the hashref by its key.

is_empty( $hashref )

Returns true iff there are no keys in the hash.

keys( $hashref )

Returns the list of keys in the hash.

kv( $hashref )

Returns a list of arrayrefs, where each arrayref is a key-value pair.

reset( $hashref )

Resets the original value to its default value, or an empty hashref if it has no default.

set( $hashref, $key, $value, ... )

Given a key and value, adds the key to the hashref with the given value.

shallow_clone( $hashref )

Creates a new hashref with the same keys and values as the original.

sorted_keys( $hashref )

Returns an alphabetically sorted list of keys in the hash.

values( $hashref )

Returns the list of values in the hash.

EXPORT

No functions are exported by this module by default. To import them all (this is usually a bad idea), use:

use Hydrogen::HashRef -all;

To import a particular function, use:

use Hydrogen::HashRef 'clear';

To rename functions:

use Hydrogen::HashRef 'clear' => { -as => 'myfunc' };

On Perl 5.37.2+ (or if Lexical::Sub is installed) you can import lexically:

use Hydrogen::HashRef -lexical, 'clear';

See Exporter::Tiny::Manual::Importing for more hints on importing.

BUGS

Please report any bugs to http://github.com/tobyink/p5-hydrogen/issues.

SEE ALSO

Hydrogen, Hydrogen::Hash, Hydrogen::Curry::HashRef, Hydrogen::Topic::HashRef, Sub::HandlesVia::HandlerLibrary::Hash, Hash::Util.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2022-2023 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.