Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Add directry to @INC system wide

by myforwik (Acolyte)
on Mar 06, 2013 at 03:09 UTC ( #1021939=perlquestion: print w/ replies, xml ) Need Help??
myforwik has asked for the wisdom of the Perl Monks concerning the following question:

How can I system wide include a directory in @INC so ANY use of perl always has it in @INC?

I am on Ubuntu 12.04 if it matters. I don't want to use enviroment varibles because that are not always passed through to everyones shells.

At the moment I have to push to @INC inside a 'begin' for every file...

Thanks, Mike

Comment on Add directry to @INC system wide
Re: Add directry to @INC system wide
by ikegami (Pope) on Mar 06, 2013 at 04:43 UTC

    @INC is built when perl is built, so you'll have to rebuild perl with the extra paths specified in the Configure stage.

    Why didn't you install the module in the expected directory if you have the power to affect all users?

Re: Add directry to @INC system wide
by kielstirling (Scribe) on Mar 06, 2013 at 05:00 UTC
    I add the following to my programs
    use FindBin qw($Bin); use lib "$Bin/lib";

    Then you can use any module(s) located in the ./lib directory.
    -Kiel
      Using $RealBin instead of $Bin means your program won't break if you create a symlink to the script.
Re: Add directry to @INC system wide
by myforwik (Acolyte) on Mar 06, 2013 at 05:30 UTC

    It looks like the simplist way is to symlink all the modules into a directory already in @INC

Re: Add directry to @INC system wide
by vinoth.ree (Parson) on Mar 06, 2013 at 05:33 UTC
    kielstirling ++

    I am also using the same method, here it is,

    use File::Spec::Functions qw(catdir splitdir canonpath); use FindBin qw($RealBin); BEGIN { my @dirs = splitdir(canonpath($RealBin)); my($path) = grep { -e $_ } ( map { $_ = catdir(@dirs[0 .. $#dirs - + $_]).'/bin/new/' } (0 .. $#dirs) ); unshift(@INC, $RealBin, $path); }
Re: Add directry to @INC system wide
by Anonymous Monk on Mar 06, 2013 at 06:04 UTC
    Just set the PERL5LIB environment variable to the directory (or directories) you wish to include, and they will be prepended to @INC for every perl.

    Cheers,
    Rob
      From the OP:
      I don't want to use enviroment varibles because that are not always passed through to everyones shells.
Re: Add directry to @INC system wide
by Anonymous Monk on Mar 06, 2013 at 07:40 UTC

    How can I system wide include a directory in @INC so ANY use of perl always has it in @INC?

    Recompile perl, and configure otherlibdirs option

Re: Add directry to @INC system wide
by Perlbotics (Abbot) on Mar 07, 2013 at 21:14 UTC

    Maybe, you can edit the system wide perl customization file?
    Run the following one liner to see if your Perl installation was compiled supporting this hook:

    perl -MConfig -e 'print $Config{usesitecustomize} ? "yes, edit $Confi +g{sitelib}/sitecustomize.pl" : "no luck", "\n"'

    Then, in ..../sitecustomize.pl:

    use lib qw(/my/preferred/dir); print "SITECUSTOMIZE: INC: @INC\n" if $ENV{DEBUG_SITECUSTOMIZE}; # j +ust for fun

    However, users can prevent loading this file using the -f switch (see perlrun). If this is not acceptable, you need to compile your own perl executable as other monks already suggested.

      Maybe, you can edit the system wide perl customization file?

      That can be disabled -- meaning not always passed through -- the only way to permanently add paths which cannot be disabled is to compile-them-in

      OTOH, simply installing modules in @INC to begin-with avoids the problem of needing to add paths to @INC

        Just in case anyone else should follow this node;
        It occurs to me that one could also create a module that "pre-pends" the desired
        additional directory the system' include path, which could then become a system
        wide include, by creating a wrapper for the Perl executable.
        If the module name were "prepend-lib-path.pm" the "wrapper" that disguises itself as
        Perl proper, would contain:
        use prepend-lib-path;
        While not an excuse to omit "lib" paths you might later decide you need;
        it might help in a pinch.

        HTH

        #!/usr/bin/perl -Tw
        use perl::always;
        my $perl_version = "5.12.4";
        print $perl_version;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021939]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (17)
As of 2014-10-20 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (74 votes), past polls