Elizabeth Mattijsen wrote:
At 11:07 -0800 12/4/03, Stas Bekman wrote:

Elizabeth Mattijsen wrote:

Alternately, again _if_ you have blessed objects and you _do_ need to fix objects up after they have been cloned (hence the name "fixup" for this functionality), you can have a method of your own devise called on each instantiated object automagically after Perl has cloned it.

That's incomplete, because you won't call DESTROY on those fixedup/possessed objects. I suppose that you should check whether the user of your module provides the fixup callback and if it does DESTROY all objects (or make it configurable).


Actually, these are both configurable seperately. You can specify whether all objects have DESTROY called on them (including the cloned ones), or only the original ones. Default is only original ones.

And you can specify a fixup routine for cloned objects. Of which the default is none.

Sounds good. I wonder whether it's safe to assume that if fixup is provided than DESTROY should be called as well for the CLONED objects.


However, this only works on blessed objects, not on unblessed ones. On the other hand, you could decide to bless your SV to a special class just to get this functionality.

You mean double bless? My objects are already "blessed", but they don't use bless:
sv_setref_pv(ST(0), "Example::CLONE", (void*)RETVAL);


Hmmm... didn't realize you can create blessed objects from XS.

Moreover, I think that's what 99.9% of XS modules do. bless is really a non-XS module thing, and non-XS modules don't need the reconstruction anyway.


But yes, the actual bookkeeping routine could be made available externally, something like:

Thread::Bless->register( $object );

would that help?

Yes it would. In fact I'd suggest to drop the CORE::bless overriding thing altogether as you may interfere with similar overrides. Just tell users to call this register method from new(), just after they have blessed the object.


How about making your module more flexible and in addition to the overriden bless function provide a new_fixup methods, so one can choose to run new_fixup on already "blessed"/sv_setref_pv'ed object to store a weak copy of it? this can be called from the normal new().


Whether or not fixup routines are called, is determined by package, not by a single object. You _do_ need to register each single object though (which is done automatically if you use "bless").

Sure, your above:


Thread::Bless->register( $object );

is what I was after ;)

So the only remaining nice-to-have issue is to do COW for a better performance.


You could do that by having the fixup routine set a flag in/for the object that it has been COWed. Then, whenever you need to make changes, you check that flag and when it's set, _then_ you can do the real fixup.

That's right.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



Reply via email to