Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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


Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://330916]
help
Chatterbox?
LanX God shaves the Queen!
[marto]: plastering
LanX citing Sean Connery
[LanX]: met a guy from Aberdeen durin holidays, liked Scotsish accent a lot ... very phonetic

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-02-19 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (261 votes). Check out past polls.

    Notices?