You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Darren Duncan <da...@DarrenDuncan.net> on 2000/12/15 05:00:47 UTC

greetings and questions

Greetings,

I have been using Perl extensively over the last couple years, mostly in
the form of CGI applications/libraries/scripts that run under Apache
servers.  I am currently migrating my code to run under mod_perl, and
after looking at the various readmes, I have a few questions.

First, a quick overview on my design and coding style:

I believe that I have taken the care to write my code
somewhat elegantly and with an eye on proper structured programming
techniques and maintainability.  Since I am relatively new to the language
(introduced to in 1998) I started off with Perl 5 and its worldview, which
means among other things that I use object-oriented features extensively,
do not use the Exporter, always use strict, make liberal use of real
references and subroutines/methods, create my own modules for code reuse,
and so-on.  While Perl affords me many ways to do something, I look for
the best compromise between maintainability and speed.  I do my best not
to obfuscate, and thereby I usually name my variables even if I don't have
to (for example, using "shift(@_)" instead of "shift").

In anticipation that I would be migrating to mod_perl in the near future,
I did what I could to read up on its more strict requirements relative to
the CGI environment.  Where possible, I used lexical (my) variables for
everything possible, including file-scope "constants".  Any
non-"special" global variables are stored inside my objects, which are
passed as arguments and stored in lexicals.  I always use strict.

Now some questions that I hope some of you can help me with.  Hopefully
each has short answers.

