Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Conditional DESTROY

by BrowserUk (Pope)
on Jun 10, 2013 at 09:45 UTC ( #1038027=note: print w/ replies, xml ) Need Help??


in reply to Conditional DESTROY

You could try storing the flag outside of the object itself:

package whatever; my %customDestroy; sub new { my( $class, $flag, ... ) = @_; my $self = {}; ... $customDestroy{ $self } = 1 if $flag; return bless $self, $slass; } ... sub DESTROY { my $self = shift; if( $customDestroy{ $self } ) { ## special behaviour } else { ## normal behaviour } }

I think package lexicals should persist long enough to outlive instances, though I haven't tested the hypothesis.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Conditional DESTROY
Download Code
Replies are listed 'Best First'.
Re^2: Conditional DESTROY
by Ralesk (Pilgrim) on Jun 10, 2013 at 09:57 UTC

    See update and Corionís thread. It was unfortunately a really stupid PEBKAC involving messing around with //= and defining the $self->{no_DESTROY} to a non-undef value beforehand ó thus never actually setting it to 1 :( I must have been quite tired on Friday.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2015-07-29 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls