Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_perl design concept questions 1

Status
Not open for further replies.

widdgetz

Technical User
Aug 31, 2003
35
0
0
US
I am designing a web site in Perl, and although I have worked with perl for several years, I have just started researching mod_perl 2.

Before mod_perl, a basic perl script used in this project could be abstracted as follows:
• Browser hits contribute.pl
• contribute.pl loads custom module Perl::Output
• contribute.pl loads CGI input from global $q = new CGI variable exported by Perl::Output
• contribute.pl appends all content to global $body variable exported by Perl::Output
• contribute.pl calls printHTML in Perl::Output which wraps $body in the page template and prints everything back to the browser

I am just not able to wrap my mind around the concept of Apache handlers - whether I need to write any and for what - and the scope of variables.

My script works under mod_perl, but unless I re-initialize the variables at the start of the script, the page is appended to the last $body output. I think, though, that there will only be one copy of $body for all requests and everything would get messed up.

Can someone enlighten me as to the proper way to do this sort of thing with mod_perl? It seems like Output.pl could be converted to a content handler but I am very confused about how everything ties together - how I would print the output from a script like contribute.pl using a modularized Output.pm...
 
because the modules (scripts) stay in memory after the iitial load, the performance gain is dramatic. But as you discovered. variables persist.

The modperl wrappers for plain perl scripts put your variables at a global scope. You can work around this by using variables scoped withing { }'s and the my() keyword.

See for info about the scoping. also has some relevant comments

Wrapping the original script (and variables) inside
Code:
sub handler { 

}
should eliminate side effects for you. This type of handler must be registered in the httpd.conf file

mod_perl is also good if you want to hook into any of apache's lifecycle events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top