|Pathologically Eclectic Rubbish Lister|
RFC: Lexical Fatal.pm for Perl 5.10by pjf (Curate)
|on Mar 09, 2008 at 05:35 UTC||Need Help??|
Most esteemed monks,
I've long been a fan of Perl's Fatal module, which allows one to replace both user-defined and built-in functions with equivalents that throw an exception on failure. However due to the limitations of Perl before 5.10, Fatal had a package-wide scope, and this would keep me awake at night. What if someone introduced Fatal to their legacy code and introduced/revealed new bugs, due to Fatal's wide-reaching consequences?
However with the powers of Perl 5.10 and the %^H lexical hints hash, we have the power to create Fatal-style changes with only lexical scope. I've put together a proof-of-concept pragma to do this, which currently works as follows:
The code as it stands has a few adjustments that I need to make, and obviously a lot of tests to ensure that code this cool works correctly. I'm primarily looking for interface and naming suggestions, although I'm happy for this to start a broard discussion.
Some matters I'm still considering:
Those who are curious should also know that this module is currently being discussed on email@example.com. If you really want you can also download my proof of concept, but you should be aware that's it's unfinished, buggy, emits warnings, ugly, is poorly documented and should not be used for production code. Using the code, or even looking at it, may cause the Earth to fall into the sun and your hair to fall out. It also only works under 5.10. It's a proof of concept, not a finished piece of art. I am seeking feedback on the interface, not the code, at this time.
Thanks in advance for all your thoughts,
Update: After many discussions on p5p it looks like we'll be getting a new Fatal.pm module with 5.10.1. The new pragma version will be called autodie.