You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Ayhan Ulusoy <ay...@drexel.edu> on 2003/10/20 15:08:23 UTC

RE : [PATCH] add PERL5LIB to @INC in the correct order

> Ayhan Ulusoy wrote:
> > If I may add my grain of salt as an -interested- user for this
one...
> >
> > Here's how I would expect PERL5LIB to work :
> 
> Sorry for cutting you short, Ayhan, but we can't and shouldn't change
the
> way
> PERL5LIB works under mp. 


[Ayhan] 

I am afraid you _have_ cut it short, Stas. Perhaps even before reading
it :)  

Admittedly, I have generated quite a bit of traffic this week-end, and
you seem like a busy man. So, I'll let it slip this time :-)

But please do me a favour and read it.  -- it's attached.





> We agreed that it was a mistake under mp1. We
> simply
> comply with perl and do nothing special about it. If you have further
> thoughts
> on PERL5LIB, please make yourself heard on the p5p list.

[Ayhan] 

But I am perfectly happy with the way Perl handles PERL5LIB, and agree
that mod_perl should keep the Perl way.  But it doesn't ... so that's
why I'm bringing it up in the mod-perl dev list, not p5p.

If you are referring to the behaviour with regards to '-T', I don't have
any problems with the way Perl handles it. Yes, mp1 behaviour for
PERL5LIB under '-T' was a mistake. The mp2 way is GOOD with regards to
that. I had not said anything to the contrary.

What is described in my original post is basically what Geoff was
talking about. In a nutshell, it's about being a able to set PERL5LIB on
a per Server/Directory/Location or per request basis. 

This works perfectly well today with perl scripts running under MOD_CGI.

Under MOD_CGI, I can do a "SetEnv PERL5LIB =xyz" on a per
Directory/Location or even Request basis (via mod_rewrite).  Since the
perl interpreter will be invoked each and every time for a CGI script,
it will take that PERL5LIB into account.

If I am not mistaken, "ModPerl::PerlRun" and to some extent
"ModPerl::Registry" are designed to emulate MOD_CGI behaviour. The way
things are today, they DON'T  --as far as PERL5LIB is concerned.

On the other hand, performance may certainly be an issue here. That's
why I have suggested that this behaviour be optional.


Geoff,  don't you have any comments here ?  Please heeeeelp :)





> 
> If you want to change @INC in mp2, you should use the lib pragma in
the
> startup file or the PerlSwitches -I idiom. Do always use -T and don't
use
> PERL5LIB (because it's ignored with -T).

[Ayhan] 

Again, I have no problems whatsoever with the way Perl behaves with
respect to PERL5LIB under '-T'.  It _should_ behave that way. 

Please read the attached post. It attempts to answer your question as to
why Perl does it that way, and why that is good.

Agreed also that it is good to use '-T' as a rule of thumb, especially
in production environments.

On the other hand, Perl gives me the choice whether or not I want to use
'-T' in a given situation. It's good to have that choice.


Cheers,


Ayhan
 

Re: RE : [PATCH] add PERL5LIB to @INC in the correct order

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Ayhan Ulusoy wrote:
>>Ayhan Ulusoy wrote:
>>
>>>If I may add my grain of salt as an -interested- user for this
> 
> one...
> 
>>>Here's how I would expect PERL5LIB to work :
>>
>>Sorry for cutting you short, Ayhan, but we can't and shouldn't change
> 
> the
> 
>>way
>>PERL5LIB works under mp. 
> 
> 
> 
> [Ayhan] 
> 
> I am afraid you _have_ cut it short, Stas. Perhaps even before reading
> it :)  

I'm sure he did read it.  he even updated the docs accordingly.

> Geoff,  don't you have any comments here ?  Please heeeeelp :)

yes.  I agree with stas - PERL5LIB should be left to perl, and left without 
interference from mod_perl.

keep in mind that PERL5LIB _does_ indeed work: provided your interpreter is 
not running under -T and $ENV{PERL5LIB} is populated when the interpreter is 
spawned, it will be recognized.

--Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [PATCH] add PERL5LIB to @INC in the correct order

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>> So I am a lazy dude who likes to blindly switch between mod_cgi and 
>> mod_perl with less then 10 key-strokes. And that's why I have been 
>> typing several thousand key-strokes for this thread ;)
> 
> 
> Got your idea. And as mentioned above mod_perl works exactly the same as 
> mod_cgi, with regards to PERl5LIB under indentical perl flags.

well, that's not completely true.  in mod_cgi you can toggle -T on a 
per-script basis, so some scripts would be able to use PERL5LIB while others 
would not.  with mod_perl PERL5LIB is all or nothing, depending on the 
global -T setting.  but if you think about it from an interpreter point of 
view, then yes, things are the same - if the interpreter is started without 
taint checking and PERL5LIB is populated, it will affect @INC.

Registry and mod_cgi will never be _exactly_ the same - they are close, but 
to get the increased speed some things end up being different.

--Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [PATCH] add PERL5LIB to @INC in the correct order

Posted by Stas Bekman <st...@stason.org>.
>>> But please do me a favour and read it.  -- it's attached.
>>
>>
>> I did now, and you bring points that Geoff has already mentioned: 
>> PERL5LIB setting per-dir doesn't work in mp1, so it won't work under mp2.
> 
> 
> Don't understand the 'so' connector here. Are you suggesting that there 
> may be "httpd.conf" files out there today which do set PERL5LIB (of all 
> things)  in a directory section without the actual intention of that 
> having any effect, so that they would suddenly break upon upgrading to 
> mp2 ???   --especially if the behavior is governed by a switch (like 
> SetupPERL5LIB ) as suggested earlier, I would rather think that is 
> unlikely.

No, what I meant that per-dir setting of PERL5LIB never worked in mp1, so it 
won't be broken in mp2.

>> The solution is simple - don't use PERL5LIB, use PerlSwitches as I've 
>> documented here:
>> http://perl.apache.org/docs/2.0/user/config/config.html#Adjusting_C__INC_
>> http://perl.apache.org/docs/2.0/user/config/config.html#Modifying_C__INC__on_a_Per_VirtualHost 
>>
>>
>> So the Vhost solution perfectly answers your problem with setting up a 
>> different @INC, for different setups running on the same server.
> 
> 
> 
> That's what I have been doing, and willing to do as a work-around until 
> I convince you to put in the feature ;) or until I end up hacking 
> something on my own.
> Cause what I need is really per-dir. There's no hurry though....

btw, on p5p someone has mentioned a module called perl5lib available from 
CPAN, which bypasses perl's security guards. I've added that info to the above 
URL.

>> Another crafty solution would be to use PerlInitHandler to push some 
>> libs onto @INC and PerlCleanupHandler to pop them away. 
>> Apache::PerlVINC in mp1 does exactly that. Feel free to port it to mp2 
>> / talk to the author first?
>> http://search.cpan.org/~davem/Apache-PerlVINC-0.03/PerlVINC.pm
> 
> 
> 
> It might perhaps be an option, but only if I can manage to extend it so 
> that it can optionally use PERL5LIB instead of a fixed set of 
> directories. But for that, the environment needs to have been set up 
> already, I am not sure it is at the PerlInitHandler phase. Need to check 
> it out;

PerlPassEnv PERL5LIB will do the trick. And sure you can adjust that module to 
optionally work with that env var.

> In any case, I am thinking more and more that this "feature" may belong 
> to ModPerl::RegistryCooker at the end of the day and not to mod_perl 
> itself,  since the divergence is with regard to mod_cgi.
> For a CGI, one expects PERL5LIB to work the same way as under mod_cgi.   
> A "pure" perl handler, on the other hand, knows that it lives in a 
> persistent interpreter which naturally processes its PERL5LIB at 
> start-up time.

Eh? a perl program running under mod_cgi and -T won't respect PERL5LIB. Do you 
say that your programs run without -T? In that case, don't run mod_perl with 
-T and voila you get PERL5LIB.

> Given that, how about if I submitted a patch to RegisteryCooker, which 
> already mingles with INC in its "run" method.  Subclassing could also be 
> an option for some time (until you are convinced), overriding the "run" 
> method.

Sure, you can always do that.

