VERSION

SYNOPSIS

DESCRIPTION

Tie::Hash::Method provides a way to create a tied hash with specific overriden behaviour without having to create a new class to do it. A tied hash with no methods overriden is functionally equivalent to a normal hash.

Each method in a standard tie can be overriden by providing a callback to the tie call. So for instance if you wanted a tied hash that changed 'foo' into 'bar' on store you could say:

The callback is called with exactly the same arguments as the tie itself, in particular the tied object is always passed as the first argument.

The tied object is itself an array, which contains a second hash in the HASH slot (index 0) which is used to perform the default operations.

The callbacks available are in a hash keyed by name in the METHOD slot of the array (index 1).

If your code needs to store extra data in the object it should be stored in the PRIVATE slot of the object (index 2). No future release of this module will ever use or alter anything in that slot.

The arguments passed to the tie constructor will be seperated by the case of their keys. The ones with all capitals will be stored in the METHOD hash, and the rest will be stored in the PRIVATE hash.

CALLBACKS

STORE this, key, value

Store datum value into key for the tied hash this.

FETCH this, key

Retrieve the datum in key for the tied hash this.

FIRSTKEY this

Return the first key in the hash.

NEXTKEY this, lastkey

Return the next key in the hash.

EXISTS this, key

Verify that key exists with the tied hash this.

DELETE this, key

Delete the key key from the tied hash this.

CLEAR this

Clear all values from the tied hash this.

SCALAR this

Returns what evaluating the hash in scalar context yields.

Methods

base_hash

return or sets the underlying hash for this tie.

$_[0]->base_hash->{$key}= $value;

h

alias for base_hash.

$_[0]->h->{$key}= $value;

private_hash

Return or sets the hash of private data associated with this tie. This value will never be touched by any code in this class or its subclasses. It is purely object specific.

$_[0]->p->{'something'}= 'cake!';

p

alias for private_hash

method_hash

return or sets the hash of methods that are overriden for this tie. Exactly why you would want to use this is a little beyond my imagination, but for those who can think of a reason here is a nice way to do it. :-)

methods

Returns a list of methods that are overriden for this tie. Why this would be useful escapes me, but here it is anyway for Completeness sake, whoever she is, but people are always coding for her so I might as well too.

Exportable Subs

The following subs are exportable on request:

hash_overload(PAIRS)

Returns a reference to a hash tied with the specified callbacks overriden. Just a short cut.