Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Throw from within a DESTROY block

by ribasushi (Monk)
on Sep 07, 2011 at 02:55 UTC ( #924509=note: print w/replies, xml ) Need Help??


in reply to Re^5: Throw from within a DESTROY block
in thread Throw from within a DESTROY block

When the business logic is tied to "at time of object destruction", there is no practical way to put the code into "delete". See tye's reply for a very good round-up of the DESTROY-based "guard pattern"
  • Comment on Re^6: Throw from within a DESTROY block

Replies are listed 'Best First'.
Re^7: Throw from within a DESTROY block
by ikegami (Pope) on Sep 07, 2011 at 03:20 UTC

    Oh, I thought you were saying you could use guard logic to fix your program.

    I was confused because what you are saying is a complete non-sequitor. I didn't say you should always move code out of destructors. I'm well aware of the value of a destructor (and of tye's solution).

    You ask for cheats to solve your particular case, but every time I provide one, you say it won't work in all circumstances. I'll say it again even though you said it was incendiary to say so, but that's not how Perl works.

    If a particular solution doesn't work for your, say why, but don't say it can never work.

      See the updated root: http://www.perlmonks.org/?node_id=924488
        What did you change? Highlighted "behaviour"? Everything I suggested allows you to get the same behaviour.
Re^7: Throw from within a DESTROY block
by ikegami (Pope) on Sep 07, 2011 at 03:02 UTC
    I don't see it. See I nothing practical in tye's reply, just how it should behave.
      Quoting from http://www.perlmonks.org/?node_id=924499:

      But the wonderful value of DESTROY is that every c'tor (constructor) that succeeds will always be followed by its paired d'tor, which makes it a very valuable tool for the sane handling of tons of things (all manner of resource allocation but also other things that should always be done in pairs, like transactions, reference counting, etc.). And handling tons of things means that you need to be able to deal with that handling going wrong or failing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://924509]
help
Chatterbox?
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-29 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.