Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

@INC from $0

by der (Initiate)
on Jul 24, 2015 at 00:35 UTC ( #1136094=perlquestion: print w/replies, xml ) Need Help??
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 (Prior) 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 (Pope) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1136094]
Approved by stevieb
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-01-19 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (215 votes). Check out past polls.

    Notices?