:) (obvious pun avoided)
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 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:
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
};
Perl is loading the module twice, resulting in "subroutine X redefined" errors.
This works, BTW, though I'm not sure it is proper (or even, exactly how).
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 ();
};