package STR;
use Class::Std::Fast cache => 1;
## ---------------- ---------------- ---------------- ##
package main;
use threads;
use 5.010;
use strict;
use warnings;
STR->new; # create and immediately throw away.
# Now do something completely different with threads:
threads->create( sub { sleep 2 && say "thread $_" } ) for 1..4;
$_->join for threads->list;
[download]
What doesn't work:
sub _cache_class_ref () {
croak q{you can't call this method in your namespace}
if 0 != index caller, 'Class::Std::';
return \%do_cache_class_of;
}
[download]
Another avenue seems to be to dynamically override Class::Std::Fast::DESTROY, but doing this in a way that preserves all the original behaviour except caching would get very complex. Finding out if these behaviours even need to be preserved is even more complex.
Note: I'm not actually using Class::Std::Fast directly, I'm using SOAP::WSDL, which via 5 intermediate steps comes back to Class::Std::Fast. My real code is dying with
DESTROY created new reference to dead object
'SOAP::WSDL::XSD::Typelib::Builtin::string' during global dest
+ruction (#1)
[download]
Does anyone have any suggestions?
You have 3 options.
clean_cache: {
no warnings qw<redefine once>;
local *Class::Std::Fast::croak = sub {};
use warnings;
delete Class::Std::Fast::_cache_class_ref()->{STR};
}
[download]
Have you (or anyone) actually run any benchmarks to see how much time using this cache option actually saves?
Because in my (admittedly simplistic) tests, it actually runs slower! Only by a microsecond or two, but still slower.
And when I look inside and see that the only thing it caches is the scalar ref used as an id, that makes sense. That is, it makes sense that it is slower.
It makes no sense (to me) to cache this at all. Indeed, if the caching was removed completely, it would run faster still because of the absence of the 'is-it-cached' tests.
And without the caching, the OP problem just 'goes away'.