ELISHEVA has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|