http://www.perlmonks.org?node_id=227897


in reply to Test::Exception extension with (evil?) overloading

I've only just started looking into Test::More and its kin, but the only other idea I have off hand is to pass a closure to a test function, to defer calling it until after the reusable code can throw an eval around it. That's what you mean by lives_and_is, right? Your complaint is that you have to duplicate all the tests to have a "lives" version.

So, you want to wrap the sub-ref argument so that it can orthogonally apply to all the tests.

Another way to have a modifier that applies orthogonally to all tests would be to pass the underlying test as well:

wrapper (\&innertest, \&subref, @args)
This would evaluate subref in an eval, failing if it dies. Then, take the result and pass it, along with the remaining @args, to the innertest function, whose result is returned.

So you could pass anything you want as the inner test.

wrapper (\&is, {$o->answer}, 42, 'answer returned 42');
—John