On Aug 18, 2009, at 6:36 AM, Jochem Jofel wrote:

Hi, I've recently discovered the HTML::Mason software and the book: Embedding Perl in HTML with Mason. I find the Mason prospect promising because of the flexible component approach, and I hope to be able to use it for a site that presumably will be a high traffic site (thus not very well suited for a (fast)CGI approach) but one crucial thing escapes me. I've created a Mason component that displays a HTML form (see: attachment). In accordance with the suggestion(s) in the book I want to call a perl module that handles the request, AFTER the form is submitted. In the perl module to call I need FULL access to the query parameters and their value(s).

I would normally make a Mason component that handles the form submission, receiving the form arguments as input variables in the %args section. This is one of the things Mason is good for -- letting you develop convenient names for the input parameters, and ensuring they get unencoded properly and stored in the variables. From that component, you can have an %init section that calls out to your perl module. In MVC parlance, you'd be using Mason as the controller and the view, but implementing your model in a perl module.

You have the choice of whether the Mason component that handles the form submission will be implemented in the same component that renders the form or not. For simple things, I often do it in the same form (the post submission goes right back to the same URL, but provides parameters). For more complex things, I sometimes make a separate component (for which I invented a convention: formname-proc.html) that receives the parameters, does any processing or updating of the database, and then redirects the user to the right place. Sometimes that's just a redirect back to formname.html. This way, if the user hits refresh, they won't re-execute the logic of the -proc: they will just reload formname.html.

Specifically: I want to call a handler module that checks which submit button has been activated and then executes the necessary code in each (of three) case(s). I've not been able to find anything suitable in the book or on the internet to do this. Can you please advise me how to achieve this? Or is this something that can only be done (properly) in a CGI environment?

Splitting on these 3 cases is a great job for a controller, logically. That means I would put it in the %init section of the - proc component. It could look like this:

user-proc.html:
<%args>
$username
$old_password
$new_password
$deletebutton
</%args>
<%init>
if ($username and $old_password and $new_password) {
  Myprog::User->update_password($username,$old_password,$new_password);
$m->redirect($r->header_in('Referer')); # Take them back to the same edit-user page to show them their updates have been done
} elsif ($username and $deletebutton) {
  Myprog::User->delete($username);
  # TODO: delete the session
$m->redirect('/'); # they deleted themselves; log them out and go to home page
}
</%init>

It's kind of a bad example (and certainly a made-up one), but it shows the concept of putting controller logic in a Mason component, and calling out to perl modules.

Thanks for any useful advise you may have to offer.
Jochem

Express yourself instantly with MSN Messenger! MSN Messenger < admin_maintain_entity_table .mas > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  
http://p.sf.net/sfu/bobj-july_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to