I am new to mason and am converting a large existing mod_perl project to mason.  (I love it so far!)
 
A few items have popped up that I have worked around but want to know if there is a better way.
 
The site is going to be a heavy cobranded site, so there will be different page types depending on different URLS.  Here are some pseudocode examples (I know the code is not fully correct below, it is just to illustrate the problems I am having):
 
======
 
index.html
------------
if ( [DOMAIN_NAME] == site_a ) { <& index.html-sitea &>
else { <& index.html-siteb &> }
 
 
autohandler
----------
<& header &>
$m->next
<& footer &>
 
index.html-sitea
--------
This is the main body data for sitea -- welcome to site a!
 
header
-------
<html>
<head>
<title> [[ SHOW TITLE HERE ]] </title>
</head>
<body>
 
login.html
-------------
if ( [[ first time loading page, or bad entry ]] ) { SHOW LOGIN FORM }
else { REDIRECT TO NEW PAGE }
 
=======
 
First issue: Passing a title from index.html-sitea to the header file
 
So i want to be able to set a page title in "index.html-sitea" that gets shown in the header file... if it was in index.html itself it is a little easier, but since it is in a sub-component of index.html it becomes more tricky.  What I wound up doing is having autohandler call a base component method (in index.html in this case) called "returnTitle" -- which in turn calls the same method in "index.html-sitea"... then autohandler passes it on to the header.  It is kind of messy this way... but it works.  Is there a better way to do this?  I tried many ways such as using %attr, etc. but it seems that due to the order of operations this was one of the only and most efficient ways to do it.
 
 
 
Second issue: how to stop displaying the header if the login form was successfully filled out.
 
For example, the user loads login.html which shows a form the first time.  The user enters a valid
username and password in the form then clicks "Login".  Login.html loads again and checks the form for validity -- it is successful, so we want to forward the user to a new page that welcomes them back.  The problem is, the autohandler runs first, which displays the header... so the header is output before the redirection code happens.

I found a redirect code in the mason development docs, and it does work from in login.html -- but it seems a little messy... I am guessing the reason it works is that by default the output is cached, and the redirect code is clearing the cache before doing the redirect, then aborting the footer from outputting?  I really don't like this solution but there does not seem to be much choice.

The other option would be to have the form submit to a different page, like login2.html and have that page not display a header and only either redirect back to login.html upon a failure or redirect to a new page upon success -- this is not really clean either.
 
 
I am wondering if there is a "<%preinit> type feature, or plans for one -- i think this would solve both problems.  Basically, <%init> runs only when it is the components turn in the chain, so after autohandler in this case (which is too late for both of these problems).  <%once> only executes once upon component load, which does not help.... I am thinking a <%preinit> would run every time the component is called but before the chain starts, so if someone runs "login.html", <%preinit> would run first, then autohandler would go, then $m->next_comp would run <%init> on login.html.    The preinit could do things like set the page title, or check the form before the header is output and stop output.
 
Does this already exist?.. and if not, is this a feasible feature to add to mason, or is it not technically possible under the hood.
 
I love mason overall though, the caching feature is actually what makes it so useful and perform great... it is definitely giving me the flexibility I did not have before.
 
Thanks
-John
 
 

Reply via email to