Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: die in a DESTROY

by water (Deacon)
on Sep 28, 2005 at 00:24 UTC ( #495598=note: print w/ replies, xml ) Need Help??


in reply to die in a DESTROY

Ok. I don't think  exit is right for me; I am writing a module and would like the code which uses it to have the option to trap it with eval.

The gist of the module is a series of pushes onto a stack, which then get sent to a DB upon request. The send-to-DB is an explicit call. I've got a DESTROY that checks the stack is empty (either never was pushed, or was pushed but then properly sent off to DB) when the object goes out of scope.

I want the DESTROY do something like this

# untested sub DESTROY { my ($self) = @_; die "destroy called with non-empty stack" if $self->stack_count; }
Now, the caller could trap this die if they knew what they were doing, or if they didn't, they'd get a fatal die if they used the module improperly (eg not calling send-to-DB).

So that's what I want to do:

die from a DESTROY in such a way isn't caught by the DESTROY itself, but could be caught (eg eval) by a module user.

Do I have any shot at getting this behavior?

water }


Comment on Re: die in a DESTROY
Select or Download Code
Replies are listed 'Best First'.
Re^2: die in a DESTROY
by sauoq (Abbot) on Sep 28, 2005 at 05:30 UTC

    Now that you've explained what you want, it seems this is a difficult problem. I played with it a bit, trying some obvious things with caller and such to no avail. I'm guessing you'd have to resort to using B to cobble together a workaround.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2015-07-31 10:34 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 (276 votes), past polls