NAME

Tie::GuardedHash - Tied hash that allows access control on the hash operations

VERSION

version 1.000001

SYNOPSIS

use Tie::GuardedHash;

my $access_validator = sub { die 'CLEAR is not allowed on this hash' if (caller(1))[3] eq 'Tie::GuardedHash::CLEAR' };

tie(%hash, 'Tie::GuardedHash', $access_validator);
tie(%hash, 'Tie::GuardedHash', $access_validator, \%base_hash);

DESCRIPTION

This module provides a hash whose operations can be subject to access control through a validation subroutine supplied when the hash is tied. The following hash operations can be controlled by that subroutine:

  • CLEAR

  • DELETE

  • EXISTS

  • FETCH

  • FIRSTKEY

  • NEXTKEY

  • SCALAR

  • STORE

The validation subroutine is called without arguments and its return value is ignored. It should throw an exception whenever the execution of an operation is not authorized. That exception is propagated to the caller using the hash.

When the hash is tied, an optional hash reference can be supplied after the validation subroutine. Its contents are used to initialize the tied hash. If omitted, the tied hash is initially empty.

SEE ALSO

perltie

AUTHOR

Antoine Maréchal <a.marechal.1994@gmail.com>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by Antoine Maréchal <a.marechal.1994@gmail.com>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)