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
} |