2

I tried

BEGIN {
    unshift @INC, 'current_path_string';
}

But it only works for use, when require, it's not searched.

Is there a work around?

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
new_perl
  • 7,345
  • 11
  • 42
  • 72

3 Answers3

4

When running under mod_perl, once the server is up @INC is frozen and cannot be updated. The only opportunity to temporarily modify @INC is while the script or the module are loaded and compiled for the first time. After that its value is reset to the original one. The only way to change @INC permanently is to modify it at Apache startup.

Two ways to alter @INC at server startup:

  • In the configuration file. e.g PerlSetEnv PERL5LIB /home/httpd/perl

  • In the startup file directly alter the @INC and load the startup file from the configuration file.

See also @INC and mod_perl

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
0

Yes, you can update @INC in the startup script. But using the code below in your module will simply work:

use lib '/app/my-libs';

at least - for my CGI app running under mod_perl.

MichielB
  • 4,181
  • 1
  • 30
  • 39
-1
use Foo;

is the same as

BEGIN {
    require Foo;
    import Foo;
}

so if it works for use, it works for require.

ikegami
  • 367,544
  • 15
  • 269
  • 518