You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "mail@adventureforum.net" <ma...@adventureforum.net> on 2003/01/24 20:19:49 UTC

"do" as temp solution for "require" problem ?

Hi,

I think mod_perl is wonderful but unfortunately enough the "require" 
function does not work as it does in CGI.
Is using the function "do" the only workaround  as temporary solution 
till this problem is fixed in a/the next mod_perl version?

Cheers,

Bart


Re: "do" as temp solution for "require" problem ?

Posted by Perrin Harkins <pe...@elem.com>.
mail@adventureforum.net wrote:
> This is working fine although a mysql database connection in a  
> subroutine in an external file doesn't always work.

Please explain.  It shouldn't ne a problem to run code that makes a 
database connection in a separate module.

- Perrin


Re: "do" as temp solution for "require" problem ?

Posted by Perrin Harkins <pe...@elem.com>.
mail@adventureforum.net wrote:
> If you look at the previous mentioned site, you can see there is only 
> one file, but it contains a lot of includes.
> - a random function for the banners on top
> - a file for the navigation on the left which includes a file for the 
> date and a file for the counter (mysql database)
> - the content pages with different files for the forms redirected per OS 
> and type of Browser.

You seem to be talking about including chunks of the page, like 
server-side includes (SSI).  That's not the same as doing a require/use 
on a module.  Modules are for storing chunks of Perl code, not HTML.

You originally asked about why your subs from required files were not 
working.  That's what Stas and Randal are telling you: you need to make 
them into real modules with "package" declarations.  There are other 
ways to do it (like "do") but they are kludges.

If you're looking for something to help you manage splitting pages up 
into chunks of HTML, you should consider either using SSI (<!--#include 
virtual="/perl/example.cgi?argument=value" -->) or using HTML::Mason, 
which is based around that idea.

- Perrin


Re: "do" as temp solution for "require" problem ?

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "Justin" == Justin Luster <ju...@sawtoothsoftware.com> writes:

Justin> When a Perl script runs under Mod_Perl the current working directory is
Justin> no longer the location of the Perl script (I think it is where
Justin> Apache.exe is).  So when you require an additional file it does not look
Justin> in the same directory as your original script for the file.  One
Justin> alternative that has been mentioned is to place your included file in
Justin> one of the locations of the @INC array.  Another option that I have used
Justin> is to add the path of the original Perl file to the @INC array so that
Justin> included files will be looked for there too.

But that's not the problem here.

See the other postings in this thread.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: "do" as temp solution for "require" problem ?

Posted by Stas Bekman <st...@stason.org>.
Justin Luster wrote:
> When a Perl script runs under Mod_Perl the current working directory is
> no longer the location of the Perl script (I think it is where
> Apache.exe is).  

You are talking about 2.0 here. And it should change to normal by the time its 
released. This issue is irrelevant to the original question.



__________________________________________________________________
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


RE: "do" as temp solution for "require" problem ?

Posted by Justin Luster <ju...@sawtoothsoftware.com>.
When a Perl script runs under Mod_Perl the current working directory is
no longer the location of the Perl script (I think it is where
Apache.exe is).  So when you require an additional file it does not look
in the same directory as your original script for the file.  One
alternative that has been mentioned is to place your included file in
one of the locations of the @INC array.  Another option that I have used
is to add the path of the original Perl file to the @INC array so that
included files will be looked for there too.


-----Original Message-----
From: mail@adventureforum.net [mailto:mail@adventureforum.net] 
Sent: Tuesday, January 28, 2003 11:51 AM
To: modperl@perl.apache.org
Cc: stas@stason.org; merlyn@stonehenge.com; perrin@elem.com
Subject: Re: "do" as temp solution for "require" problem ?

Hi,
Yes, I am using Apache::Registry; how did you know that? ;-)
In fact I am trying to change the CGI-Perl pages of 
http://www.deweertsport.be to mod_perl.
As I was used to work with include files in PHP, I sort continued this 
way of making pages in Perl-CGI.
If you look at the previous mentioned site, you can see there is only 
one file, but it contains a lot of includes.
- a random function for the banners on top
- a file for the navigation on the left which includes a file for the 
date and a file for the counter (mysql database)
- the content pages with different files for the forms redirected per 
OS and type of Browser.
The reason why I work that way is to have a sort of frame in which the 
content is included, directed via the variables of the URL.
That gives me a good overview on how the site is built and it makes it 
easy to maintain.
Now, with mod_per this is a whole different story. Probably I need to 
review my strategy as things get more complicated regarding using 
"use", or "require" ... or "do" ....
Would using Apache::PerlRun be a better option to deal with this way of 
building a website?
Thanks for your advise!
Bart

On Tuesday, January 28, 2003, at 05:21 PM, Randal L. Schwartz wrote:

>>>>>> "mail@adventureforum" == mail@adventureforum net 
>>>>>> <ma...@adventureforum.net> writes:
>
> mail@adventureforum> I am using: mod_perl/1.26
>
> mail@adventureforum> Now I tried to include subroutines from an 
> external .pl file with
> mail@adventureforum> "require".
>
> This smells a bit like you're using Apache::Registry (you haven't said
> yet) and you've moved some subroutines into a separate file, but not a
> separate package, and you either aren't aware or don't understand the
> significance of the fact that every Apache::Registry script runs in a
> different package.
>
> Could that be the case?
>
> If you're using Apache::Registry, and you're not properly using
> packages, you'll get burned.  Turn your external code into a real
> module, and things will work again.  Use "use", not "require", not
> "do".
>
> print "Just another (mod) Perl hacker,"
>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777

