info > HTML::Mason::CGIHandler

📚 NAME

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

🚀 Quick Reference

Use CaseCommandDescription
🧩 Configure Apache for Mason <LocationMatch "\.html$">
Action html-mason /cgi-bin/mason_handler.cgi
AddHandler html-mason .html
(plus protection rules)
Set up Apache to invoke Mason CGI handler for .html files, while protecting handler scripts and dhandler/autohandler.
🖥️ Create CGI handler script my $h = HTML::Mason::CGIHandler->new( data_dir => '/path', allow_globals => [qw(%session $u)] );
$h->handle_request;
Initialize handler with interpreter options and process the current request.
📝 Write a component with args <%args>
$mood => 'satisfied'
</%args>
% $r->err_header_out(Location => "http://...$mood.html");
Use Mason component syntax with argument declarations and $r for redirect.
🔄 Handle a specific component path $h->handle_comp('/path/to/component'); Execute a particular component, parsing query params and sending HTTP header.
📦 Handle a CGI object directly $h->handle_cgi_object($cgi_object); Use with CGI::Fast or custom CGI object; component path from $cgi->path_info().
🔍 Access CGI query from component $m->cgi_object (returns CGI object) Get the current CGI request object for cookies, form data, etc.

📋 SYNOPSIS

In httpd.conf or .htaccess:

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

A script at /cgi-bin/mason_handler.pl :

#!/usr/bin/perl
use HTML::Mason::CGIHandler;

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

$h->handle_request;

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

<%args>
 $mood => 'satisfied'
</%args>
% $r->err_header_out(Location => "http://blahblahblah.com/moodring/$mood.html");
...

📝 DESCRIPTION

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, plus:

📋 HTML::Mason::FakeTable Methods

This class emulates Apache::Table and is used to manage tables of values for: headers_in, headers_out, err_headers_out, notes, subprocess_env. It differs only in that multiple values for a key cannot be fetched via each; use get() or do() instead.


perl v5.30.2 2020-05-22 HTML::Mason::CGIHandler(3pm)

HTML::Mason::CGIHandler
📚 NAME 🚀 Quick Reference 📋 SYNOPSIS 📝 DESCRIPTION
⚙️ HTML::Mason::CGIHandler Methods 🔧 $r Methods ➕ Added $m methods 📋 HTML::Mason::FakeTable Methods

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-28 10:19 @216.73.216.117
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!