McA has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
once upon a time there was a hash introduced in our codebase. And the usage of that hash which was transferred to almost any function grew and grew. The usage of several keys cemented the "API" of that hash. After years I'm not happy with that because an object would have been the better approach (e.g. for the possibility to garantee the consistence of severals keys/value pairs). Now my question:
Is it possible to have somthing like Dr.-Jekyll-and-Mr. Hyde-object: A tied hash which is also blessed to be an object? Code would look like that:
my $obj = DrJekyll->new; $obj->{somekey} = 'something'; $obj->transform();
Everyone knowing the standard way of representing objects as blessed hash refs will now say: Yes, of course. With a simple blessed hash you can do that. But I want to have control over the access to a key. That means as soon as someone codes $obj->{somekey} = 'something'; I want a hook. That would be possible with tied hashes.
I hope this is an interesting question.
Best regards
McA
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Tieing ans Blessing
by tobyink (Canon) on Oct 05, 2012 at 09:13 UTC | |
Re: Tieing and Blessing
by McA (Priest) on Oct 05, 2012 at 09:34 UTC | |
Re: Tieing and Blessing
by anazawa (Scribe) on Oct 05, 2012 at 13:38 UTC | |
by anaconda_wly (Scribe) on Jan 07, 2013 at 09:24 UTC | |
by anazawa (Scribe) on Jan 26, 2013 at 15:27 UTC |