Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Restricting @INC for specific application need

by ig (Vicar)
on Mar 27, 2009 at 06:28 UTC ( #753582=note: print w/ replies, xml ) Need Help??


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' +};


Comment on Re: Restricting @INC for specific application need
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://753582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-08-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (277 votes), past polls