RE: When to use 'use' for accessing modules?

2001-10-24 Thread Geoffrey Young


> > > > > Is $ENV{foo}='bar'; in startup.pl equivalent to 
> > PerlSetEnv foo bar
> > > > > in httpd.conf?
> > > >
> > > > Yes.
> 
> well, not exactly.  PerlSetEnv sets the subprocess_env table. 
>  as a side effect of that, you get PerlSetEnv values in %ENV 
> if you have PerlSetupEnv On.  The other way to look at it is 
> that anything set with PerlSetEnv is always accessible via 
> $r->subprocess_env, but not necessarily with %ENV.

scratch that - too early in the morning :)  I have no idea what I was
talking about

I'll just keep quiet now...

> 
> > > 
> > > Are you sure? I experimented a few months ago, and found that
> > > $ENV{foo}='bar'; would only last in each child until the 
> > first request
> > > of the child completed.
> 
> that's a bug
> 
> http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=995652277
11585&w=2

that's still true, though :)

--Geoff



RE: When to use 'use' for accessing modules?

2001-10-24 Thread Geoffrey Young



> -Original Message-
> From: Perrin Harkins [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 24, 2001 1:41 AM
> To: Steve Piner
> Cc: Chris Allen; [EMAIL PROTECTED]
> Subject: Re: When to use 'use' for accessing modules?
> 
> 
> Steve Piner wrote:
> > 
> > Perrin Harkins wrote:
> > 
> > > Chris Allen wrote:
> > [...]
> > > > Is $ENV{foo}='bar'; in startup.pl equivalent to 
> PerlSetEnv foo bar
> > > > in httpd.conf?
> > >
> > > Yes.

well, not exactly.  PerlSetEnv sets the subprocess_env table.  as a side
effect of that, you get PerlSetEnv values in %ENV if you have PerlSetupEnv
On.  The other way to look at it is that anything set with PerlSetEnv is
always accessible via $r->subprocess_env, but not necessarily with %ENV.

> > 
> > Are you sure? I experimented a few months ago, and found that
> > $ENV{foo}='bar'; would only last in each child until the 
> first request
> > of the child completed.

that's a bug

http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=99565227711585&w=2

> 
> You may be right.  Depends on the setting of PerlSetupEnv, I think.
> - Perrin
> 

HTH

--Geoff



Re: When to use 'use' for accessing modules?

2001-10-24 Thread Perrin Harkins

Steve Piner wrote:
> 
> Perrin Harkins wrote:
> 
> > Chris Allen wrote:
> [...]
> > > Is $ENV{foo}='bar'; in startup.pl equivalent to PerlSetEnv foo bar
> > > in httpd.conf?
> >
> > Yes.
> 
> Are you sure? I experimented a few months ago, and found that
> $ENV{foo}='bar'; would only last in each child until the first request
> of the child completed.

You may be right.  Depends on the setting of PerlSetupEnv, I think.
- Perrin



Re: When to use 'use' for accessing modules?

2001-10-23 Thread Steve Piner



Perrin Harkins wrote:

> Chris Allen wrote:
[...]
> > Is $ENV{foo}='bar'; in startup.pl equivalent to PerlSetEnv foo bar
> > in httpd.conf?
> 
> Yes.

Are you sure? I experimented a few months ago, and found that
$ENV{foo}='bar'; would only last in each child until the first request
of the child completed.

Steve

-- 
Steve Piner
Web Applications Developer
Marketview Limited
http://www.marketview.co.nz



Re: When to use 'use' for accessing modules?

2001-10-23 Thread Perrin Harkins

Chris Allen wrote:

> If site::products calls functions from site::customers, do I need
> a 'use site::customers' in site::products, when I have already
> done a 'use' in my startup.pl?


No, but I always do.  It's good documentation, to remind you that if you 
ever ran this code outside of mod_perl it would be necessary to have 
that 'use' in place.


> site::products contains the line:
> 
> @ISA=('site::base'); 
> 
> so that methods from site::base can be overridden in site::products.
> 
> Do I need a 'use site::base' in site::products for this to work 
> correctly?


Only if site::base has not been loaded already, but I always do it 
anyway, for the same reason as above.


> Is $ENV{foo}='bar'; in startup.pl equivalent to PerlSetEnv foo bar
> in httpd.conf?


Yes.


> Experience has shown that I *don't* need the 'use' statements anywhere
> other than startup.pl - but I am not sure why, and would find some pointers
> to a discussion of this very useful.


You don't need them because the modules they would load are already loaded.

> I would also be interested to know that
> if the 'use' statements *are* unnecessary, does including them add any extra
> overhead of processing/memory??


There is a very fast check that happens once when the module containing 
the 'use' is called.  It checks to see if the used module is already 
loaded (i.e. if it is in %INC).  It also calls the used module's export 
function, unless you pass an empty list:

use Foo ();

You should avoid importing symbols all over the place, as explained in 
the Guide, but otherwise there is no significant overhead from having 
use statements all over the place.

- Perrin





When to use 'use' for accessing modules?

2001-10-23 Thread Chris Allen

I have a modperl site that accesses a number of modules. 
In my startup.pl I have:


#!/usr/bin/perl -w
use strict;
use lib('/path/to/my/installation'); # 'site' directory is here

use Apache::DBI;
use Apache::StatINC;
use site::customers;
use site::orders;
use site::products;
use site::base;

1;


None of the modules exports *any* symbols at all - all are called in 
the form:

$product=site::products->new(23);
$product->get('price');



First question:

If site::products calls functions from site::customers, do I need
a 'use site::customers' in site::products, when I have already
done a 'use' in my startup.pl?


Second question:

site::products contains the line:

@ISA=('site::base'); 

so that methods from site::base can be overridden in site::products.

Do I need a 'use site::base' in site::products for this to work 
correctly?



Third (unrelated) question.

Is $ENV{foo}='bar'; in startup.pl equivalent to PerlSetEnv foo bar
in httpd.conf?



---

Experience has shown that I *don't* need the 'use' statements anywhere
other than startup.pl - but I am not sure why, and would find some pointers
to a discussion of this very useful. I would also be interested to know that
if the 'use' statements *are* unnecessary, does including them add any extra
overhead of processing/memory??

Many thanks,


Chris Allen.