Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I use Mason a lot. Mostly on a mod_perl server. It can run, a bit slowly, in cgi mode. You can also run with FastCGI, although you lose some mod_perl based functionality.

Mason has a pretty high overhead in CGI-mode, because you'll need to load the interpreter, handler, and parser objects, and then load your component and any modules used by any of these pieces for every page view. Speed is acceptable if you have very low traffic. Any persistance framework (ISAPI, mod_perl, etc.) will help a lot.

There is an excellent article on masonhq called Design Issues with Mason. It should answer your question about not using embedded code. You can also use components in a MVC style--some components are used for display, some for app logic, and some for data access. Whichever style you use, mason's embedded code capability makes creating working prototype applications incredibly fast and easy.

Probably the coolest thing about Mason is it's parameter handling. You have THREE different ways of getting params, and it can be useful to mix them. You can declare an <%args> section in your component, and name your variables:

<%args> $foo => 'FOO!' # the value of foo goes here, default value "FOO!" @bar # Here we ask for a list of bar values, no default means bar is +a required param. $dog => $foo.'dog' # You can have dynamic defaults. $cat => undef # or undef by default. </%args>

You can also just pull things out of @_, just like a perl subroutine, which is actually what a mason component compiles into. And third, you can use the magnificent %ARGS hash. This is really handy for building components that print form data in a pretty way without having to hard code in fields:

<HTML><head><title>STUFF</title></head> <body> <table> % foreach my $field ( keys %fieldSpecs ) { <tr><td><% $field %></td><td><% $ARGS{$field} %></td></tr> % } </table> </body> </HTML> <%args> %fieldSpecs </%args>

Of course a real usage of the above would need to be a bit more complex. You can manipulate one structure without affecting the others. This has proven to be rather handy.

Dhandlers, autohandlers and inheritance are also very cool mason features. Autohandlers provide a way of creating nested templates and core functionality common to entire hierarchies on your server. If you have a file at /home/html/foo/bar/baz.html, it will automatically invoke the autohandlers at /home/html/autohandler (I'm assuming /home/html/is you doc root), /home/html/foo/autohandler, /home/html/foo/bar/autohandler. Combined with inheritance we have a very powerful feature. You can create sub components that live inside a main, parent component, if you specify that they are 'method's they can then be inherited. For example if you want every component on your website to be able to find print the time in roman numerals, you write a method to do this, then stick it in your root authandler. Then in any component you can call $m->comp(SELF:RomanTime) to get the results. Dhandlers allow you to specify how to react to requests for files that don't exist. Say you have all your content in xml stored in a database. You can write a dhandler that translates an html document request into a call to routines that look up the appropriate xml in the db, transform it to html. Your autohandler will take care of wrapping it in your standard templates for you.

That's my Mason is Cool rant. I hope you have found it useful. Check out Bricolage and RT, a couple of impressive Mason apps. Plus, VIm has a syntax definition for Mason.


TGI says moo


In reply to Re: Re: Re: More on Web Application Frameworks by TGI
in thread More on Web Application Frameworks by impossiblerobot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 10:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found