Steven,

ModPerl::Registry allows a standard cgi program that uses CGI.pm and other modules to 
run unchanged (or nearly unchanged) under mod_perl.  You will still need all the 
modules that are used by the cgi because the code is nearly the same.  With 
ModPerl::Registry your modules will only be compiled on first use instead of every 
time they are used (as in a regular cgi with no mod_perl).  So, ModPerl::Registry 
emulates what a cgi needs to run in the mod_perl environment.  This makes regular cgi 
programs run faster by eliminating a lot of unnecessary re-compiling.

Here is a simple cgi program that runs under registry.  It uses CGI.pm and the Oracle 
modules.  It would probably run without mod_perl if I just changed "use 
Apache::DBI();" to "use DBI();".  This is one of those modules that has a "special" 
version for mod_perl.  I may also have to add a couple lines of code (use statements) 
that are in my startup.pl, but it would run without mod_perl.

use CGI qw/:standard :html3/;
use CGI::Carp qw(fatalsToBrowser); 

use Apache::DBI();
$cgiOBJ = new CGI;

$dataSource             = "dbi:Oracle:rcidb"; # put your DSN here
$userName               = 'xxx'; # you know what goes here
$password               = 'yyy'; # and here
$dbh = DBI->connect($dataSource, $userName, $password) or die $DBI::errstr;


print $cgiOBJ->header(-expires=>'-1d'),
      $cgiOBJ->start_html(-TITLE=>'oracle test.pl',
                          -BGCOLOR=>'#FFFFFF');

print "start here<hr>";
$sql = "SELECT * FROM terminals.assets where substr(asset_part_no,1,1) = 'B'";
$sth = $dbh->prepare($sql) || die $dbh->errstr;
$rc = $sth->execute || die  $sth->errstr;
while (($firstField, $anotherField) = $sth->fetchrow_array){
        print "$firstField: $anotherField<br>\n";
}
warn $DBI::errstr if $DBI::err;
$sth->finish;
# disconnect from database
$dbh->disconnect;
print "<hr>end here";
print $cgiOBJ->end_html;

If getting those legacy cgi programs into production on a mod_perl server, the 
easiest/fastest way is to use ModPerl::Registry.  I'm happy with the speed boost I get 
from using ModPerl::Registry.  Most of the speed comes when you move the bulk of your 
code into modules instead of having a single file program.  Since Apache has to be 
re-started to see changes in modules, I prototype in single file programs or test 
programs and move code into modules as it gets perfected.

If maximum performance or serving large numbers of simultaneous users is your 
priority, you could re-write your cgi programs to use handlers instead of 
ModPerl::Registry. You may be doing a lot of writing though.  Also, if you want to do 
something really exotic in your web application you may need to write handlers.  The 
others on the list can give you more applications for that technology.

It's all a matter of your particular situation.  I had a hard time early on.  Learning 
this and perl and web development at the same time was a real exercise.  I haven't 
delved into the handlers because I haven't needed it and I have other responsibilities.

Hope this helps.

Chuck


-----Original Message-----
From: Steven Scotten [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 4:28 PM
To: [EMAIL PROTECTED]
Subject: Re: newbie confused, documentation seems contradictory and/or
incomplete.


Thanks Chuck, Glenn, and Stas!

On Jun 16, 2004, at 6:53 PM, Goehring, Chuck Mr., RCI - San Diego wrote:

> If you were not using mod_perl 1.x in your old cgi programs, you 
> probably don't need to be using any of the request stuff.  
> ModPerl::Registry does all the voodoo for you for ordinary cgi 
> programs.

OK, it sounds like maybe the purpose of ModPerl::Registry is what's 
tripping me up. After all, both ModPerl and CGI.pm do a lot of things. 
I've read many times that one "should" use the ModPerl and Apache 
modules (the "request stuff"?) *instead* of CGI.pm. I've been looking 
for drop-in replacements for CGI::param and CGI::start_html and even 
CGI::start_form amd CGI::p.

Although you say that ModPerl::Registry does all the voodoo, your code 
example includes 'use CGI qw/:standard :html3/;' which indicates to me 
that the "voodoo" does not include stuff like building forms and 
handling submissions? Yet a web search shows tens of thousands of 
examples of Apache::Request code from 1.3 doing that.

So with CGI.pm I did this:

use CGI;
$q = new CGI;
$resultofthe_blah_field = $q->param('blah'); # silly variable name for 
example

using 1.3 I think I'd do this (just pasted from 
http://httpd.apache.org/apreq/Apache-Request.html):

use Apache::Request ();
my $apr = Apache::Request->new($r);
my $value = $apr->param('foo');

...so is there a 2.0 version of this? When I try it like this I get 
"ModPerl::Registry: Can't locate Apache/Request.pm in @INC"

...or must I keep on using CGI.pm which is purportedly much slower and 
resource-hungry?

Thanks,


Steve


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to