1. Since I imagine that I would be running inside Apache::Registry (I
don't own the machine, someone else sets up the server), does it take care
of reloading any modules that I "use" or "require" when they change on
disk?  I read that this doesn't happen under mod_perl in general, but it
would be useful since I often update my code and I can't restart the
server.

2. The POD for Apache::Registry says that it doesn't like __END__ and
__DATA__ tokens.  So what affect do these actually have if left in?  Does
Perl just try to parse what came afterwards as if they weren't there, or
are there other issues?  (Note: I don't use these for filehandles.)  I do
not use main:: at all.

3. Related to the above, I use the Net::SMTP module by Graham Barr quite a
lot to implement send e-mail (instead of sendmail) because it gives me
feedback on whether the send actually worked, is faster(?), and it runs on
any host system.  However, this module uses tokens like __END__, so I'm
wondering if it would break under mod_perl.  In preliminary testing of
this and my own modules, the mail seems to send fine, but I'm concerned
about longetivity.

4. Since I have been avoiding globals (eg: "Q::varname") so far, I'm not
sure where and how to use them to work the way I need.  The only time I
would need globals (I assume) is if I want to use "singletons".  And yes,
I know about Class::Singleton, but I stopped using it due to global fears.
And so:

  a. How do I set up and clean up a "static" variable that is shared by
multiple instances of a class that are in the same server thread and not
seen by other threads (the same functionality that CGIs take for granted).
Currently I use one object to create the others, thereby copying
references, but I would prefer not to.

  b. How do I set up and (when needed) clean up a "persistant" variable
that would be shared by multiple server threads, such as an open database
connection.  Related to this, would I be able to use a DBI object as this
persistant variable, or would I have to use something else.

I am guessing that (b) is probably a whole discussion in itself, and
perhaps there's a book on it?  (I already have Oreily's "Advanced Perl"
and "Writing Apache Modules...", although know not where to look in them.)

So I will leave off asking more questions for the moment.

Any help would be greatly appreciated, as these issues have been pressing
on me for many months (at least #4 was).

Thanks a lot in advance,

// Darren Duncan


Re: greetings and questions

Posted by Tom Brown <tb...@baremetal.com>.
On Thu, 14 Dec 2000, Tom Brown wrote:

> On Thu, 14 Dec 2000, Ajit Deshpande wrote:
> > > 2. The POD for Apache::Registry says that it doesn't like __END__ and
> > > __DATA__ tokens.  So what affect do these actually have if left in?  Does
> 
> In scripts? it's a syntax error, but that's a completely separate issue
> from modules which get used "as is" ...
> 
> scripts get wrapped inside braces (and probably an eval) and obviously if
> you cut off the closing braces with an __END__ you're going to be in
> trouble...
> 
> Apache::Registry isn't that big or complex ... have a look at it...

sorry, I realized I over simplified my answer and there are good
conclusions to be had from a better one... so my apologies for following
up on my own post... 

here's the immediately relevent code from Apache::Registry.pm

            my $eval = join(
                            '',
                            'package ',
                            $package,
                            ';use Apache qw(exit);',
                            'sub handler {',
                            $line,
                            $sub,
                            "\n}", # last line comment without newline?
                           );
            compile($eval);

... what you think of as your script is $sub in this join()... $package is
the Registry assigned package name, $line is a hint to the perl compiler
to try to get line numbers fixed...




Re: greetings and questions

Posted by Tom Brown <tb...@baremetal.com>.
On Thu, 14 Dec 2000, Ajit Deshpande wrote:
> > 2. The POD for Apache::Registry says that it doesn't like __END__ and
> > __DATA__ tokens.  So what affect do these actually have if left in?  Does

In scripts? it's a syntax error, but that's a completely separate issue
from modules which get used "as is" ...

scripts get wrapped inside braces (and probably an eval) and obviously if
you cut off the closing braces with an __END__ you're going to be in
trouble...

Apache::Registry isn't that big or complex ... have a look at it...


Re: greetings and questions

Posted by Ajit Deshpande <aj...@skycorp.net>.
On Thu, Dec 14, 2000 at 08:00:47PM -0800, Darren Duncan wrote:
> Now some questions that I hope some of you can help me with.  Hopefully
> each has short answers.

The mod_perl Guide at http://perl.apache.org/guide/ has a lot of good
information for programming under mod_perl. Most of the answers to your
questions below should already be answered there.

Apache::Registry Introduction:
http://perl.apache.org/guide/porting.html#Exposing_Apache_Registry_secret

Apache::Registry specific watchouts:
http://perl.apache.org/guide/performance.html#Apache_Registry_and_Derivatives
 
> of reloading any modules that I "use" or "require" when they change on

http://perl.apache.org/guide/config.html#The_Startup_File

> 2. The POD for Apache::Registry says that it doesn't like __END__ and
> __DATA__ tokens.  So what affect do these actually have if left in?  Does

http://perl.apache.org/guide/porting.html#_END_and_DATA_tokens

> 3. Related to the above, I use the Net::SMTP module by Graham Barr quite a
> lot to implement send e-mail (instead of sendmail) because it gives me

Doesnt answer your question but points you in the right direction:
http://perl.apache.org/guide/snippets.html#Sending_Email_from_mod_perl
 
> 4. Since I have been avoiding globals (eg: "Q::varname") so far, I'm not
> sure where and how to use them to work the way I need.  The only time I

If there is anything the guide covers really well, its this topic :)

For starters:
http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S

Search for "global" in the search engine on the above URLs and you will
find a bunch of interesting explanations

Ajit

Re: greetings and questions

Posted by Stas Bekman <st...@stason.org>.
On Fri, 15 Dec 2000, Ajit Deshpande wrote:

> On Fri, Dec 15, 2000 at 05:23:05PM +0100, Stas Bekman wrote:
> > Currently I cannot use your TOC since:  
> > 1) it's automatically created 
> 
> I was proposing patching the CVS so that it Automatically generates
> the new format

It's Pod::HtmlPsPdf which generates index.html, currently it doesn't
support the proposed format. You are welcome to patch it so it will.

> > 2) your toc grouping doesn't reflect the order the chapters should be read
> > in, the guide is mainly a "guide" (designed for sequantial reading) and
> > when used as a reference the search is to be used. The chapters aren't
> > linked in the random order but in the predefined one.
> 
> Agreed. Its almost like we need a Mini-Me (TM) Guide to The Guide :)

:)
 
> > 3) your toc has omitted a few chapters.
> 
> Oh, I was just giving an example..

ok
 
> But if you are working on the book, thats just fine! Just trying to
> help here.. not criticize :)

Healthy critisism makes only good. I was just explaining the reasoning for
things to be the way they are. Your help is very welcome, please don't
interpret my replies as discouraging ones, even if sometimes I might sound
so... not on purpose... :)

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/  



Re: greetings and questions

