Re: Problem with @INC
Doug MacEachern wrote: On Sat, 13 May 2000, Robert Nice wrote: use lib '../site_perl'; it's been explained, 'use lib' happens at compile time (once per-script) and @INC is reset to whatever it was startup time after each request. the simple solution for you, which i didn't see mentioned, is to modify @INC at runtime, e.g. This was one of those times where the cause was understood, I was just looking for a solution. It's quite interesting some of the private discussions and solutions that I've been engaged in. Some people have sent me sizeable chunks of code to get around it. I'm currently using a startup script with a use lib which is fine, however unshift @INC, '../site_perl'; ... if this works (and I can't see why it wouldn't) all I can say is "Damn, why didn't I think of that!". Why didn't anybody else? For some reason I thought 'use lib' did something special, too much faith that's my problem. Someone put it in the guide please ;-) On another speculative note seeing as 'use strict' changes compiler behaviour somewhat is it feasable to write a module that would convert or modPerlise a script to catch half the stuff that comes up on this list every week? H? Thanks, -- Robert Nice
Re: Problem with @INC
On Sat, 13 May 2000, Robert Nice wrote: use lib '../site_perl'; it's been explained, 'use lib' happens at compile time (once per-script) and @INC is reset to whatever it was startup time after each request. the simple solution for you, which i didn't see mentioned, is to modify @INC at runtime, e.g. unshift @INC, '../site_perl';
Re: Problem with @INC
Yeah but that doesn't help him entirely with a solution to his problem -- which is that he wants to load something at runtime later on -- not at compile time. And in fact, it is a must to be able to do this in some cases. eg he correctly points out that LWP uses the factory design pattern to load modules dynamically rather than at compile time. I use this technique all over the stuff I write because it conveniently defers the decision of what to load -- Of course, if it is loaded ahead of time using PerlRequire then there isn't any problem... and you get enhanced performance, but it is also a pain to know all the modules and submodules you want to load ahead of time. CAVEAT ALERT: Then the only caveat is namespace problems if there is more than one local copy of a module... however, given that caveat in mind, the following code should work well: use lib qw(./Modules); use vars qw(@SAVED_INC); BEGIN { @SAVED_INC = @INC; } @INC = @SAVED_INC; In the header of the relevant scripts. Later, Gunther At 11:36 PM 5/13/00 +0300, Stas Bekman wrote: On Sat, 13 May 2000, Robert Nice wrote: Hi, Simple problem, I had a quick search thorugh the archives and a good delve into the perl website, no joy. You didn't delve deep enough, perl.apache.org/index.html reveals no mod_perl specific info. Guide is your guide into mod_perl. The answer to your question is there: http://perl.apache.org/guide/porting.html#_INC_and_mod_perl (Using modPerl 1.23) #!/usr/bin/perl -w use lib '../site_perl'; use CGI; my $cgi = new CGI; print $cgi-header; print join("br\n", @INC); --- First time (compiling run): ../site_perl /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /etc/httpd/ /etc/httpd/lib/perl Second run : /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /etc/httpd/ /etc/httpd/lib/perl --- In other words my 'use lib' line disappears. I can understand why. You typically won't need it after it's already been compiled. I've been happily using modPerl for ages and this hasn't caused a problem. My company however newly requires that I speak to 25 different credit card processors and I wanted to pull them in with 'eval "require $classname"' statements like LWP does with net protocols. For efficency I'd like to compile them when needed not in bulk on the first run. I'd also prefer not to put my libraries in the system library area as it defeats my development setup of having test and beta libraries on the same machine. I've got a workaround (I force them all to load on the first run if under modPerl), however I thought I'd post, might be something for the developers to think about. Cheers, Robert Nice Technical Director WebsiteBilling.com Inc _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://perl.org http://stason.org/TULARC http://singlesheaven.com http://perlmonth.com http://sourcegarden.org __ Gunther Birznieks ([EMAIL PROTECTED]) Extropia - The Web Technology Company http://www.extropia.com/
Re: Problem with @INC
On Sat, 13 May 2000, Robert Nice wrote: Hi, Simple problem, I had a quick search thorugh the archives and a good delve into the perl website, no joy. You didn't delve deep enough, perl.apache.org/index.html reveals no mod_perl specific info. Guide is your guide into mod_perl. The answer to your question is there: http://perl.apache.org/guide/porting.html#_INC_and_mod_perl (Using modPerl 1.23) #!/usr/bin/perl -w use lib '../site_perl'; use CGI; my $cgi = new CGI; print $cgi-header; print join("br\n", @INC); --- First time (compiling run): ../site_perl /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /etc/httpd/ /etc/httpd/lib/perl Second run : /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 . /etc/httpd/ /etc/httpd/lib/perl --- In other words my 'use lib' line disappears. I can understand why. You typically won't need it after it's already been compiled. I've been happily using modPerl for ages and this hasn't caused a problem. My company however newly requires that I speak to 25 different credit card processors and I wanted to pull them in with 'eval "require $classname"' statements like LWP does with net protocols. For efficency I'd like to compile them when needed not in bulk on the first run. I'd also prefer not to put my libraries in the system library area as it defeats my development setup of having test and beta libraries on the same machine. I've got a workaround (I force them all to load on the first run if under modPerl), however I thought I'd post, might be something for the developers to think about. Cheers, Robert Nice Technical Director WebsiteBilling.com Inc _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://perl.org http://stason.org/TULARC http://singlesheaven.com http://perlmonth.com http://sourcegarden.org