<?xml version="1.0" encoding="windows-1252"?>
<node id="1007736" title="Re^2: Cancel/no-op a require" created="2012-12-07 08:36:36" updated="2012-12-07 08:36:36">
<type id="11">
note</type>
<author id="904273">
sedusedan</author>
<data>
<field name="doctext">
&lt;p&gt;:) (obvious pun avoided)

&lt;p&gt;My problem at hand is actually grok-ing the @INC import hook API and avoiding duplicate importing. I'm trying to add a feature to [mod://Log::Any::For::Package] to install import hook. If user specifies Foo::* in the list of packages to add logging to, then after some Foo::* module is loaded, I want the hook to add logging to the newly loaded package automatically. With this:

&lt;p&gt;&lt;code&gt;
unshift @INC, sub {
    my ($self, $name) = @_;
    
    # load the module first
    local @INC = grep { !ref($_) || $_ != $self } @INC;
    require $name;

    # add logging to the package

    # instruct Perl to not load the module again
};
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Perl is loading the module twice, resulting in "subroutine X redefined" errors.

&lt;p&gt;This works, BTW, though I'm not sure it is proper (or even, exactly how).

&lt;p&gt;&lt;code&gt;
unshift @INC, sub {
    my ($self, $name) = @_;
    
    $INC{$name} = 1;

    # load the module first
    local @INC = grep { !ref($_) || $_ != $self } @INC;
    require $name;

    # add logging to the package

    return ();
};
&lt;/code&gt;&lt;/p&gt;
</field>
<field name="root_node">
1007731</field>
<field name="parent_node">
1007733</field>
</data>
</node>
