Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: autodie with non-builtins

by pjf (Curate)
on Feb 17, 2009 at 11:06 UTC ( #744358=note: print w/ replies, xml ) Need Help??


in reply to autodie with non-builtins

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.


Comment on Re: autodie with non-builtins

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-07-31 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls