http://qs1969.pair.com?node_id=520952

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:

package My::Class; use InsideOut::Helper qw( bless ); sub new { my $class = shift; my $self = \do { my $scalar }; bless $self, $class; }

Behind the scenes, this bless would do something like this:

my $REGISTRY; sub bless { &CORE::bless; $REGISTRY{ $_[1] }{ refaddr $_[0] } = $_[0]; return $_[0]; }

$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:

my $NAME_OF{ id $self } = "Larry"; # instead of my $NAME_OF{ refaddr $self } = "Larry";

Do people feel this kind of aliasing is helpful or symbol pollution?

Your feedback is greatly appreciated.

-xdg

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.