<?xml version="1.0" encoding="windows-1252"?>
<node id="1018100" title="Re: Redefining Imported Subs: of scope and no" created="2013-02-11 01:10:49" updated="2013-02-11 01:10:49">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;How do I dynamically redefine imported subroutines?&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;That's actually quite easy, but &lt;c&gt;say&lt;/c&gt; is not being imported; it's not even a subroutine! &lt;c&gt;say&lt;/c&gt; is an operator, and &lt;c&gt;use feature 'say';&lt;/c&gt; merely controls whether the compiler recognises it or not. (It always recognises &lt;c&gt;CORE::say&lt;/c&gt;, though.)

&lt;p&gt;Some operators can be overridden from within Perl by overriding &lt;c&gt;GLOBAL::CORE::op&lt;/c&gt;, and some can't. The following checks whether &lt;c&gt;say&lt;/c&gt; can be overridden this way:

&lt;c&gt;
&gt;perl -E"say defined(prototype('CORE::say')) ?'yes':'no'"
no
&lt;/c&gt;

&lt;p&gt;Its funky syntax doesn't permit it.

&lt;c&gt;
say
say LIST
say FILEHANDLE LIST
say BLOCK LIST
&lt;/c&gt;

&lt;p&gt;It could be done using a CallChecker, but that involves dropping to C/XS.
</field>
<field name="root_node">
1017898</field>
<field name="parent_node">
1017898</field>
</data>
</node>
