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'
+};
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|