![]() |
Practical mod_perl / HTML Book / | ![]() |
||
![]() |
||||
![]() |
![]() |
|||
![]() |
![]() |
|||
![]() |
||||
|
|
||||
![]() |
![]() |
|||
![]() |
24.5.5.3. A simple response handler example |
![]() |
||
![]() |
||||
![]() |
![]() |
![]() |
||
![]() |
||||
Let's demonstrate the differences between the modperl and perl-script core handlers. Example 24-2 represents a simple mod_perl response handler that prints out the environment variables as seen by it.
package Apache::PrintEnv1;
use strict;
use warnings;
use Apache::RequestRec ( ); # for $r->content_type
use Apache::Const -compile => 'OK';
sub handler {
my $r = shift;
$r->content_type('text/plain');
for (sort keys %ENV){
print "$_ => $ENV{$_}\n";
}
return Apache::OK;
}
1;
This is the required configuration for the perl-script handler:
PerlModule Apache::PrintEnv1
<Location /print_env1>
SetHandler perl-script
PerlResponseHandler Apache::PrintEnv1
</Location>
Now issue a request to http://localhost/print_env1, and you should see all the environment variables printed out.
The same response handler, adjusted to work with the modperl core handler, is shown in Example 24-3.
package Apache::PrintEnv2;
use strict;
use warnings;
use Apache::RequestRec ( ); # for $r->content_type
use Apache::RequestIO ( ); # for $r->print
use Apache::Const -compile => 'OK';
sub handler {
my $r = shift;
$r->content_type('text/plain');
$r->subprocess_env;
for (sort keys %ENV){
$r->print("$_ => $ENV{$_}\n");
}
return Apache::OK;
}
1;
The configuration now will look like this:
PerlModule Apache::PrintEnv2
<Location /print_env2>
SetHandler modperl
PerlResponseHandler Apache::PrintEnv2
</Location>
Apache::PrintEnv2 cannot use print( ), so it uses $r->print( ) to generate a response. Under the modperl core handler, %ENV is not populated by default; therefore, subprocess_env( ) is called in a void context. Alternatively, we could configure this section to do:
PerlOptions +SetupEnv
If you issue a request to http://localhost/print_env2, you should see all the environment variables printed out as with http://localhost/print_env1.
 
Continue to:
mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice
![]() |
Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.