> Below is my poor man's use-case that has motivated me for all this :
> 
> I love it when an application works both under mod_cgi and mod_perl.  
> Call me a maniac (but I am not alone).  I allow myself (and the rest of 
> the poor team here) to use mod_perl & apache specific features _only_ 
> for non-response handlers (filters & such)    Except on extremely rare 
> occasions, anything that generates a response is written to be a plain 
> CGI script without any global variables (so that they will work under 
> mod-perl). The CGI script will handle anything that is "web-related" 
> (relying on CGI.pm and  TT). All "business logic", as they call it, is 
> done in specialized modules who know nothing about the web or HTML or 
> anything.
> 
> Yes, this may be keeping us from unleashing the full power of mp, but it 
> also keeps us from other headaches, especially while mp is going thru 
> change.

Response handlers aren't going through a change. Expect them to stay as they 
are now.

> Throughout the development phase, we test under both mod_cgi and 
> mod_perl, switching between them frequently (actually this is also quite 
> useful for testing parts of mp2, as it lets you see where it diverges. 
> Another advantage is to actually experience --and appreciate over and 
> over again-- the performance gains that mod_perl brings. Add to that 
> some CGI::Cache, and some "memoize" & singleton magic which really comes 
> to life only under mod-perl, you're set for a pleasant ride...)
> 
> Under mod_cgi, we have to use PERL5LIB;     for mod_perl PerlVINC 
> force(s/d) you to use some other "api".   Ain't good.
> 
> So I am a lazy dude who likes to blindly switch between mod_cgi and 
> mod_perl with less then 10 key-strokes. And that's why I have been 
> typing several thousand key-strokes for this thread ;)

Got your idea. And as mentioned above mod_perl works exactly the same as 
mod_cgi, with regards to PERl5LIB under indentical perl flags.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [PATCH] add PERL5LIB to @INC in the correct order

Posted by Ayhan Ulusoy <ay...@qovo.net>.
>
>Guilty as charged, but I said that in first place ;)
... snip ...
>  Therefore please bear with me and feel free to nudge me if my 
> in-head-filter has ignored your email, just like you did now ;)


Don't worry Stas, and thanks for bearing with me bombarding you with lots 
of babble.
Besides, this is not an urgent topic for me, so please feel free to let it 
sleep for a while...


>>But please do me a favour and read it.  -- it's attached.
>
>I did now, and you bring points that Geoff has already mentioned: PERL5LIB 
>setting per-dir doesn't work in mp1, so it won't work under mp2.

Don't understand the 'so' connector here. Are you suggesting that there may 
be "httpd.conf" files out there today which do set PERL5LIB (of all 
things)  in a directory section without the actual intention of that having 
any effect, so that they would suddenly break upon upgrading to mp2 
???   --especially if the behavior is governed by a switch (like 
SetupPERL5LIB ) as suggested earlier, I would rather think that is unlikely.






>The solution is simple - don't use PERL5LIB, use PerlSwitches as I've 
>documented here:
>http://perl.apache.org/docs/2.0/user/config/config.html#Adjusting_C__INC_
>http://perl.apache.org/docs/2.0/user/config/config.html#Modifying_C__INC__on_a_Per_VirtualHost
>
>So the Vhost solution perfectly answers your problem with setting up a 
>different @INC, for different setups running on the same server.


That's what I have been doing, and willing to do as a work-around until I 
convince you to put in the feature ;) or until I end up hacking something 
on my own.
Cause what I need is really per-dir. There's no hurry though....





>Another crafty solution would be to use PerlInitHandler to push some libs 
>onto @INC and PerlCleanupHandler to pop them away. Apache::PerlVINC in mp1 
>does exactly that. Feel free to port it to mp2 / talk to the author first?
>http://search.cpan.org/~davem/Apache-PerlVINC-0.03/PerlVINC.pm


It might perhaps be an option, but only if I can manage to extend it so 
that it can optionally use PERL5LIB instead of a fixed set of directories. 
But for that, the environment needs to have been set up already, I am not 
sure it is at the PerlInitHandler phase. Need to check it out;

In any case, I am thinking more and more that this "feature" may belong to 
ModPerl::RegistryCooker at the end of the day and not to mod_perl 
itself,  since the divergence is with regard to mod_cgi.
For a CGI, one expects PERL5LIB to work the same way as under mod_cgi.   A 
"pure" perl handler, on the other hand, knows that it lives in a persistent 
interpreter which naturally processes its PERL5LIB at start-up time.

