View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Stas Bekman > DocSet-0.19 > Content


Annotate this POD

View/Report Bugs


Content Handler Example

Creating a content handler with mod_perl 1.0 ^

Handlers are simply perl subroutines called by the server at various stages of the HTTP request cycle. A content handler is a subroutine that is called by the response phase. Handlers, are typically created as a perl modules, separate files store in a library, and accessable via perl's @INC array.

For example, here's an example that returns a greeting and the current local time.

  package My::Greeting;
  use strict;
  use Apache::Constants qw(OK);
  sub handler {
      my $r = shift;
      my $now = scalar localtime;
      my $server_name = $r->server->server_hostname;
      print <<EOT;
  Thanks for visiting $server_name.
  The local time is $now.
      return OK;
  1; # modules must return true

Save the above as a file file in your perl library (e.g. My/ Now, to return the above greeting when the URL /hello is visited on your server:

  <Location /hello>
      SetHandler perl-script
      PerlHandler My::Greeting

For a more in-depth explanation of creating mod_perl handlers, and mod_perl in general, see the mod_perl Guide.

« back
syntax highlighting: