perl-docs-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mose...@apache.org
Subject cvs commit: modperl-docs/src/start/tips config.html handler.html logging.html
Date Wed, 24 Apr 2002 04:12:18 GMT
moseley     02/04/23 21:12:18

  Added:       src/images titlegrad.gif
               src/start/tips config.html handler.html logging.html
  Log:
  Adding new files to CVS, so I can then tag.
  
  Revision  Changes    Path
  1.1                  modperl-docs/src/images/titlegrad.gif
  
  	<<Binary file>>
  
  
  1.1                  modperl-docs/src/start/tips/config.html
  
  Index: config.html
  ===================================================================
  <html>
  <head>
      <title>Configure Apache with Perl Example</title> 
      <meta name="Description" content="Configuation Example">
  </head>
  <body bgcolor="white">
  
  
  <h1>Configureing Apache using &lt;Perl&gt; sections</h1>
  
  <p>
  With mod_perl, Perl code can be embedded directly in the Apache configuration file.
  Perl in httpd.conf is commonly used to dynamically configure Apache, but anything from
  URL translation to content generation can be accomplished directly in the configuation file.
  </p>
  
  <p>
  This example reads configuration settings from a text file and configures Apache's
  virtual hosts.
  
  <p>
  The httpd.conf setup:
  </p>
  
  
  <pre>
      NameVirutalHost 192.168.1.22
  
      # Read in virtual host config from a tab-delimited file.
      &lt;Perl&gt;
          open(HOSTS,'/etc/apache/vhosts.txt')
              or die "Failed to open vhosts.txt: $!";
  
          while (&lt;HOSTS&gt;) {
              my %config;
              my @params = qw/ServerName DocumentRoot ErrorLog TransferLog ServerAdmin/;
              @config{ @params } = split /\t/;
  
              push @{$VirtualHost{'192.168.1.22'}}, \%config;
          }
          close HOSTS;
       
      
      &lt;/Perl&gt;
  </pre>
  
  
  <p>
  See <a href="../../docs/1.0/guide/config.html#toc_Apache_Configuration_in_Perl">The
Guide</a>
  for other examples of configuring Apache with mod_perl.
  </p>
  
  
  <p>
  <a class="more" href="../index.html#config">&#171&nbsp;back</a>
  </p>
  
  
  </body>
  </html>
  
  
  
  1.1                  modperl-docs/src/start/tips/handler.html
  
  Index: handler.html
  ===================================================================
  <html>
  <head>
      <title>Content Handler Example</title> 
      <meta name="Description" content="Content Handler Example">
  </head>
  <body bgcolor="white">
  
  
  <h1>Creating a content handler with mod_perl</h1>
  
  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.
  
  <pre>
      package My::Greeting;
      use strict;
    
      sub handler {
          my $r = shift;
          my $now = scalar localtime;
          my $server_name = $r-&gt;server-&gt;server_hostname;
  
          $r-&gt;send_http_header('text/plain');
          
          print &lt;&lt;EOT;
              Thanks for visiting $server_name.
              The local time is $now
          EOT
          return Apache::Constants::OK;
      }
      1; # modules must return true
  </pre>
  
  Save the above as a file file in your perl library (e.g. My/Greeting.pm).
  Now, to return the above greeting when the URL /hello is visited on your server:
  
  <pre>
      &lt;location /hello&gt;
          SetHandler perl-script
          PerlHandler My::Greeting
      &lt;/files&gt;
  </pre>
  
  
  <p>
  For a more in-depth explanation of creating mod_perl handlers see
  <a href="../../docs/index.html">Documentation</a>.
  The <a href="../../docs/1.0/guide/index.html">mod_perl Guide</a> is also recommended
  reading.
  
  
  <p>
  <a class="more" href="../index.html#handler">&#171&nbsp;back</a>
  </p>
  
  
  </body>
  </html>
  
  
  
  1.1                  modperl-docs/src/start/tips/logging.html
  
  Index: logging.html
  ===================================================================
  <html>
  <head>
      <title>Log Handler Example</title> 
      <meta name="Description" content="Log Handler Example">
  </head>
  <body bgcolor="white">
  
  
  <h1>Creating a PerlLogHandler</h1>
  
  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.
  </p>
  <p>
  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.
  </p>
  
  <pre>
      package My::Notify;
      use strict;
      use Apache::Constants(':common');
  
      use Mail::Send;
  
      sub handler {
          my $r = shift;
  
          my $email = $r-&gt;server-&gt;server_admin || return DECLINED;
  
          my $mail = Mail::Send->new(
              To      =&gt; $email,
              Subject =&gt; "mod_perl Notification",
          );
          my $file = $r->filename;
          my $fh = $mail-&gt;open;
          $fh-&gt;print("File '$file' was accessed");
          $fh-&gt;close;
  
          return DECLINED; # let apache write to the lot
      }
      1; # modules must return true
  </pre>
  
  <p>
  
  The httpd.conf setup:
  
  
  <pre>
      &lt;location /private&gt;
          SetHandler perl-script
          PerlLogHandler My::Notify
      &lt;/location&gt;
  </pre>
  
  
  
  <p>
  <a class="more" href="../index.html#logging">&#171&nbsp;back</a>
  </p>
  
  
  </body>
  </html>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org


Mime
View raw message