Given that, how about if I submitted a patch to RegisteryCooker, which 
already mingles with INC in its "run" method.  Subclassing could also be an 
option for some time (until you are convinced), overriding the "run" method.



Below is my poor man's use-case that has motivated me for all this :

I love it when an application works both under mod_cgi and mod_perl.  Call 
me a maniac (but I am not alone).  I allow myself (and the rest of the poor 
team here) to use mod_perl & apache specific features _only_ for 
non-response handlers (filters & such)    Except on extremely rare 
occasions, anything that generates a response is written to be a plain CGI 
script without any global variables (so that they will work under 
mod-perl). The CGI script will handle anything that is "web-related" 
(relying on CGI.pm and  TT). All "business logic", as they call it, is done 
in specialized modules who know nothing about the web or HTML or anything.

Yes, this may be keeping us from unleashing the full power of mp, but it 
also keeps us from other headaches, especially while mp is going thru change.

Throughout the development phase, we test under both mod_cgi and mod_perl, 
switching between them frequently (actually this is also quite useful for 
testing parts of mp2, as it lets you see where it diverges. Another 
advantage is to actually experience --and appreciate over and over again-- 
the performance gains that mod_perl brings. Add to that some CGI::Cache, 
and some "memoize" & singleton magic which really comes to life only under 
mod-perl, you're set for a pleasant ride...)

Under mod_cgi, we have to use PERL5LIB;     for mod_perl PerlVINC 
force(s/d) you to use some other "api".   Ain't good.

So I am a lazy dude who likes to blindly switch between mod_cgi and 
mod_perl with less then 10 key-strokes. And that's why I have been typing 
several thousand key-strokes for this thread ;)



Cheers,

Ayhan




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [PATCH] add PERL5LIB to @INC in the correct order

Posted by Stas Bekman <st...@stason.org>.
Ayhan Ulusoy wrote:

> I am afraid you _have_ cut it short, Stas. Perhaps even before reading
> it :)  
> 
> Admittedly, I have generated quite a bit of traffic this week-end, and
> you seem like a busy man. So, I'll let it slip this time :-)

Guilty as charged, but I said that in first place ;) Since I've to read email 
traffic on about 15 or so mailing lists, all in one way or another affecting 
mod_perl, I have to adopt some sort of filtering in my head, without which I 
won't be able to do any work at all, but spend all the time just reading 
emails all day long. So normally I do that by looking at the subject and 
sometimes the first para of the post. [that's another reason why I asked you 
to post different issues in different posts ;)]. Therefore please bear with me 
and feel free to nudge me if my in-head-filter has ignored your email, just 
like you did now ;)

> But please do me a favour and read it.  -- it's attached.

I did now, and you bring points that Geoff has already mentioned: PERL5LIB 
setting per-dir doesn't work in mp1, so it won't work under mp2.

> If you are referring to the behaviour with regards to '-T', I don't have
> any problems with the way Perl handles it. Yes, mp1 behaviour for
> PERL5LIB under '-T' was a mistake. The mp2 way is GOOD with regards to
> that. I had not said anything to the contrary.
> 
> What is described in my original post is basically what Geoff was
> talking about. In a nutshell, it's about being a able to set PERL5LIB on
> a per Server/Directory/Location or per request basis. 

The solution is simple - don't use PERL5LIB, use PerlSwitches as I've 
documented here:
http://perl.apache.org/docs/2.0/user/config/config.html#Adjusting_C__INC_
http://perl.apache.org/docs/2.0/user/config/config.html#Modifying_C__INC__on_a_Per_VirtualHost

So the Vhost solution perfectly answers your problem with setting up a 
different @INC, for different setups running on the same server.

Another crafty solution would be to use PerlInitHandler to push some libs onto 
@INC and PerlCleanupHandler to pop them away. Apache::PerlVINC in mp1 does 
exactly that. Feel free to port it to mp2 / talk to the author first?
http://search.cpan.org/~davem/Apache-PerlVINC-0.03/PerlVINC.pm

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org