taint has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Monks.

I looking to completely rebuild all the pages on a domain. In doing so, I want to work with libs/modules/packages that are in a state of flux. So I'll be useing libs relative to the domains web root. I tried

# for illustrative purposes only! define ('libs') /full/path/to/webroot/libs
Hmm... my version of Perl seems to be missing define. :(
OK. You get my point. My question is;
How can I best insure that however deep I'm in the web tree, libs is always known to be off of web root?
use lib ('/libs');
I looked at trying to coerce base into something useful. But that didn't look like a very good answer. I did consider blib, which is basically intended for such things. But aren't sure it's the best choice. For the most part, the pages aren't dynamic yet. But I'm hoping to find the most efficient way to handle this. Any, and all suggestions appreciated.

Thanks.

--Chris

#!/usr/bin/perl -Tw
use Perl::Always or die;
my $perl_version = (5.12.5);
print $perl_version;

Replies are listed 'Best First'.
Re: How to best "use lib" relative to a web site root?
by davido (Cardinal) on Nov 27, 2013 at 21:00 UTC

    See FindBin. Its POD's SYNOPSIS should be enough to get you going.

    Update: Also, if you generate an "app" with Mojolicious, you'll see that the app executable starts with this:

    use FindBin; BEGIN { unshift @INC, "$FindBin::Bin/../lib" }

    ...which is similar to the FindBin SYNOPSIS, but avoids the use of the lib pragma (not sure why).


    Dave

      Thank you, davido.

      I looked at that in perldoc, and also thought that to be a strong candidate (created for Mac filepath munging), but wasn't sure it'd fully accomplish my goal. I'll give it a go. While I'm at it, I'll see if I can deduce what would cause them to eliminate the lib pragma. Should provide me a great deal more insight on the very question I asked here. :)

      Thank you, davido. For taking the time to respond.

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: How to best "use lib" relative to a web site root?
by Anonymous Monk on Nov 27, 2013 at 23:14 UTC
    File::FindLib - Find and use a file/dir from a directory above your script file