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


Annotate this POD

View/Report Bugs


Log Handler Example

Creating a PerlLogHandler ^

Every request phase can be controlled using mod_perl. Here's an example of a PerlLogHandler. The PerlLogHandler is one of the last phases of the request cycle.

This example sends mail when a request is made to the /private section of your web space. A more common use of a PerlLogHandler might be to track hits on a specific set of URLs, or to write logging data to a relational database.

  package My::Notify;
  use strict;
  use Apache::Constants qw(:common);

  use Mail::Send;

  sub handler {
      my $r = shift;

      my $email = $r->server->server_admin || return DECLINED;

      my $mail = Mail::Send->new(
          To      => $email,
          Subject => "mod_perl Notification",
      my $file = $r->filename;
      my $fh = $mail->open;
      $fh->print("File '$file' was accessed");

      return DECLINED; # let apache write to the lot
  1; # modules must return true

The httpd.conf setup:

  <Location /private>
      SetHandler perl-script
      PerlLogHandler My::Notify
« back
syntax highlighting: