Elizabeth Mattijsen wrote:You are talking about a totally different thing. Reconstruction of the C struct and DESTROY, while related, aren't the same thing ;)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.No true. I had to jump through these hoops for just about all Thread::xxx modules I made, e.g. Thread::Pool. You don't want the pool destroyed when one of the worker threads exits... ;-)
You are right... ;-) Must have been half asleep already... ;-)
Again, what I was saying is that bless() is normally not used by XS modules. I made no comments regarding DESTROY...
You're right. Sorry for the confusion...
It depends on your definition of "the general case". I think you are a bit biased on this aspect as most of your modules already require 'threads' ;) I doubt it's a general case. A general case is a CPAN module interfacing C structs which should work with and without threads. And which most likely doesn't call bless() anyway.... In fact I'd suggest to drop the CORE::bless overriding thing altogether as you may interfere with similar overrides.It honours whatever overrides for CORE::bless existed already. And it makes the general case (which I think just the not DESTROYing of cloned objects) very easy to add: just add:
use Thread::Bless;
to your module's code.
But in which context is CLONE() called then? Only in the context of threads, isn't it?
Thread::Bless is all about "corrective actions" as the result of a blessed object being cloned. Whether they happen just after being cloned ("fixup" or "post_clone"reconstruct") or when the object goes out of scope (DESTROY), it's all about threads.
If you consider that I need to use this module only when I have 5.8.x w/ threads, I can't use() it, but require() it and then figure out what to import. The register things, etc, etc...
The import routine is not used to export anything: it just runs the right class methods for you. Nothing is exported, everything is done with class methods.
Well, I'm not very keen on overriding CORE:: functions in the complex systems with multiple modules from different sources (think mod_perl). You override CORE::bless whether I need it or not and it affects all other modules. It'll always callJust tell users to call this register method from new(), just after they have blessed the object.That goes against the principle of least interference. To me, this is really a problem that should be fixed at the system level, e.g. with a pragma.
register( __PACKAGE__,$object );
even for objects which have nothing to do with Thread::Bless. I suppose this is just a bug that needs to be fixed.
The condition whether or not to actually register the object, is inside the "register" routine. I did it that way so that when you try to register objects of a class that is not supposed to be handled, it will simply not register it. Maybe it should croak in that case, what do you think? The register sub is basically:
shift;
foreach (@_) {
next unless my $settings = $handled{blessed $_}; # this should maybe croak?
weaken( $settings->{'object'}->{refaddr $_} = $_ );
}
But you probably weren't aware of it, since you haven't used it with other modules that use bless by themselves, so there could be other side-effects we haven't thought of.
Good point. I though I had added tests for it. But I didn't. Tests are now added for it and it works as expected (not handled classes have their DESTROY called always).
I think instead of overriding CORE::bless, you should optionally import bless into the caller namespace, in which case it won't affect other modules. So your modules will still be simple but call:
use Thread::Bless qw(bless);
Well... yes, that could be done. However, I also want to be able to "fix" modules externally with Thread::Bless. If you know that a module is suffering from multiple DESTROYs particularly. A scenario:
use threads; use Thread::Bless package => 'Foo'; use Foo; # this pre-threads module suffers from multiple DESTROY syndrome
By the way, are we in agreement that "fixup" should be called "post_clone_reconstruct"?
Liz
