Skip Menu |

This queue is for tickets about the Perl-AtEndOfScope CPAN distribution.

Report information
The Basics
Id: 36647
Status: resolved
Priority: 0/
Queue: Perl-AtEndOfScope

People
Owner: Nobody in particular
Requestors: johanl [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.01
Fixed in: (no value)



Subject: Problems when dying
We just encountered a problem with AtEndOfScope in combinatin with dying code. Something like this (untested): sub a1 { my $update_import_row = Perl::AtEndOfScope->new( sub { $self->import_row->update() }, ); die("Oops\n"); } eval { a1(); }; print "Gaah\n" if $@; This all seemed to work fine until something in update() also died. Presumably, leaving the scope by something dying and unwinding the call stack is pretty normal and within the expected behaviour. However, dying changes global state i.e. $@. And since arbitrary code can be run inside the AtEndOfScope subref, that may very well reset $@. That is what happened to us. Something like this in AtEndOfScope would keep the $@ value safe during the AtEndOfScope code execution: sub DESTROY { my ($fn, @args)=@{shift()}; local $@; &{$fn}(@args); } Maybe there are other globals that would need to be localised as well, but $@ seems central since it's pretty normal to leave a scope by an exception being thrown. /J
see Version 0.02