Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
What are you thoughts about using Cwd::abs_path() instead of $FindBin::Bin?
Motivation
In Mojolicious the auto-generated application script contains:
use FindBin; BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
The issue I have with this is: $FindBin::Bin will not resolve a symbolic link. This can be fine in cases where you want to use different libraries with the same script. Simply create a symbolic link of the script to the location where your different libraries are.
But in my situation I simply wanted to create a symbolic link of the startscript to /usr/local/bin. Of course this is doomed to fail as I will end up with "/usr/local/bin/../lib". But the libraries are in "/app/myapp/lib".
So I've changed it now to
use Cwd 'abs_path'; BEGIN { unshift @INC, abs_path("$0/../../lib") }
Not only will it work in my situation, additionally the "relative part" gets resolved and the path added to @INC will be "/app/myapp/lib".
Questions
- Will it fail in any situation you can think of?
- Is there any disadvantage in using Cwd instead of FindBin?
- What are your thoughts on this matter?
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cwd::abs_path or FindBin::Bin?
by haukex (Archbishop) on Jun 05, 2019 at 07:18 UTC | |
by Skeeve (Parson) on Jun 05, 2019 at 07:24 UTC | |
by haukex (Archbishop) on Jun 05, 2019 at 08:17 UTC | |
by Skeeve (Parson) on Jun 05, 2019 at 10:24 UTC | |
by haukex (Archbishop) on Jun 05, 2019 at 10:41 UTC | |
| |
Re: Cwd::abs_path or FindBin::Bin?
by ikegami (Patriarch) on Jun 08, 2019 at 10:32 UTC |