geekondemand has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a Tie module that will roughly do the following: Of course it would be nice if the dispatch subroutines could actually refer to the hash itself to get other values... but that may be more than I can hope for.

I've looked at Tie::ShadowHash and it looks promising, but I'd need building blocks in a module that ties to a dispatch table.

Are there any tricks to do this elegantly with existing modules rather than writing my own tie module. I'm looking for building bocks and combinator methods that combine two tied hashes to make a new tied hash.

Replies are listed 'Best First'.
Re: Tie with dispatch table
by Limbic~Region (Chancellor) on Jun 08, 2005 at 12:38 UTC
    geekondemand,
    Are there any tricks to do this elegantly with existing modules rather than writing my own tie module. I'm looking for building bocks and combinator methods that combine two tied hashes to make a new tied hash.

    Well, Tie::Hash is a base class for tied hashes so your foundation is already in place. You just need to overide a few methods such as STORE (to make it read only) and FETCH (to check exists on the internal dispatch table and invoke or fall back to your default method).

    I will leave the implementation up to you, but please come back if you need help with specifics. If you need an example of a tied hash that uses multiple underlying datastructures (with support for initializing options in the constructor), take a look at Tie::Hash::Sorted. I used a hash and an array under the covers.

    Cheers - L~R