http://qs1969.pair.com?node_id=1136094

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

I'm looking for a CPAN module that will put the directory from $0 onto @INC. It's a trivial bit of code, yes, but I hate to replicate it all over the place. (And of course, I can't re-use that code without getting something onto @INC first (the admins at most shops won't let me put stuff into system directories).)

I'm okay with mandating a directory on every user's PATH, but I like to keep things as simple as possible and not rely on trying to get PERL5LIB set in every user's env. My philosophy is that if you can run the program, it should just run.

Does some form of this exist, or some other elegant solution I've overlooked?

Replies are listed 'Best First'.
Re: @INC from $0 (FindLib)
by tye (Sage) on Jul 24, 2015 at 02:17 UTC

    We arrange to have File::FindLib installed (it is just 1 file) into a default include directory of the Perl we use and use it to bootstrap the rest.

    - tye        

      Yup, that's the ticket. Thanks!
Re: @INC from $0
by dave_the_m (Monsignor) on Jul 24, 2015 at 08:59 UTC
    This is what the core module FindBin is designed for:
    use FindBin; use lib $FindBin::Bin;

    Dave.

Re: @INC from $0
by BrowserUk (Patriarch) on Jul 24, 2015 at 01:14 UTC
      use happens at BEGIN time, so that won't work  Empty compile time value given to use lib
Re: @INC from $0
by Anonymous Monk on Jul 24, 2015 at 01:47 UTC

    use File::Spec; use File::Basename(); use lib File::Basename::dirname( File::Spec->rel2abs( $0 ) ).'/lib';

    Here are hints