Recommended use of FindBin

60 views
Skip to first unread message

Stefan Adams

unread,
Feb 17, 2015, 6:28:25 PM2/17/15
to mojolicious
I have a question about a recommendation in the Cookbook.  In Making your application installable, it is recommended to use FindBin, but reading the POD of FindBin seems to recommend avoiding the use of FindBin for CPAN modules.

Am I misunderstanding the FindBin recommendation or is this a conflict?

Making your application installable
Finally a few small changes should be made to the application script. The shebang becomes the recommended #!perl, which the toolchain rewrites to the proper shebang during installation. Also use FindBin rather than lib, since installable scripts can't use lib without breaking updated dual-life modules.

FindBin(3)
KNOWN ISSUES
       If there are two modules using "FindBin" from different directories under the same interpreter, this won't work. Since "FindBin" uses a "BEGIN" block, it'll be executed only once, and only the first caller will get it right. This is a problem under mod_perl and other persistent Perl environments, where you shouldn't use this module. Which also means that you should avoid using "FindBin" in modules that you plan to put on CPAN. To make sure that "FindBin" will work is to call the "again" function:

sri

unread,
Feb 17, 2015, 6:40:23 PM2/17/15
to mojol...@googlegroups.com
FindBin(3)
KNOWN ISSUES
       If there are two modules using "FindBin" from different directories under the same interpreter, this won't work. Since "FindBin" uses a "BEGIN" block, it'll be executed only once, and only the first caller will get it right. This is a problem under mod_perl and other persistent Perl environments, where you shouldn't use this module. Which also means that you should avoid using "FindBin" in modules that you plan to put on CPAN. To make sure that "FindBin" will work is to call the "again" function:

Stefan Adams

unread,
Feb 17, 2015, 6:53:30 PM2/17/15
to mojolicious
Oh!  Is it that line that allows us to use FindBin in our CPAN modules without consequence, then?  That is, because of your use of FindBin->again our apps are in the clear and exempt from the recommendation to "avoid using FindBin"?
Reply all
Reply to author
Forward
0 new messages