Elizabeth Mattijsen wrote: [...]
... 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.
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.
But in which context is CLONE() called then? Only in the context of threads, isn't it?
What I meant is that most CPAN modules are working with and without threads. So you can't just 'use Thread::Bless;' if the code happens to run under non-threaded perl. Since you will have to do:
require Thread::Bless; Thread::Bless->import();
without even importing anything, it's a at least confusing ;)
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.
No objections here. Again it looks like we are talking about different things ;)
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.
but you still need to call import(), which doesn't import anything, please see above.
Just 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.
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 call
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 $_} = $_ );
}
I think it just shouldn't be called at all if it's not defined.
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 see, the overriden bless gets the register function from Thread::Bless, so it always finds it. For some reason I thought it won't find it if bless() is called from a totally unrelated module. Still your overriden bless now calls functions unnecessary if not used in the context of Thread::Bless, which is bad, IMHO.
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
Sounds good, but probably you need to use a more intuitive API. The suggested API tells me absolutely nothing about what it's going to do.
use Thread::Bless single_destroy => 1;
you get the package from the caller.
and again, you can't always call use, so it'll be ugly to call:
require Thread::Bless; Thread::Bless->import(single_destroy => 1);
so better give it a proper class method name?
Thread::Bless->single_destroy(1);
and then you could make import perform the syntax sugar:
Thread::Bless->import('single_destroy');
which allows you to expand the module functionality, without breaking anything. Just like @IMPORT is a bad idea, doing what you do in import by default is a bad idea too. Make it flexible and your modules will still use a short one liner to enable all the functionalities that you need, without hurting anybody.
Finally I think Thread::Bless is a not a very good name for the functionality it provides. I think you have a collection of utils to make modules work correctly under perl ithreads, and almost none of them has anything to do with bless (e.g. DESTROY doesn't) and most XS modules don't use bless. I don't think potential users of it will realize that they need this module, unless referred by documentation. What do you think about dropping that package and start afresh with a better name and better API, which we can also run through p5p and may be add a few other utils missing from threads.pm? I won't be surprised if we will end up with threads::utils and it'll be part of the CORE (And on CPAN). if you decide to keep Thread::Bless alive you could then simply inherit from threads::utils to do what it does now. But it'll be just confusing.
By the way, are we in agreement that "fixup" should be called "post_clone_reconstruct"?
Heh, at least we still have some related discussion to the subject of my email ;)
I'd go with clone_reconstruct() if it's fine with you.
__________________________________________________________________ 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