> 0095
> <me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl 
> training!
>


Re: "do" as temp solution for "require" problem ?

Posted by "mail@adventureforum.net" <ma...@adventureforum.net>.
Hi,
Yes, I am using Apache::Registry; how did you know that? ;-)
In fact I am trying to change the CGI-Perl pages of 
http://www.deweertsport.be to mod_perl.
As I was used to work with include files in PHP, I sort continued this 
way of making pages in Perl-CGI.
If you look at the previous mentioned site, you can see there is only 
one file, but it contains a lot of includes.
- a random function for the banners on top
- a file for the navigation on the left which includes a file for the 
date and a file for the counter (mysql database)
- the content pages with different files for the forms redirected per 
OS and type of Browser.
The reason why I work that way is to have a sort of frame in which the 
content is included, directed via the variables of the URL.
That gives me a good overview on how the site is built and it makes it 
easy to maintain.
Now, with mod_per this is a whole different story. Probably I need to 
review my strategy as things get more complicated regarding using 
"use", or "require" ... or "do" ....
Would using Apache::PerlRun be a better option to deal with this way of 
building a website?
Thanks for your advise!
Bart

On Tuesday, January 28, 2003, at 05:21 PM, Randal L. Schwartz wrote:

>>>>>> "mail@adventureforum" == mail@adventureforum net 
>>>>>> <ma...@adventureforum.net> writes:
>
> mail@adventureforum> I am using: mod_perl/1.26
>
> mail@adventureforum> Now I tried to include subroutines from an 
> external .pl file with
> mail@adventureforum> "require".
>
> This smells a bit like you're using Apache::Registry (you haven't said
> yet) and you've moved some subroutines into a separate file, but not a
> separate package, and you either aren't aware or don't understand the
> significance of the fact that every Apache::Registry script runs in a
> different package.
>
> Could that be the case?
>
> If you're using Apache::Registry, and you're not properly using
> packages, you'll get burned.  Turn your external code into a real
> module, and things will work again.  Use "use", not "require", not
> "do".
>
> print "Just another (mod) Perl hacker,"
>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 
> 0095
> <me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl 
> training!
>


Re: "do" as temp solution for "require" problem ?

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "mail@adventureforum" == mail@adventureforum net <ma...@adventureforum.net> writes:

mail@adventureforum> I am using: mod_perl/1.26

mail@adventureforum> Now I tried to include subroutines from an external .pl file with
mail@adventureforum> "require".

This smells a bit like you're using Apache::Registry (you haven't said
yet) and you've moved some subroutines into a separate file, but not a
separate package, and you either aren't aware or don't understand the
significance of the fact that every Apache::Registry script runs in a
different package.

Could that be the case?

If you're using Apache::Registry, and you're not properly using
packages, you'll get burned.  Turn your external code into a real
module, and things will work again.  Use "use", not "require", not
"do".

print "Just another (mod) Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: "do" as temp solution for "require" problem ?

Posted by "mail@adventureforum.net" <ma...@adventureforum.net>.
Hi,

I am using: mod_perl/1.26

Now I tried to include subroutines from an external .pl file with  
"require".

This I got from:  
http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery
"For example if we move the code from the script into the subroutine  
run, place the subroutines into the mylib.pl file, save it in the same  
directory as the script itself and require() it, there will be no  
problem at all. (Don't forget the 1; at the end of the library or the  
require() might fail.)"

This is working fine although a mysql database connection in a  
subroutine in an external file doesn't always work.

The "do" solution I got from:  
http://perl.apache.org/docs/1.0/guide/ 
porting.html#Name_collisions_with_Modules_and_libs
-> on the bottom of the page: A hack)

Cheers,

Bart



On Sunday, January 26, 2003, at 05:30 AM, Stas Bekman wrote:

> mail@adventureforum.net wrote:
>> Hi,
>> I think mod_perl is wonderful but unfortunately enough the "require"  
>> function does not work as it does in CGI.
>> Is using the function "do" the only workaround  as temporary solution  
>> till this problem is fixed in a/the next mod_perl version?
>
> Have you read:
> http://perl.apache.org/docs/1.0/guide/ 
> porting.html#Name_collisions_with_Modules_and_libs
> ?
>
> If you are referring to a different problem, what mod_perl version are  
> you talking about?
>
> __________________________________________________________________
> 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
>


Re: "do" as temp solution for "require" problem ?

Posted by Stas Bekman <st...@stason.org>.
mail@adventureforum.net wrote:
> Hi,
> 
> I think mod_perl is wonderful but unfortunately enough the "require" 
> function does not work as it does in CGI.
> Is using the function "do" the only workaround  as temporary solution 
> till this problem is fixed in a/the next mod_perl version?

Have you read:
http://perl.apache.org/docs/1.0/guide/porting.html#Name_collisions_with_Modules_and_libs
?

If you are referring to a different problem, what mod_perl version are you 
talking about?

__________________________________________________________________
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