I don't really want to dredge up all the tricks and traps I've come across dealing with these handlers, but I did want to at least mention the general attitude I came away with.

These handlers are one of the last bastions of action at a distance in Perl, and they cause no end of trouble. The best approach you can have to them is to avoid them entirely; however, some problems just don't seem to be as easily solved (or maybe solved at all) without them.

If you're writing a generic module to catch __DIE__ or __WARN__ that anyone can use, and that will interact well with other code trying to do the same thing, good luck. You'll need it. However, if you're trying to design a framework that will be largely consistent throughout it becomes a bit easier. I wrote a small web framework a long time back that relied on it. I wouldn't recommend it.

My best recommendation to avoid __DIE__ handlers in particular is to make heavy use of block eval and die. __DIE__ is essentially a try/catch design turned inside out; turning it back right-side in might be a far better approach.


In reply to Re: die/warn signal handler best practice questions by Somni
in thread die/warn signal handler best practice questions by bsb

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.