Do you know where your variables are? | |
PerlMonks |
Re: Speeding-up OO accessor methodsby demerphq (Chancellor) |
on Feb 22, 2004 at 11:08 UTC ( [id://330916]=note: print w/replies, xml ) | Need Help?? |
I think a better idea is to use a tied hash as the basis of your class in testing and development, and an untied hash in production release. This way you bypass the requirement for converting from method syntax to hash syntax using a regex. All attributes of the objects are accessed via hash notation. The tie ensures that the keys and values are legal, etc. Then when you switch out of development/test mode, you disable the tie and get the speed benefit of pure hash accesses. You could even selectively enable the tie as required. I believe that Damian Conway wrote Tie::SecureHash with this in mind, with the added benefit of namespace rules to aid in subclassing. But I think it may also be worth hand coding in some cases.
---
demerphq First they ignore you, then they laugh at you, then they fight you, then you win.
In Section
Seekers of Perl Wisdom
|
|