Perl calls a subroutine reference in @INC
when it is traversing @INC
to look for a module. That is, you'll trigger it when you try to load a module with use
or require
and Perl does not find that module in the preceding @INC
locations.
BEGIN {
push @INC,
sub { print "Oops: There was an error looking for $_[1]
"; };
}
eval "use Cat::Burglar";
eval "use Local::NotThere";
require Cat::Burglar;
You need to ensure that your subroutine reference is in @INC
before you try to load the modules. Remember that use
is a compile time feature and that require
is a run time feature. As with adding other "regular" @INC
entries, you probably want to do it in a BEGIN
block as early as possible in your program.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…