title: After scoped `no autodie` the program dies at `*STDOUT`
body: <p>This program</p>
  <pre><code>use warnings;
  use strict;
  use feature qw(say);
  
  {
      #use autodie;   # all good when this is uncommented
      no autodie;
  }
  
  open my $OLDSTD, '&gt;&amp;', *STDOUT;        #--&gt; line 10 (program fails)
  open *STDOUT, '&gt;', 'stdout.out';
  
  say &quot;$$ done&quot;;
  </code></pre>
  <p>aborts with</p>
  <pre>
  Undefined subroutine called at problem_no_autodie.pl line 10.
  </pre>
  <p>To restate the comment in code: if there is a <code>use autodie;</code> statement first then all is well. (All is well with only <code>use autodie;</code> as well.) Curiously, in the same scope with <code>no autodie</code> statement I see no such problems either; only code outside of its scope fails! Kinda anti-scoping, eh?</p>
  <p>If this scoped <code>no autodie</code> comes <em>after</em> the use of <code>*STDOUT</code> then it's all good again. Further use of <code>*STDOUT</code>, after (the scoped) <code>no autodie</code>, fails the program.</p>
  <p>There is a <a href="https://perldoc.perl.org/autodie.html#GOTCHAS" rel="nofollow noreferrer">Gotcha</a> mentioned in docs that involves barewords (which I don't fully understand), and the program indeed fails with <code>STDOUT</code> -- but I have it as <code>*STDOUT</code>.</p>
  <p>So it appears that <code>*STDOUT</code> is treated as a user's sub, but I don't understand that nor how the scope of <code>autodie</code> gets defeated.  (Scope leakage is mentioned as a bug in some versions but in a seemingly unrelated way.)  And there is a practical problem with this.</p>
  <p>I don't use <code>autodie</code> in my code. But consider this sub, which I do use</p>
  <pre><code>sub isatty {
      no autodie;
      state $isatty = open(my $tty, '+&lt;', '/dev/tty');
      return $isatty;
  }
  </code></pre>
  <p>It is legitimate for that <code>open</code> to fail, so we have to disable <code>autodie</code> in that scope in case the user of the sub has it on. Then is the described behavior going to hurt? Under what circumstances?</p>
  <p>I am puzzled by this effect of <code>no autodie</code> and by its leakage out of its scope, and by all their strange details. But the real concern is that I am not sure how to protect the code that uses a library like the one above against that behavior, since I don't understand it. Any ideas?</p>
  <p>I see this under 5.16.3 (system), 5.26.2 and 5.30.0 (perlbrew) on CentOS 7.8</p>
  <p>I <em>do not</em> see this behavior on 5.32.0; no failure there.</p>
  <hr />
  <p><em>The <code>... or die $!</code> check with <code>open</code> didn't make any difference so it's not shown for simplicity.</em></p>