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: