On 12/31/06, Paul LeoNerd Evans <[EMAIL PROTECTED]> wrote:
It does use Sub::Uplevel but I can't really see why. It seems only used
by way of hiding the internal functions from caller(), perhaps to neaten
up error messages or the like...? I can't see why a simple
implementation inline in the test script (see some of my other mails)
would need to use that, as long as the user was aware of the extra
lines.

Because Test::Exception uses code prototypes, what visually looks like
the eval block in the current package is actually an anonymous
subroutine that Test::Exception wraps and calls.  In *most* cases,
that doesn't matter, but consider this trivial example:

eval {
 die if not caller();
}
# check $@ per all caveats in the thread

dies_ok {
 die if not caller();
} "can we die?"

Without the Sub::Uplevel magic, the second example won't work as expected.

Where might this matter for real?  A couple example would be testing
functions that rely on caller() to modify a symbol table or to check
"public/private" permissions.

Test::Exception isn't like a preprocessor macro -- it changes the
semantics of how the code is called in non-trivial ways.

David

Reply via email to