Re: Curious About Require

2001-06-20 Thread Mark Doyle

Greetings,

require will only happen once per perl process and since mod_perl
is essentially a single perl process, the file is only require'd
for the first request. You can get around this by deleting the file from 
the %INC
hash which keeps track of which files you have loaded. Something like:

BEGIN {
delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'};
require '/foo/bar/query.pl';
  }

Cheers,
Mark

On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote:

 Hello,
 I have a question about require when using mod-perl. I produced four 
 simple
 .pl files.
 main.pl, one.pl two.pl three.pl

 So my question is why this bazaar behavior. If I change the query.pl 
 to a
 module and use it in each of the pages it is fine. I just find this 
 behavior
 rather funny. If anyone has any insight please update me.

 Thanks,
 Scott Purcell




Re: Curious About Require

2001-06-20 Thread Stas Bekman

On Wed, 20 Jun 2001, Mark Doyle wrote:

 Greetings,

 require will only happen once per perl process and since mod_perl
 is essentially a single perl process, the file is only require'd
 for the first request. You can get around this by deleting the file from
 the %INC
 hash which keeps track of which files you have loaded. Something like:

 BEGIN {
 delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'};
 require '/foo/bar/query.pl';
   }

Mark, your suggestion doesn't work because of BEGIN.

See the URL posted in my other reply for the explanation.

 Cheers,
 Mark

 On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote:

  Hello,
  I have a question about require when using mod-perl. I produced four
  simple
  .pl files.
  main.pl, one.pl two.pl three.pl
 
  So my question is why this bazaar behavior. If I change the query.pl
  to a
  module and use it in each of the pages it is fine. I just find this
  behavior
  rather funny. If anyone has any insight please update me.
 
  Thanks,
  Scott Purcell
 




_
Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
http://stason.org/   mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/





Re: Curious About Require

2001-06-20 Thread Stas Bekman

On Thu, 21 Jun 2001, Stas Bekman wrote:

 On Wed, 20 Jun 2001, Mark Doyle wrote:

  Greetings,
 
  require will only happen once per perl process and since mod_perl
  is essentially a single perl process, the file is only require'd
  for the first request. You can get around this by deleting the file from
  the %INC
  hash which keeps track of which files you have loaded. Something like:
 
  BEGIN {
  delete $INC{'/foo/bar/query.pl'} if exists $INC{'/foo/bar/query.pl'};
  require '/foo/bar/query.pl';
}

 Mark, your suggestion doesn't work because of BEGIN.

Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only in
Registry/PerlRun which executes BEGIN on every request.

Sorry about my previous post :(

But if you delete and reload the file on every request it defeats the
purpose of using mod_perl to some degree, depending on how many files you
force to reload and how big they are.

BTW, here is shorter version of your suggestion:

BEGIN { do '/foo/bar/query.pl'; }

 See the URL posted in my other reply for the explanation.

Still holds :)

  Cheers,
  Mark
 
  On Wednesday, June 20, 2001, at 10:04 AM, Purcell, Scott wrote:
 
   Hello,
   I have a question about require when using mod-perl. I produced four
   simple
   .pl files.
   main.pl, one.pl two.pl three.pl
  
   So my question is why this bazaar behavior. If I change the query.pl
   to a
   module and use it in each of the pages it is fine. I just find this
   behavior
   rather funny. If anyone has any insight please update me.
  
   Thanks,
   Scott Purcell
  
 



 _
 Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
 http://stason.org/   mod_perl Guide  http://perl.apache.org/guide
 mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
 http://singlesheaven.com http://perl.apache.org http://perlmonth.com/






_
Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
http://stason.org/   mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/





Re: Curious About Require

2001-06-20 Thread Perrin Harkins

   BEGIN {
   delete $INC{'/foo/bar/query.pl'} if exists
$INC{'/foo/bar/query.pl'};
   require '/foo/bar/query.pl';
 }
 
  Mark, your suggestion doesn't work because of BEGIN.

 Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only in
 Registry/PerlRun which executes BEGIN on every request.

It only needs to do the require once per script, so if you put this in each
script it will be fine.  Also, I don't think Registry runs BEGIN blocks
every time.  Can't remember about PerlRun.

 BTW, here is shorter version of your suggestion:

 BEGIN { do '/foo/bar/query.pl'; }

That's what I used when porting someone's old perl4-ish code to PerlRun.
Both of these quick fixes waste memory though.

- Perrin




Re: Curious About Require

2001-06-20 Thread Mark Doyle

Greetings,

On Wednesday, June 20, 2001, at 12:45 PM, Stas Bekman wrote:

 Ooops, gotta go to sleep. Your suggestion, Mark, will work :) but only 
 in
 Registry/PerlRun which executes BEGIN on every request.

 Sorry about my previous post :(

 But if you delete and reload the file on every request it defeats the
 purpose of using mod_perl to some degree, depending on how many files 
 you
 force to reload and how big they are.

 BTW, here is shorter version of your suggestion:

 BEGIN { do '/foo/bar/query.pl'; }

Sorry, I guess I should have been more explicit. I don't want to
require in the file on every request, but rather only allow the
same file to be require'd multiple times (to install the same sub
routines into different packages).  This is needed because we have
modularized some of our XML handlers for SUBS-style parsing in
XML::Parser and we need create multiple subclasses of XML::Parser
that share the same modularized components. The packages that
subclass XML::Parser are read in only once in the startup.pl file.
The last require leaves the files in the %INC hash, so it isn't
subsequently read in on every request (so 'do' isn't quite the
same).

Cheers,
Mark



Re: Curious About Require

2001-06-20 Thread Perrin Harkins

I hate to belabor this point, but I don't want people to get the wrong idea:

  BEGIN { do '/foo/bar/query.pl'; }

 Sorry, I guess I should have been more explicit. I don't want to
 require in the file on every request, but rather only allow the
 same file to be require'd multiple times (to install the same sub
 routines into different packages).

That's what this accomplishes.  It only runs once, being inside of a BEGIN
block.  Using do() instead of require() skips the %INC check, so you don't
have to delete anything from %INC this way.  Of course, do() doesn't check
to see if your module returned true, but they are basically equivalent.
TMTOWTDI.

- Perrin