title: Pretending an Autoloaded Function has a Block Prototype
body: <p>Let's say I have a subroutine that takes a sub as argument.</p>
  <pre><code>sub foobar {
      my $block = shift;
      $block-&gt;();
  }
  </code></pre>
  <p>Then I can call it like so</p>
  <pre><code>foobar(sub { print &quot;Hello :)\n&quot; });
  </code></pre>
  <p>I can also use block syntax if I declare it with an appropriate prototype.</p>
  <pre><code>sub foobar(&amp;) {
      my $block = shift;
      $block-&gt;();
  }
  
  foobar { print &quot;Hello :)\n&quot; };
  </code></pre>
  <p>Now, suppose that my function doesn't actually exist and is an AUTOLOAD, such as</p>
  <pre><code>sub AUTOLOAD {
      $AUTOLOAD =~ s/.*:://;
      if ($AUTOLOAD eq &quot;foobar&quot;) {
          my $block = shift;
          $block-&gt;();
      } else {
          die(&quot;No such function $AUTOLOAD&quot;);
      }
  }
  </code></pre>
  <p>We can still call it with an explicit <code>sub</code></p>
  <pre><code>foobar(sub { print &quot;Hello :)\n&quot; });
  </code></pre>
  <p>And we can eliminate unnecessary parentheses by predeclaring the subroutine.</p>
  <pre><code>use subs 'foobar';
  
  foobar sub { print &quot;Hello :)\n&quot; };
  </code></pre>
  <p>But I can't get the block syntax back if my function doesn't <em>actually</em> exist and have a prototype. I'd like to be able to do this</p>
  <pre><code>foobar { print &quot;Hello :)\n&quot; };
  </code></pre>
  <p>Assuming I know the name <code>foobar</code> in advance and can predeclare things as needed (as I did with <code>use subs 'foobar'</code>), is there any way I can convince Perl that <code>foobar</code> takes a block argument, despite only having access to <code>foobar</code> through an AUTOLOAD?</p>
  <p><strong>Note:</strong> This is not production code and never will be. I'm asking out of curiosity and to potentially use tricks like this in programming puzzles / challenges, so readability and maintainability is not a concern.</p>