perlquestion
Skeeve
<p>
What are you thoughts about using Cwd::abs_path() instead of $FindBin::Bin?
</p>
<h4>Motivation</h4>
<p>
In Mojolicious the auto-generated application script contains:
</p>
<code>
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
</code>
<p>
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.
</p>
<p>
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".
</p>
<p>
So I've changed it now to
</p>
<code>
use Cwd 'abs_path';
BEGIN { unshift @INC, abs_path("$0/../../lib") }
</code>
<p>
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".
</p>
<h4>Questions</h4>
<ol>
<li>
Will it fail in any situation you can think of?
</li>
<li>
Is there any disadvantage in using Cwd instead of FindBin?
</li>
<li>
What are your thoughts on this matter?
</li>
</ol>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-253915">
<hr><code>s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%</code>
<br><font color="red"><code>+</code></font><code>.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e</code>
</div></div>