in reply to Getting around $? setting in END blocks

But we're using 5.6.1 and Manip::END requires 5.8.0.
I'm not so sure (in fact, i'm pretty sure it will work on 5.6.x). Yes, the Makefile.PL says use 5.008;, but the module does not, which leads me to believe that the use 5.008; in the Makefile.PL is just a h2xs artifact the author forgot to remove (and i'm right). This is a typical problem.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: Getting around $? setting in END blocks
by fergal (Chaplain) on Aug 26, 2004 at 22:34 UTC
    I think you're right (I can't remember) and I never tested it on anything else as it was more a proof of concept than a serious module. That said, it does work.

    A new version should be on CPAN by the time you read this. It removes the 5.8 dependency and also fixes a small bug in the error reporting, was it you who sent me the patch on RT?

    As for the original question, the best way to add an END block is by writing an END block! If you want it to be triggered before all the others, put it at the end of your program, if you want it to be triggered after all the others put it at the start, before any use or require . A combination of the two can solve your problem.

    my $saved_value; END { $? = $saved_value } # this will be the final END block #### your program goes here #### using whatever modules you want END { $saved_value = $? # } # this will be the first END block
    The only thing that could go wrong with this scheme is that something could pull in a module containing another END block using require or eval "use something" and that END block could fiddle with $? before you get to save it. If this is happening you could try calling my_exit instead where
    sub my_exit { my $value = shift; $saved_value = $value; exit $value; }