Re: mod-perl, modules and initializations
On Tuesday 08 January 2002 08:16 pm, Dave Morgan wrote: > I'm trying to populate select boxes(or other input types)for my HTML > pages. > An example would be a drop down list of states and/or provinces. A large > number > of these are populated from lookup tables in the dba and are relatively > static. Okay, I suspect the problem is that whenever you get a new request the setup you did for CGI.pm gets cleared. You should store the static data in a global, and then populate the CGI widget with it on every request. - Perrin
Re: mod-perl, modules and initializations
I'm trying to populate select boxes(or other input types)for my HTML pages. An example would be a drop down list of states and/or provinces. A large number of these are populated from lookup tables in the dba and are relatively static. I understand there is no form data at that time, however, when the server is up and running (and I am accessing it as a client) is when I am having the problem of extracting the data. Hope this is clearer Dave Perrin Harkins wrote: > > > By load stage I mean BEGIN blocks, anonymous > > subroutines in packages loaded at startup, or even named > > subroutines called from startup.pl > > All of those things happen during server startup, before any request has > been submitted. There is no form data at that time. > > Maybe if you could explain what you're trying to accomplish by calling > CGI methods during initialization, someone could suggest an alternative > way to do it. > > - Perrin -- Dave Morgan [EMAIL PROTECTED] 403 399 2442
Re: mod-perl, modules and initializations
> By load stage I mean BEGIN blocks, anonymous > subroutines in packages loaded at startup, or even named > subroutines called from startup.pl All of those things happen during server startup, before any request has been submitted. There is no form data at that time. Maybe if you could explain what you're trying to accomplish by calling CGI methods during initialization, someone could suggest an alternative way to do it. - Perrin
Re: mod-perl, modules and initializations
Hi All, Thanks to Perrin's help I have been able to isolate all my current problems down to whenever I make a call to CGI::scrolling_list(...); in a piece of code that is executed in the load stage of mod_perl I am unable to extract any values from my forms using CGI::param("field_name "); in my cgi scripts. By load stage I mean BEGIN blocks, anonymous subroutines in packages loaded at startup, or even named subroutines called from startup.pl If I remove the call from the load stage I can issue the scrolling_list call from any cgi (or packaged sub called from a script) and everything works fine. Versions: perl 5.6.1, mod-perl 1.26, CGI 2.78 Any ideas? other than go bug the CGI.pm people, I'm already on my way :) Perrin Harkins wrote: snip .. > It looks to me like you are confused about "our" and BEGIN. If you change > the "our" to a "use vars" I think it will fix your problems. This is not > mod_perl-specific. snip... I was able to get BEGIN blocks to work with "our", after I changed everything to the "use vars" syntax, and back. No idea what changed, don't really care, just happy :) Both the mod_perl docs and perl 5.6.1 docs are pushing the use of "our" Dave -- Dave Morgan [EMAIL PROTECTED] 403 399 2442 I cut perl the way I cut C, badly.
Re: mod-perl, modules and initializations
> What is the difference between how a BEGIN block and an anonymous block > in a module loaded into mod_perl? It looks to me like you are confused about "our" and BEGIN. If you change the "our" to a "use vars" I think it will fix your problems. This is not mod_perl-specific. > Are anonymous blocks in a module only read and executed when mod-perl > first loads them, ie once? The block in your example is not inside of a subroutine, so it will only be called once when the module is loaded. > Another problem is when I try to build a SELECT HTML element with a > call to > the CGI module. In my anonymous block all of a sudden the HTML form > variables > are no longer available with the CGI::param call. Yet I can build the > select element later in the cgi scripts using the same variables > without a problem. I'm guessing it's more scoping problems with "our." > In a simpler line, should I have a use DBI() in startup.pl as well as > the > PerlModule Apache::DBI in httpd.conf? You need to use both Apache::DBI and DBI somewhere. Either place is fine. I usually pull in lots of modules, so it's easier to do in startup.pl. - Perrin
Re: mod-perl, modules and initializations
the guide is your friend: http://perl.apache.org/guide Dave Morgan wrote: > What is the difference between how a BEGIN block and an anonymous block http://thingy.kcilink.com/modperlguide/porting/BEGIN_blocks.html > > Another problem is when I try to build a SELECT HTML element with a > call to > the CGI module. In my anonymous block all of a sudden the HTML form > variables > are no longer available with the CGI::param call. Yet I can build the > select element later in the cgi scripts using the same variables > without a problem. the above is not clear. > > In a simpler line, should I have a use DBI() in startup.pl as well as > the > PerlModule Apache::DBI in httpd.conf? you really only need one or the other. not sure if one is preferable with Apache::DBI. http://thingy.kcilink.com/modperlguide/config/PerlModule_and_PerlRequire_Direc.html > > > I will summarize and post responses. not necessary. as you can see, the guide is a professional job of summarizing these types of questions. i think you'll find it invaluable. there is also a book by the author of mod_perl: http://www.modperl.org/ if you want to do any serious mod_perl programming, you probably should read through both. -- ___cliff [EMAIL PROTECTED]http://www.genwax.com/
mod-perl, modules and initializations
Hi All, My environment is Apache, mod-perl, Apache::DBI, oracle backend, everything works fine. The problem is always MY code :) I'm trying to figure out the correct/efficient way to initialize constants in a module. What I need to do is initialize various constants when Apache is started, whether hard coded, read in from a file or extracted from a database. I have managed to thoroughly confuse myself and have the following questions. What is the difference between how a BEGIN block and an anonymous block in a module loaded into mod_perl? At different times I understand, though I probably don't understand the implications of that in a mod-perl environment. The reason I ask is: as a begin block my initializations do not take effect yet as an anonymous block they do. Or is this based in my lack of understanding of perl? Are anonymous blocks in a module only read and executed when mod-perl first loads them, ie once? Another problem is when I try to build a SELECT HTML element with a call to the CGI module. In my anonymous block all of a sudden the HTML form variables are no longer available with the CGI::param call. Yet I can build the select element later in the cgi scripts using the same variables without a problem. Huh? Did I mention I'm confused and my head hurts :} In a simpler line, should I have a use DBI() in startup.pl as well as the PerlModule Apache::DBI in httpd.conf? I will summarize and post responses. TIA Dave Code snippets # from httpd.conf AddModule mod_perl.c PerlSetEnv ORACLE_HOME /opt/oracle PerlSetEnv DSOURCE dbi:Oracle:IMG PerlSetEnv DATACLERK public_tst PerlSetEnv PSSWD opentoall PerlModule Apache::Registry PerlModule Apache::DBI PerlWarn On PerlTaintCheck On PerlRequire /opt/apache/conf/startup.pl # #all of startup.pl use CGI (); use COMMON (); use WSERVICES (); Apache::DBI->connect_on_init($ENV{"DSOURCE"}, $ENV{"DATACLERK"}, $ENV{"PSSWD"}, { PrintError => 1, #warn() on errors RaiseError => 0, # don't die on error AutoCommit => 1, # commit executes immediately } ); ### # WSERVICES.pm package WSERVICES; require Exporter; use strict; use COMMON; # wrapper for basic file and db manipulation use DBD::Oracle qw(:ora_types); use CGI qw/:html :cgi :form/; our(@DB_NAMES $FILE_NAME $NUMPERPAGE $GEOCODED_LIST $LOCATION); our @ISA= qw(Exporter); our @EXPORT = qw(@DB_NAMES $FILE_NAME $NUMPERPAGE, $GEOCODED_LIST $LOCATION example_sub); # As a begin block none of the following initializations occur # all subs in COMMON.pm { $NUMPERPAGE = 12; $FILE_NAME = &Readfile('file.txt'); #see COMMON.pm &Create_DB_Connection; @DB_NAMES = @{&Get_Select_List()}; &Destroy_DB_Connection; #following code destroys variables passed through CGI param sub # yet exact same call will work if called in cgi script or subroutine $GEOCODED_LIST = scrolling_list(-name=>'CITY_LOC', -default=>$LOCATION, -values=>\@DB_NAMES, -size=> 1); } sub examplesub{return 43;} 1; ## -- Dave Morgan [EMAIL PROTECTED] 403 399 2442 "perl Makefile.PL; make install;" is just way too convenient