I'm working with a CPAN package that has decided to make its error handling customizable via a global variable storing an error handling subroutine. I'm really not sure how to best to extend the package and would like your collective wisdom.

I need to override the default handling because the default version returns a localized error string. In my extension I need to make my error handling conditional on the type of error. I don't want to trap and parse locale specific strings to guess the type of error. Fortunately the underlying API has locale independent error constants I can use instead. However, I only have access to those constants if I provide my own error handler.

Now here is the dilemma: if I set the global variable for the error handler sub directly (no localizing), then I run the risk of clashing with other CPAN modules I might want to use that also set the global variable. I also risk clashing with any consumer code of my module that wants to set their own handler. They may throw an error object I don't expect or I may throw an error object they don't expect. Neither is a "good thing".

If I localize the variable that stores the error handler, my extension is insulated from clashes, but now I've violated the user's expectation that they can customize error handling any way they wish. I don't like changing documented features.

So what is the best way to handle this? - do I

Also, is there a more stable Perlish way to allow some measure of customization for error handling? I think all of the above choices are lousy and would rather not put someone in the position of having to choose amongst them for any module I write.

Many thanks in advance, beth


In reply to What is the best way to extend packages with global error handlers? by ELISHEVA

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.