Mason Web Server

Mason Web Server


Mason is a fantastic object-oriented web-authoring system built on Perl.

Overview

I grew very tired of updating sites the "old-fashioned" way, making dozens of changes whenever the look or feel of a website changed. This site, and others I have been involved with, use Mason extensively, allowing me to make drastic site re-designs with only a few modifications.

Mason is an Apache handler written in Perl, and can sometimes be a bit of effort to get configured correctly. I am posting my configurations here so that it will hopefully be of some use.

NOTE: As of Fedora Core 6, Mason has been packaged into RPM format (thank god) as perl-HTML-mason. The below configuration may still be useful as a reference, particularly if you want to link your own modules into Mason.

Apache Configuration

httpd.conf

NOTE: Make sure index.mhtml and index.mhtm are in your DirectoryIndex

### MASON

# Configure perl environment and fire up some handy perl modules
PerlRequire /etc/httpd/conf/mod_perl_startup.pl

# External modules need to be linked with the Commands namespace to be used by mason components.
<Perl>
{ package HTML::Mason::Commands;
  use FritzMason;       # my library
}
</Perl>

PerlSetVar  MasonArgsMethod  CGI

PerlModule HTML::Mason::ApacheHandler

# Anything ending in these file extensions gets handled by mason
<LocationMatch "\.m(html|htm)$">
           SetHandler perl-script
           PerlHandler HTML::Mason::ApacheHandler
</LocationMatch>
# Anything ending in these file extensions gets an error (kludge)
<LocationMatch "\.(mas|fla|xcf|psd)|autohandler$">
           SetHandler perl-script
           PerlInitHandler Apache2::Constants::NOT_FOUND
#          ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
</LocationMatch>

mod_perl_startup.pl

NOTE: This Perl script is called by the Apache PerlRequire directive, and loads all the modules referenced below into memory. You may or may not want all of this, but it can be a performance saver depending on the environment.

#!/usr/bin/perl
 use Apache2::compat ();
 use ModPerl::Util (); #for CORE::GLOBAL::exit
 use Apache2::RequestRec ();
 use Apache2::RequestIO ();
 use Apache2::RequestUtil ();
 use Apache2::ServerRec ();
 use Apache2::ServerUtil ();
 use Apache2::Connection ();
 use Apache2::Log ();
 use Apache::Session ();
 use CGI ();
 use CGI::Cookie ();
 use APR::Table ();
 use ModPerl::Registry ();
 use Apache2::Const -compile => ':common';
 use APR::Const -compile => ':common';
 use Carp ();

 1;



ctime: 2004-07-08