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

In reply to Re^2: Getting around $? setting in END blocks by fergal
in thread Getting around $? setting in END blocks by DrWhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.