simpler replacement for <%shared>

Jonathan Swartz <[email protected]>
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
The main use of the <%shared> section is to declare variables that can 
be shared between different parts of a component and that persist for a 
single request.

However, <%shared> has some disadvantages:

* It is fragile, often breaking when combined with other features. e.g. 
see bugs 213, 337, 427, 447, 535, and 546, or just search for "%shared" 
on the todo list.

* Its funky implementation - namely, recreating the closures for each 
subcomponent/method for every request - carries an unavoidable 
performance penalty (though this has never been measured).

We can provide almost the same functionality in a simpler, more reliable 
way with a restricted block that simply declares one or more shared 
request variables. e.g.

    <%request_vars>
    $a
    $b => 'default'
    %c
    </%request_vars>

The syntax of this block is familiar from the <%args> section.

Beyond implementation simplicity and efficiency, this section has 
several advantages over <%shared>:

* Mason can automatically cleanup the values of each request var at the 
end of the request. Variables declared in <%shared> cannot be 
automatically cleaned up and thus often look like leaks.

* It is possible to ask a component what its request vars are (similar 
to $comp->declared_args) and even what their current values are; useful 
for debugging and logging.

* It has a clearer name that reminds the user of the lifetime of these 
variables.

Amazon is using a section like this for reasons of efficiency, and 
developers do not seem to miss the more general <%shared> functionality. 
It does not conflict with the <%shared> section - they can coexist - but 
if we introduced this we might consider recommending it and/or slowly 
deprecating <%shared>.

Comments welcome.

Jon




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.