Posted by Ajit Deshpande <aj...@skycorp.net>.
On Fri, Dec 15, 2000 at 05:23:05PM +0100, Stas Bekman wrote:
> Currently I cannot use your TOC since:  
> 1) it's automatically created 

I was proposing patching the CVS so that it Automatically generates
the new format
 
> 2) your toc grouping doesn't reflect the order the chapters should be read
> in, the guide is mainly a "guide" (designed for sequantial reading) and
> when used as a reference the search is to be used. The chapters aren't
> linked in the random order but in the predefined one.

Agreed. Its almost like we need a Mini-Me (TM) Guide to The Guide :)

> 3) your toc has omitted a few chapters.

Oh, I was just giving an example..

But if you are working on the book, thats just fine! Just trying to help
here.. not criticize :)

Re: greetings and questions

Posted by Stas Bekman <st...@stason.org>.
> On Fri, Dec 15, 2000 at 01:21:04PM +0100, Stas Bekman wrote:
> > Hmm, should I add <font size=+7></font> around it? Do others find it
> > hidden?
> 
> In fact I do. Also, are the other documents being maintained? Do you
> really want users to go read the other ones?

I'm cannot tell users not to read other documents. You should ask their
respective owners whether they find their documents still unique and
whether they should stay online, since the guide has swallowed long time
ago most of the material in these, but not all of it.
 
> Another thing I observed: The Guide is becoming almost TOO big and
> unwieldly.

I can tell you that it's stable now. Most of the work done within the
existing material and no new material is added (well very little). I still
have a bunch of outstanding emails with very good info that should enter
the guide, but I didn't get to them yet.

> New people can get overwhelmed. 

New people are always overhelmed. Whether you have a little or no
documentation or too much of it.

> How about arranging the Table of Contents into Chapters and moving
> topics around a little as follows:
> 
>     1. Introduction	
>        - Incentive & Credits
>        - Overview
>        - Downloading s/w and documentation
>       
>     2. mod_perl Administration
>        - mod_perl Installation
>        - mod_perl Configuration
>        - Controlling and Monitoring the Server
>        - Choosing the Right Strategy
>        - Real World Scenarios
>        - Choosing an o/s and h/w
> 
>     3. mod_perl Programming
>        - Perl reference
>        - CGI to mod_perl Porting
>        - Frequently mod_perl Problems & Workarounds
>        - Troubleshooting Index
>        - Code Snippets
>        - Debugging
>        - Working with Apache::* modules
>        
>     4. Conclusion
>        - Getting Help and Further Learning
>        - mod_perl Advocacy
> 
> If you want I can give you patches against CVS to re-arrange the TOC as
> above.

This is planned long time ago, but I won't do anything before the book
will be completed. It's long time overdue. Once the book will be out, you
won't need the guide anymore. Believe me that the book will have a proper
TOC and organization.

Currently I cannot use your TOC since:  

1) it's automatically created 

2) your toc grouping doesn't reflect the order the chapters should be read
in, the guide is mainly a "guide" (designed for sequantial reading) and
when used as a reference the search is to be used. The chapters aren't
linked in the random order but in the predefined one.

3) your toc has omitted a few chapters.

I'll highlight the guide though as suggested by a few users in the private
emails. Also if you go to take23.org and you should, the guide is
outstanding there.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/  



Re: greetings and questions

Posted by Ajit Deshpande <aj...@skycorp.net>.
On Fri, Dec 15, 2000 at 01:21:04PM +0100, Stas Bekman wrote:
> Hmm, should I add <font size=+7></font> around it? Do others find it
> hidden?

In fact I do. Also, are the other documents being maintained? Do you
really want users to go read the other ones?

Another thing I observed: The Guide is becoming almost TOO big and
unwieldly. New people can get overwhelmed. How about arranging the Table
of Contents into Chapters and moving topics around a little as follows:

    1. Introduction	
       - Incentive & Credits
       - Overview
       - Downloading s/w and documentation
      
    2. mod_perl Administration
       - mod_perl Installation
       - mod_perl Configuration
       - Controlling and Monitoring the Server
       - Choosing the Right Strategy
       - Real World Scenarios
       - Choosing an o/s and h/w

    3. mod_perl Programming
       - Perl reference
       - CGI to mod_perl Porting
       - Frequently mod_perl Problems & Workarounds
       - Troubleshooting Index
       - Code Snippets
       - Debugging
       - Working with Apache::* modules
       
    4. Conclusion
       - Getting Help and Further Learning
       - mod_perl Advocacy

