Re: simpler replacement for <%shared>

michael bayer <[email protected]>
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
hey, totally random idea -

ive recently starting adding XML-attribute-like entities to some of the 
<%tags> in myghty.  with this particular issue, this syntax comes to 
mind:

# request scoped arguments, available across all components within the 
template
<%args scope="request">
	$foo => 'bar'
</%args>

# component scoped arguments, what %args does already
<%args scope="component">
	$l => 3
</%args>

which I like mainly because users have fewer kinds of tags to learn, 
but with a richer featureset within each tag (which theoretically also 
increases understanding of that tag).

also of note, i never used %shared at all with mason, where it appeared 
to be mysterious and flaky....but once I ported it to myghty and called 
it %requestlocal, i find myself using it all the time (and its 
implementation is pretty similar, with the closures and all).  go 
figure.


On Sep 28, 2004, at 2:39 PM, Jonathan Swartz wrote:

> 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
> _______________________________________________
> Mason-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-devel


-------------------------------------------------------
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.