Jonathan Swartz > HTML-Mason-1.50 > HTML::Mason::CGIHandler



Annotate this POD


New  8
Open  2
Stalled  5
View/Report Bugs
Module Version: 1.00   Source   Latest Release: HTML-Mason-1.56


HTML::Mason::CGIHandler - Use Mason in a CGI environment


version 1.50


In httpd.conf or .htaccess:

    <LocationMatch "\.html$">
        Action html-mason /cgi-bin/mason_handler.cgi
        AddHandler html-mason .html
    <LocationMatch "^/cgi-bin/">
        RemoveHandler .html
    <FilesMatch "(autohandler|dhandler)$">
        Order allow,deny
        Deny from all

A script at /cgi-bin/ :

   use HTML::Mason::CGIHandler;

   my $h = HTML::Mason::CGIHandler->new
     data_dir  => '/home/jethro/code/mason_data',
     allow_globals => [qw(%session $u)],


A .html component somewhere in the web server's document root:

    $mood => 'satisfied'
   % $r->err_header_out(Location => "$mood.html");


This module lets you execute Mason components in a CGI environment. It lets you keep your top-level components in the web server's document root, using regular component syntax and without worrying about the particular details of invoking Mason on each request.

If you want to use Mason components from within a regular CGI script (or any other Perl program, for that matter), then you don't need this module. You can simply follow the directions in the Using Mason from a standalone script section of the administrator's manual.

This module also provides an $r request object for use inside components, similar to the Apache request object under HTML::Mason::ApacheHandler, but limited in functionality. Please note that we aim to replicate the mod_perl functionality as closely as possible - if you find differences, do not depend on them to stay different. We may fix them in a future release. Also, if you need some missing functionality in $r, let us know, we might be able to provide it.

Finally, this module alters the HTML::Mason::Request object $m to provide direct access to the CGI query, should such access be necessary.

HTML::Mason::CGIHandler Methods

$r Methods

Added $m methods

The $m object provided in components has all the functionality of the regular HTML::Mason::Request object $m, and the following:

HTML::Mason::FakeTable Methods

This class emulates the behavior of the Apache::Table class, and is used to store manage the tables of values for the following attributes of <$r>:


HTML::Mason::FakeTable is designed to behave exactly like Apache::Table, and differs in only one respect. When a given key has multiple values in an Apache::Table object, one can fetch each of the values for that key using Perl's each operator:

  while (my ($k, $v) = each %{$r->headers_out}) {
      push @cookies, $v if lc $k eq 'set-cookie';

If anyone knows how Apache::Table does this, let us know! In the meantime, use get() or do() to get at all of the values for a given key (get() is much more efficient, anyway).

Since the methods named for these attributes return an HTML::Mason::FakeTable object hash in a scalar reference, it seemed only fair to document its interface.





This software is copyright (c) 2012 by Jonathan Swartz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: