Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Restricting @INC for specific application need

by ig (Vicar)
on Mar 27, 2009 at 06:28 UTC ( [id://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' +};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found