Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^8: Modern Perl Programming Highs and Lows

by diotalevi (Canon)
on May 10, 2009 at 16:36 UTC ( #763143=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Modern Perl Programming Highs and Lows
in thread Modern Perl Programming Highs and Lows

Well... you neglected to account for DESTROY { eval {} } and DESTROY { die } for any objects created in your test code. You failed to account for buggy overloading in exception objects. To do all of that correctly you've got to use the return value of the eval{} to decide failure, hook and unhook $SIG{__DIE__}, save $@ so when you stringify it, you don't accidentally cause it to clobber itself.

Perl exception handling is actually a garden of pain.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊


Comment on Re^8: Modern Perl Programming Highs and Lows
Select or Download Code
Re^9: Modern Perl Programming Highs and Lows
by educated_foo (Vicar) on May 10, 2009 at 22:45 UTC
    Those things you mention fall into the "doctor, it hurts when I do this" category. Normal code shouldn't need DESTROY at all, and if it does, it should be extremely careful. And if you're creating complex overloaded exception objects, you have already lost. What does your test module's overloaded $SIG{__DIE__} do with a module that itself overloads $SIG{__DIE__}?

    Sure, it's possible to build ever-more-complicated exception mechanisms with lots of corner cases, and to require more testing modules to control them. Sometimes you may even be forced into this silliness. But since you're inviting a world of hurt by doing so, you should ask yourself first whether a simpler solution could work.

      No, none of this is "it hurts doctor" stuff. It's quite normal to have exception objects. It's normal for exception objects to have stringification. It's unusual but not not bad to have a destructor. It is bad to fail to protect your caller against $@ clobbering but mistakes can happen. It's pretty unusual to see your tests $SIG{__DIE__} get overridden and it's worth automating the instrumentation of that happening. Mostly, I really like Test::Exception because with perl, you must be paranoid and this lets me outsource my paranoia.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://763143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-09-17 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (87 votes), past polls