If you want I can give you patches against CVS to re-arrange the TOC as
above.

Ajit

Re: greetings and questions

Posted by "G.W. Haywood" <ge...@www.jubileegroup.co.uk>.
Hi All,

On Fri, 15 Dec 2000, Stas Bekman wrote:
 
> Please don't take it personally, it's just that quite many people came
> here asking questions that were long time ago answered and documented. It
> just shows people's ignorance, lack of respect and wish to get things the
> easy way.

C'mon, Stas, lighten up!  Maybe the guy's just frantically busy!
(Although that first post _was_ a bit long:)

73,
Ged.
(Too frantically busy to read some of these threads:)


Re: greetings and questions

Posted by Stas Bekman <st...@stason.org>.
On Sat, 16 Dec 2000, Jeremy Howard wrote:

> Stas Bekman wrote:
> > Come'n, are you sure you have ever looked at perl.apache.org?
> >
> > http://perl.apache.org/#docs
> >
> > Books and Documentation:
> >
> >                        Writing Apache Modules with Perl and C book by
> >                        Lincoln Stein and Doug MacEachern.
> >
> >                  ==>   Start learning mod_perl with the mod_perl Guide
> >                        by Stas Bekman.
> > <...>
> I remember when I started with mod_perl last year, I didn't notice the guide
> until I saw it mentioned on the list. perl.apache.org is a long page, and
> it's not obvious what order to read the various links in... The FAQ linked
> to on this page includes 'What documentation should I read?' and doesn't
> include the Guide in the answer... The link to the guide is the 32nd of 97
> links on this page... It is one of 11 documentation links... So I guess what
> I'm trying to say is that it's not that obvious ;-)

Let me ask you this question. When you are looking for something in a fat
book, do you just read all the pages and then say, ouch this item I was
looking for was placed on page 789. No you don't -- you look at the Table
of Contents or the index pages.

So the perl.apache.org/index.html has its TOC:

                       Download 
                       Take23: News and Resources for the mod_perl world 
                       Perl Apache Modules 
                       Help with Perl Apache Modules Wanted 
              =======> Books and Documentation 
                       mod_perl in Magazines 
                       Mailing Lists and Contact Info 

and then when you click on the obvious link, you get to another list,
where the guide is listed after the eagle book.

> Maybe the mod_perl site could start with:
> ----
> New to mod_perl? First, <a href="http://perl.apache.org/dist/">download</a>
> it and then <a href="http://perl.apache.org/guide/install.html">learn</a> to
> install it. Now read <a href="http://perl.apache.org/guide/">"The Guide"</a>
> and become and mod_perl guru!
> ----
> ...or something like that.

It used to be like that, but then people didn't see other documents
available.

It just shows that people don't really look at the available resources.
And no, don't tell me that I know where to find things because I already
know where they are. I've spent time thinking how this should be done so
it'd be as obvious as possible where things are to be found. 

Moreover when you subscribe to the mailing list, you receive a special
email explaining what are the available resources are and where to find
them. 

Please don't take it personally, it's just that quite many people came
here asking questions that were long time ago answered and documented. It
just shows people's ignorance, lack of respect and wish to get things the
easy way.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/  



Re: greetings and questions

Posted by Jeremy Howard <jh...@fastmail.fm>.
Stas Bekman wrote:
> Come'n, are you sure you have ever looked at perl.apache.org?
>
> http://perl.apache.org/#docs
>
> Books and Documentation:
>
>                        Writing Apache Modules with Perl and C book by
>                        Lincoln Stein and Doug MacEachern.
>
>                  ==>   Start learning mod_perl with the mod_perl Guide
>                        by Stas Bekman.
> <...>
I remember when I started with mod_perl last year, I didn't notice the guide
until I saw it mentioned on the list. perl.apache.org is a long page, and
it's not obvious what order to read the various links in... The FAQ linked
to on this page includes 'What documentation should I read?' and doesn't
include the Guide in the answer... The link to the guide is the 32nd of 97
links on this page... It is one of 11 documentation links... So I guess what
I'm trying to say is that it's not that obvious ;-)

