It's a slow Saturday, so I thought I'd ask a question here that I'm sure I'm already missing the answer for.
So, I like my tests to pass on all platforms, but pre v5.14, eval had some issues. Instead of modifying my code to work around those (because my understanding is that you need to do trickery around the eval within the module), or using external modules (Try::Catch, Try::Tiny), instead, I wrote my test like the following example code. Is this reasonable, or are there holes in doing things this way, that could possibly cause issues for newer versions of perl where eval actually does The Right Thing?
What happens is, that my test calls an object method, and that method creates a (temporary, ie. it goes out of scope within the method call) internal object of its own class. The new temp object, based on calls within the method call being tested has at least one eval in it (which, based on docs in Try::Tiny and other reliable sources state that using $@ in pre-v5.14 isn't good (because it's global) due to clobbering), clobbers $@ with a successful pass, and my check for $@ fails horribly.
{
$SIG{__DIE__}
= sub { ok (1 == 1, "if the thing with the guy in the place, we
+croak"); };
# $obj->blah() croaks() guaranteed, but it creates a
# temp object of its own class, which has eval() and
# clobbers $@, so $@ is always '' when things return
# back to the test
eval { $obj->blah(do_this => 1); };
}
Is this a safe way to work around the versions of perl that have broken eval without modifying module code, or is there a better way (without having to add any code to the module being tested)? Also, does doing things in this fashion compromise latter tests/test files?