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.


In reply to Re: autodie with non-builtins by pjf
in thread autodie with non-builtins by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.