|Welcome to the Monastery|
Re: autodie with non-builtinsby pjf (Curate)
|on Feb 17, 2009 at 11:06 UTC||Need Help??|
Okay, I've done my research. It looks like autodie won't trigger when used with a user-defined sub if and only if that sub is called in array context, and it returns something other than an empty list/undefined to indicate failure.
The reasons for this is that autodie has to make assumptions about user-defined functions, including those from modules such as File::Copy. It always considers an undefined value to indicate failure in scalar context, and it also considers a list consisting of a single undefined a failure, due to the large amount of code that does a return undef regardless of context.
The bug lies in how it handles the value zero. Presently (as of 1.998) it considers any scalar false to be a failure, on the assumption that foo() or die is a common idiom for checking errors. It doesn't consider an array consisting of a single (defined) false value to be an error, since it's quite conceivable that a function that routinely returns a list could return this as valid data.
This behaviour may not be correct, but it's rather late on my side of the world, and a week of international travel has left me short on sleep. As such, I'll be examining it in more detail in the morning.
In the meantime, if you use mv (or any other File::Copy subroutine) in void context (ie, without say), then it should work just fine with autodie.
Perl Training Australia