Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I "use lib" the appropriate directory depending on installation location?
    primarykey
    data
    text
    <p>I have an object-oriented web-app that is installed in multiple locations on my server. Once for "live", once for "beta", etc. Being object-oriented, it consists of many perl modules. In the main module, I must "use lib" the appropriate directory for all of the <em>custom</em> perl modules for that instance of the app.</p> <p>This is no big deal, I have a BEGIN block that checks the location of the main program and sets the library directory appropriately. However I also have a lot of utility, command line programs that need to do the same thing. I don't want to cut and paste this code everywhere.</p> <p>What is the best way to share this code snippet amongst the various programs that need it? </p> <p>I can't "use" it because the libary path isn't set up yet. Maybe "do" or "require" would the be the right answer, but both of those will search @INC, which is inappropriate. </p> <p>Maybe something like <code>eval `cat GetLib.pl`;</code> would be appropriate but it seems kind of clunky and fragile.</p> <p>Here is the BEGIN block that I currently use:</p> <pre><code>BEGIN { use FindBin qw ($Bin); require lib; if ($Bin =~ /^\/home\/w\/myapp_live/) { lib-&gt;import('/home/w/myapp_live/lib'); print STDERR "live site\n"; } if ($Bin =~ /^\/home\/w\/myapp_beta/) { lib-&gt;import('/home/w/myapp_beta/lib'); print STDERR "beta site\n"; } if ($Bin =~ /^\/home\/w\/myapp_test/) { lib-&gt;import('/home/w/myapp_test/lib'); print STDERR "testing site\n"; } } </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload