Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Speeding-up OO accessor methods

by demerphq (Chancellor)
on Feb 22, 2004 at 11:08 UTC ( #330916=note: print w/ replies, xml ) Need Help??


in reply to Speeding-up OO accessor methods

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.
    -- Gandhi



Comment on Re: Speeding-up OO accessor methods
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://330916]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-09-02 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls