NAME

Module::Generic::TieHash - Generic Tie Hash Mechanism for Object Oriented Hashes

SYNOPSIS

use DateTime;
my $tie = tie( my %hash, 'Module::Generic::TieHash', { key_object => 1 } );
my $now = DateTime->now;
my $array = [];
my $ref = {};
my $scalar = \"Hello";
my $code = sub{1};
my $glob = \*main;

$hash{ $now } = 'today';
$hash{ $array } = 'an array';
$hash{ $ref } = 'an hash';
$hash{ $scalar } = 'a scalar reference';
$hash{ $code } = 'anonymous subroutine';
$hash{ $glob } = 'a filehandle';
$hash{name} = 'John Doe';

DESCRIPTION

This module implements a tied hash mechanism that accepts as keys strings or references, if the option key_object is enabled, recursively, meaning, even embedded hash references within the top hash reference are also tied to this class.

It also supports callback hooks for Storable

The constructor TIEHASH supports the following options provided as an hash reference:

  • debug

    The debug value as an integer.

  • disable

    An array reference of module classes for which this package will give direct access to the tie object rather to the data stored.

    To avoid conflict, the object properties and the tied hash properties are stored in different parts of the tied object.

    By default, Module::Generic is part of the exclusion list for which this tied object is disabled.

  • key_object

    Boolean. If true, this allows for the storing of objects as hash keys. Normally, perl would stringify an object to use it as an hash key.

Also, if you set the global variable $PAUSED, then, the exclusion mechanism will be disabled, and during that time, any access to the tied hash will return data stored in it, rather than the object properties.

VERSION

v1.2.2

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright (c) 2020-2023 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.