http://www.perlmonks.org?node_id=753582


in reply to Restricting @INC for specific application need

If you want to be sure certain modules are loaded from your application library, you can set @INC to include only the application library (or libraries as the case may be) rather than prepending the application library. In this way, if the module isn't in the application library it isn't loaded. For example:

#!/usr/bin/perl # use strict; use warnings; BEGIN { local @INC = ( "/opt/app/lib" ); eval "use Application::Module"; }

If the modules in your application library use modules from the standard library and assume a default @INC, then you can't change @INC when you use them but you can check %INC after they are loaded to ensure they are loaded form the correct location.

For example, if you wanted to load a patched version of File::Find from your application directory and fail if it was accidentally omitted from there you could do something like the following:

#!/usr/bin/perl # use strict; use warnings; use constant APPLIB => "/opt/app/lib"; use lib APPLIB; use File::Find; substr($INC{'File/Find.pm'},0,length(APPLIB)) eq APPLIB or die "File::Find incorrectly loaded from " . $INC{'File/Find.pm' +};