开发者

What's the canonical way to make the directory that has the current source file to be searched by `use` and `require` statements in Perl in mod_perl?

开发者 https://www.devze.com 2023-03-20 20:04 出处:网络
I tried BEGIN { unshift @INC, \'current_path_string\'; } But it only works for us开发者_如何学Ce, when require, it\'s not searched.

I tried

BEGIN {
    unshift @INC, 'current_path_string';
}

But it only works for us开发者_如何学Ce, when require, it's not searched.

Is there a work around?


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


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.


use Foo;

is the same as

BEGIN {
    require Foo;
    import Foo;
}

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号