in reply to Re: Re: Re: DESTROY and DBI
in thread DESTROY and DBI
Hmmm, you don't need the total encapsulation features of the FlyweightWrapper, either...
I'm betting packages get unloaded correctly. What happens if you add a hash at the package level in your class called instances, and do this:
Offhand, I can't remember whether calling DESTROY directly is ok or not, but if not, you could get the same effect with a helper sub that DESTROY calls.# private hash of instances my %instances; #... sub new { # ... build up $self, bless it, do whatever $instances{$self}=1; # ... whatever else you need to do... } #... sub DESTROY { # don't double-destroy return unless $instances{$self}; #... do whatever $instances{$self}=0; } END { foreach my $instance(keys %instances) { $instance->DESTROY() if $instances{$instance}; } }
Edit: I forgot to check $instances{$self} at the top of DESTROY
|
|---|