You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs-cvs@perl.apache.org by st...@apache.org on 2003/07/15 12:30:35 UTC
cvs commit: modperl-docs/src/docs/2.0/user/config config.pod
stas 2003/07/15 03:30:33
Modified: src/docs/2.0/user/config config.pod
Log:
add examples to demonstrate the difference between modperl and perl-script
SetHandlers
Revision Changes Path
1.40 +89 -0 modperl-docs/src/docs/2.0/user/config/config.pod
Index: config.pod
===================================================================
RCS file: /home/cvs/modperl-docs/src/docs/2.0/user/config/config.pod,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- config.pod 23 May 2003 07:37:21 -0000 1.39
+++ config.pod 15 Jul 2003 10:30:33 -0000 1.40
@@ -293,6 +293,95 @@
=back
+=head3 Examples
+
+Let's demonstrate the differences between the C<modperl> and the
+C<perl-script> core handlers in the following example, which
+represents a simple mod_perl response handler which prints out the
+environment variables as seen by it:
+
+ file:MyApache/PrintEnv1.pm
+ -----------------------
+ package MyApache::PrintEnv1;
+ use strict;
+
+ use Apache::RequestRec (); # for $r->content_type
+ use Apache::RequestIO (); # for print
+ use Apache::Const -compile => ':common';
+
+ 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:
+
+ PerlModule MyApache::PrintEnv1
+ <Location /print_env1>
+ SetHandler perl-script
+ PerlResponseHandler MyApache::PrintEnv1
+ </Location>
+
+Now issue a request to I<http://localhost/print_env1> and you should
+see all the environment variables printed out.
+
+Here is the same response handler, adjusted to work with the
+C<modperl> core handler:
+
+ file:MyApache/PrintEnv2.pm
+ ------------------------
+ package MyApache::PrintEnv2;
+ use strict;
+
+ use Apache::RequestRec (); # for $r->content_type
+ use Apache::RequestIO (); # for $r->print
+
+ use Apache::Const -compile => ':common';
+
+ 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 as:
+
+ PerlModule MyApache::PrintEnv2
+ <Location /print_env2>
+ SetHandler modperl
+ PerlResponseHandler MyApache::PrintEnv2
+ </Location>
+
+C<MyApache::PrintEnv2> cannot use C<print()> and therefore uses
+C<$r-E<gt>print()> to generate a response. Under the C<modperl> core
+handler C<%ENV> is not populated by default, therefore
+C<subprocess_env()> is called in a void context. Alternatively we
+could configure this section to do:
+
+ PerlOptions +SetupEnv
+
+If you issue a request to I<http://localhost/print_env2>, you should
+see all the environment variables printed out as with
+I<http://localhost/print_env1>.
+
+
+
=head2 C<PerlOptions>
The directive C<PerlOptions> provides fine-grained configuration for
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org