Re: Reloading Library Files
Stas Bekman wrote: Ted Prah wrote: Thanks Drew, I tried that, but it did not work. What happends if you add: PerlWarn On in httpd.conf or start the script with perl -w? any warnings? I had PerlWarn On and added -w anyway, but there were no errors. do you test only this script alone? What happens if you add the package declaration and then call it using the full name? e.g.: Yes, this is the only script (and corresponding library file) that I use for this test. When I use the package declaration and make the call using the full name, the reloads work fine. The reason I am using the library file is to follow your recommendation in the mod_perl guide where a script is split into two files to avoid the nested subroutine problem. Out of curiosity I tested the sample code (counter.pl and mylib.pl) and they too did not reload properly when mylib.pl was modified. Does the reloading of a modification of mylib.pl work for you? I would prefer to use the library file approach as opposed to the package approach as a lot of our code uses libraries that are not in packages, but will move to packages if that is a necessity. Thank you, I really appreciate your help. z.pl - test script which calls entry_point in z_lib.pl --- #!/usr/local/bin/perl -w use strict; require '/home/cgi-bin/z_lib.pl'; My::Z::entry_point(); --- z_lib.pl -- package My::Z; use strict; sub entry_point { my $r = Apache-request; $r-content_type('text/html'); $r-send_http_header; print HERE 1; #print HERE 2; } Ted Drew Taylor wrote: Have you tried moving the PerlInitHandler PerlSetVar up and out of the Location directive, making it global for the server? I'm not sure that would fix it, but it's worth a try. Drew At 02:37 PM 5/17/02 -0400, Ted Prah wrote: I have tried Apache::Reload as well, but I get the same results. Ted Drew Taylor wrote: Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 == -- Ted Prah NetCasters, Inc. Phone: 978.887.2100 x44 Fax: 978.887.6750 [EMAIL PROTECTED] -- __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com -- Ted Prah NetCasters, Inc. Phone: 978.887.2100 x44 Fax: 978.887.6750 [EMAIL PROTECTED]
Re: Reloading Library Files
Ted Prah wrote: do you test only this script alone? What happens if you add the package declaration and then call it using the full name? e.g.: Yes, this is the only script (and corresponding library file) that I use for this test. When I use the package declaration and make the call using the full name, the reloads work fine. The reason I am using the library file is to follow your recommendation in the mod_perl guide where a script is split into two files to avoid the nested subroutine problem. Out of curiosity I tested the sample code (counter.pl and mylib.pl) and they too did not reload properly when mylib.pl was modified. Does the reloading of a modification of mylib.pl work for you? I would prefer to use the library file approach as opposed to the package approach as a lot of our code uses libraries that are not in packages, but will move to packages if that is a necessity. Well, that explains everything. When you require() a library without that doesn't declare a package for the first time from the registry script, all its global symbols (subs, vars, etc) get imported into the namespace of the caller, i.e. the registry script (APACHE::ROOT::...). When Apache::Reload require()s that library that doesn't declare a package, all the global symbols end up in the Apache::Reload namespace! So the library does get reloaded and you see the compile time errors if there are any, but the symbols don't get imported to the right namespace. So the old code is running. Moreover this leads to a pollution of the Apache::Reload namespace, which may cause to problems if you happen to overwrite some of its symbols (subs, vars, etc). I suppose if you want to use the cheap workaround, you have to s/require/do/. Remember that the guide suggests the lib.pl trick as a workaround, not a solution you go with during the normal development. Was this explanation clear enough? We need to add it to the Apache::Reload manpage to avoid this kind of questions in the future. Funny though, that it's the first time this problem has been reported. Which shows that most of the people don't use workarounds when they do real developments :) __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Reloading Library Files
Stas Bekman wrote: Ted Prah wrote: do you test only this script alone? What happens if you add the package declaration and then call it using the full name? e.g.: Yes, this is the only script (and corresponding library file) that I use for this test. When I use the package declaration and make the call using the full name, the reloads work fine. The reason I am using the library file is to follow your recommendation in the mod_perl guide where a script is split into two files to avoid the nested subroutine problem. Out of curiosity I tested the sample code (counter.pl and mylib.pl) and they too did not reload properly when mylib.pl was modified. Does the reloading of a modification of mylib.pl work for you? I would prefer to use the library file approach as opposed to the package approach as a lot of our code uses libraries that are not in packages, but will move to packages if that is a necessity. Well, that explains everything. When you require() a library without that doesn't declare a package for the first time from the registry script, all its global symbols (subs, vars, etc) get imported into the namespace of the caller, i.e. the registry script (APACHE::ROOT::...). When Apache::Reload require()s that library that doesn't declare a package, all the global symbols end up in the Apache::Reload namespace! So the library does get reloaded and you see the compile time errors if there are any, but the symbols don't get imported to the right namespace. So the old code is running. Moreover this leads to a pollution of the Apache::Reload namespace, which may cause to problems if you happen to overwrite some of its symbols (subs, vars, etc). That explains the library files not reloading - Thanks! I suppose if you want to use the cheap workaround, you have to s/require/do/. Remember that the guide suggests the lib.pl trick as a workaround, not a solution you go with during the normal development. I didn't realize that using the library wrapper was a cheap workaround to the nested subroutine problem. The effects of the nested subroutine problem is my biggest concern with writing code for mod_perl. What I liked about the lib.pl trick is that it completely eliminates this problem. I won't lose sleep wondering if somehow the code went into production with a nested subroutine. I realize that there are other ways to eliminate the nested subroutine problem, but what are the preferred techniques used by mod_perl developers? Check the error_log file for problems and fix as needed? Was this explanation clear enough? We need to add it to the Apache::Reload manpage to avoid this kind of questions in the future. Makes sense. Funny though, that it's the first time this problem has been reported. Which shows that most of the people don't use workarounds when they do real developments :) __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com -- Ted Prah NetCasters, Inc. [EMAIL PROTECTED]
Re: Reloading Library Files
Ted Prah wrote: That explains the library files not reloading - Thanks! Great! I suppose if you want to use the cheap workaround, you have to s/require/do/. Remember that the guide suggests the lib.pl trick as a workaround, not a solution you go with during the normal development. I didn't realize that using the library wrapper was a cheap workaround to the nested subroutine problem. The effects of the nested subroutine problem is my biggest concern with writing code for mod_perl. What I liked about the lib.pl trick is that it completely eliminates this problem. I won't lose sleep wondering if somehow the code went into production with a nested subroutine. I realize that there are other ways to eliminate the nested subroutine problem, but what are the preferred techniques used by mod_perl developers? Check the error_log file for problems and fix as needed? The majority are discussed here: http://perl.apache.org/release/docs/general/perl_reference.html#Remedies_for_Inner_Subroutines Declaring the package in your libs is a good idea. Because if you don't, most likely you are going to encounter this problem: http://perl.apache.org/release/docs/1.0/guide/porting.html#Name_collisions_with_Modules_and_libs The solutions are discussed there as well. Check the error_log file for problems and fix as needed? Ted, this is not an option, this is a must thing to do. If you don't monitor constantly the error_log file while developing you are looking for a trouble. http://perl.apache.org/release/docs/1.0/guide/debug.html#Warning_and_Errors_Explained __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Reloading Library Files
Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. Hmm, I haven't used StatINC for a long time, any luck with Apache::Reload? http://perl.apache.org/guide/porting.html#Using_Apache_Reload __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Reloading Library Files
Ted Prah wrote: Thanks Drew, I tried that, but it did not work. What happends if you add: PerlWarn On in httpd.conf or start the script with perl -w? any warnings? do you test only this script alone? What happens if you add the package declaration and then call it using the full name? e.g.: z.pl - test script which calls entry_point in z_lib.pl --- #!/usr/local/bin/perl -w use strict; require '/home/cgi-bin/z_lib.pl'; My::Z::entry_point(); --- z_lib.pl -- package My::Z; use strict; sub entry_point { my $r = Apache-request; $r-content_type('text/html'); $r-send_http_header; print HERE 1; #print HERE 2; } Ted Drew Taylor wrote: Have you tried moving the PerlInitHandler PerlSetVar up and out of the Location directive, making it global for the server? I'm not sure that would fix it, but it's worth a try. Drew At 02:37 PM 5/17/02 -0400, Ted Prah wrote: I have tried Apache::Reload as well, but I get the same results. Ted Drew Taylor wrote: Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 == -- Ted Prah NetCasters, Inc. Phone: 978.887.2100 x44 Fax: 978.887.6750 [EMAIL PROTECTED] -- __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Reloading Library Files
Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. z.pl - test script which calls entry_point in z_lib.pl --- #!/usr/local/bin/perl use strict; require '/home/cgi-bin/z_lib.pl'; entry_point(); --- z_lib.pl -- #!/usr/local/bin/perl use strict; sub entry_point { my $r = Apache-request; $r-content_type('text/html'); $r-send_http_header; print HERE 1; #print HERE 2; } 1; -- My Test Procedure: 1.) Start server (w/ -X option) 2.) Run z.pl via browser - output is HERE 1 3.) Uncomment out second print statement in z_lib.pl 4.) Reload z.pl via browser - output is HERE 1 I would expect it to display the output of the second print statement, but it does not. 5.) Re-start server 6.) Run z.pl via browser - output is HERE 1 HERE 2 If I deliberately put an error in z_lib.pl and reload z.pl, I receive an error message. So, it appears that the library file z_lib.pl is getting reloaded. But why don't my changes show up? Also, here is the output in the error_log that displays Apache::StatINC messages Apache::StatINC: process 21891 reloading /home/cgi-bin/z_lib.pl. Apache::StatINC::handler('Apache=SCALAR(0x211220)') called at /dev/null line 0 eval {...} called at /dev/null line 0 I have extended INC by using use lib .. in the startup file. I have read through the mod_perl guide at http://apache.perl.org/, but am unable to resolve this problem. Should I replace the 'require's with 'do's in development and then switch back to requires when moving to production? My Environment: perl version: 5.6.1 mod_perl version: 1.26 apache version: 1.3.24 OS: Solaris 2.8 from httpd.conf PerlWarn On PerlModule Apache::StatINC PerlRequire /httpd/conf/startup.pl Alias /cgi-bin/ /home/cgi-bin/ PerlModule Apache::Registry Location /cgi-bin SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI allow from all PerlSendHeader On PerlInitHandler Apache::StatINC PerlSetVar StatINC_Debug 1 /Location startup.pl --- use strict; # Extend INC if needed use lib qw(/home/cgi-bin); # Make sure we are in a sane environment. $ENV{MOD_PERL} or die not running under mod_perl!; # Don't include the name of the virtual host in the package name $Apache::Registry::NameWithVirtualHost = 0; # Load Perl modules of your choice here # This code is interpreted *once* when the server starts use Apache::DBI (); use DBI (); # Tell me more about warnings use Carp (); $SIG{__WARN__} = \Carp::cluck; 1; --- Thanks for any help you can provide, Ted
Re: Reloading Library Files
Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 ==
Re: Reloading Library Files
I have tried Apache::Reload as well, but I get the same results. Ted Drew Taylor wrote: Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 ==
Re: Reloading Library Files
Have you tried moving the PerlInitHandler PerlSetVar up and out of the Location directive, making it global for the server? I'm not sure that would fix it, but it's worth a try. Drew At 02:37 PM 5/17/02 -0400, Ted Prah wrote: I have tried Apache::Reload as well, but I get the same results. Ted Drew Taylor wrote: Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 ==
Re: Reloading Library Files
Thanks Drew, I tried that, but it did not work. Ted Drew Taylor wrote: Have you tried moving the PerlInitHandler PerlSetVar up and out of the Location directive, making it global for the server? I'm not sure that would fix it, but it's worth a try. Drew At 02:37 PM 5/17/02 -0400, Ted Prah wrote: I have tried Apache::Reload as well, but I get the same results. Ted Drew Taylor wrote: Take a look at Apache::Reload or Apache::StatINC. Reload is more flexible, but StatINC has been around a little longer. Both have worked well for me. But be sure that you don't use these modules on a production server. :-) httpd.conf == PerlInitHandler Apache::Reload Drew At 01:38 PM 5/17/02 -0400, Ted Prah wrote: Hi, I am new to mod_perl and am having problems seeing the changes made to library files. Must I restart the server every time I change a library file in order to see my changes? My test code and environment is below. == Drew Taylor | Freelance web development using http://www.drewtaylor.com/ | perl/mod_perl/MySQL/postgresql/DBI mailto:[EMAIL PROTECTED] | Email jobs at drewtaylor.com -- Speakeasy.net: A DSL provider with a clue. Sign up today. http://www.speakeasy.net/refer/29655 == -- Ted Prah NetCasters, Inc. Phone: 978.887.2100 x44 Fax: 978.887.6750 [EMAIL PROTECTED]