Maybe the mod_perl site could start with:
----
New to mod_perl? First, <a href="http://perl.apache.org/dist/">download</a>
it and then <a href="http://perl.apache.org/guide/install.html">learn</a> to
install it. Now read <a href="http://perl.apache.org/guide/">"The Guide"</a>
and become and mod_perl guru!
----
...or something like that.



Re: greetings and questions

Posted by "G.W. Haywood" <ge...@www.jubileegroup.co.uk>.
Hi Stas,

On Fri, 15 Dec 2000, Stas Bekman wrote:

> Come'n, are you sure you have ever looked at perl.apache.org?
[snip] 
> Hmm, should I add <font size=+7></font> around it?

How about <blink> :) </blink>

73,
Ged.



Re: greetings and questions

Posted by Stas Bekman <st...@stason.org>.
On Thu, 14 Dec 2000, Darren Duncan wrote:

> Thanks to everyone who answered my questions in some form or other.
> 
> As it is, I *had* been reading whatever manuals I found, but those 
> were the documentation that came with the mod_perl distribution on 
> CPAN.
> 
> I was not aware of the existence of "http://perl.apache.org/guide/" 
> and if I had been then I would have looked there.  I had seen a 
> number of documents on the perl.apache.org server, but not that one. 

Come'n, are you sure you have ever looked at perl.apache.org?

http://perl.apache.org/#docs

Books and Documentation:

                       Writing Apache Modules with Perl and C book by
                       Lincoln Stein and Doug MacEachern. 

                 ==>   Start learning mod_perl with the mod_perl Guide
                       by Stas Bekman. 

                       Quick guide for moving from CGI to mod_perl. 

                       mod_perl_traps, common traps and solutions for
                       mod_perl users. 

                       The mod_perl plugin reference guide by Doug
                       MacEachern. 

                       mod_perl FAQ by Frank Cringle. 

                       mod_perl performance tuning guide by Vivek Khera. 

                       mod_perl reference card by Andrew Ford. 

                       Popular Perl Complaints and Myths by Adam Pisoni. 

                       Perl FAQTS -- a Perl knowledge base
                       online. mod_perl.faqts 

                       Perlfaq Prime online PerlFAQ:mod_perl 


Hmm, should I add <font size=+7></font> around it? Do others find it
hidden?

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/  



Re: greetings and questions

Posted by Darren Duncan <da...@DarrenDuncan.net>.
Thanks to everyone who answered my questions in some form or other.

As it is, I *had* been reading whatever manuals I found, but those 
were the documentation that came with the mod_perl distribution on 
CPAN.

I was not aware of the existence of "http://perl.apache.org/guide/" 
and if I had been then I would have looked there.  I had seen a 
number of documents on the perl.apache.org server, but not that one. 
So thanks to those of you who pointed it out.

And no, I'm not offended by any "RTFM" comments.  I can fully 
understand that many of you would have seen the same questions asked 
over and over by people that didn't read the FAQs first.  So while I 
had read some FAQs it seems like I missed the important one.  Chalk 
it up to my first posting on a new listserv.

So I will look at The Guide now.

Thank you,

// Darren Duncan

P.S. Tom Brown, what a small world this is?

Re: greetings and questions

Posted by Jeremy Howard <jh...@fastmail.fm>.
Darren Duncan wrote:
> <...>
> Now some questions that I hope some of you can help me with.  Hopefully
> each has short answers.
> <...>
Hi Darren,

I think that all of your questions are answered in the mod_perl guide, which
is at:

  http://perl.apache.org/guide/

I don't have time right now to post a link to the answer to each individual
question, but after you've had a good look through the guide feel free to
ask again if you can't find the answer to a particular question, or if you
need clarification on some point.

PS: I hope you're not offended by this 'RTFM' reply--but the Guide will give
much better answers than I can since it's been revised over some time by the
whole community...