|Do you know where your variables are?|
Overriding bless for inside-out object safetyby xdg (Monsignor)
|on Jan 04, 2006 at 16:33 UTC||Need Help??|
I've been experimenting with some approaches for making inside-out objects a little more user friendly. (c.f. Anti-inside-out-object-ism for some of the common complaints). One of the more obscure issues has to do with thread-safety. I presented an approach for that in Threads and fork and CLONE, oh my!. I'm considering ways of making that more automatic and transparent.
One approach I've considered is a helper module that would override/redefine bless to register objects transparently for use in CLONE (which would also be imported automatically). Usage would be just as with a normal constructor:
Behind the scenes, this bless would do something like this:
$REGISTRY would also be used in CLONE to fix up inside-out objects during thread creation.
I'm a little cautious redefining something as critical as bless so I'd like feedback on this idea. Some specific questions I have include:
Side notes -- the example above is incomplete as inside-out lexical properties also need to be registered somehow for use with CLONE. (I'm working on a good, simple syntax for that.) The InsideOut::Helper name is also just a placeholder as I haven't come up with a name for this module, yet. (That said, what do people think about a new InsideOut top-level name to make a sharper distinction from the more traditional Class? I'm not sure it's needed, but I could see a case for it.)
Also, at least some inside-out generators automatically import a function like id as an alias to refaddr for use like this:
Do people feel this kind of aliasing is helpful or symbol pollution?
Your feedback is greatly appreciated.
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.