Code > Site-Level autohandler

Download Plaintext Version

Init block

<%init>
    # $dbh is declared to be a Mason global in httpd.conf ("PerlSetVar
    # MasonAllowGlobals $dbh").  We open a database handler here so that it
    # is available to any other component that might want one.  We also load
    # Apache::DBI in httpd.conf so database handles are transparently reused,
    # reducing startup costs.

    $dbh = DBI->connect('DBI:Pg:', $DB_USERNAME, $DB_PASSWORD,
        { RaiseError => 1 } );

    # The contortions we go through here to get the body allow top level
    # components to redirect, send binary files, and/or abort should they
    # choose to do so, while still allowing them to die normally as well.
    # This also allows title/page-head/navigation methods in top level
    # components to do their intended jobs, too.  This approach is based
    # on the documentation at:  http://www.masonhq.com/?ScompAndAbort

    my $body;

    eval { $m->comp({ store => \$body }, $m->fetch_next, %ARGS) };

    if (my $error = $@) {
        print $body if $m->aborted;
        die $error;
    }

    # An empty navigation component (such as the one in this autohandler)
    # still returns whitespace, which, for the purposes of choosing how to
    # layout the page, we interpret to mean there is no navigation.

    my $navigation = $m->scomp('SELF:navigation');
       $navigation = undef if $navigation !~ /\S/;
</%init>

Method: title

<%method title>
  <%init>
    # The page title will usually be the same as the page header, but any
    # anchor tags must be removed.

    my $title =  $m->scomp('SELF:page-head');
       $title =~ s{</?a(>| [^>]*?>)}{}g;
  </%init>

    <% $title %>
</%method>

Method: page-head

<%method page-head>
    Memphis Amiga Group (MAG) History
</%method>

Method: navigation

<%method navigation>
</%method>