Re: extending <% | %>
Scott Lanning <[email protected]> Thu, 14 Feb 2008 13:41:30 +0100 (CET)
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 31 Jan 2008, Hans Dieter Pearcey wrote: > On Wed, Jan 16, 2008 at 11:12:04AM -0500, Hans Dieter Pearcey wrote: >> Attached is a patch that makes | in substitutions more powerful. > > The biggest problem is with using '|'. While I think it's unlikely that anyone > is doing lots of bitwise-or inside <% %>, it's not impossible that someone > would write a regex that matches the pattern I'm using for finding filters; it > is roughly: > > /\| \s* \w+(\(.*\))? \s* $/x > > which matches, for example, > > <% $x =~ m(foo|bar(baz)?) %> > > I can't think of a really satisfactory way to solve this. I definitely do not > want to get too heavily into trying to parse Perl, and the only alternative I > can think of is to use a different delimiter for these kinds of filters. > > I generated a whole bunch of examples with different delimiters, and I've > attached them, but I don't really like any of them, either, and most of them > wouldn't completely sidestep the problem anyway. > > Anyone have better ideas? I would love to hear them. Would backslashing non-delimiting pipes be bad? <% $x =~ m(foo\|bar(baz)?) %> The list of delimiters that you made made me think that pipes could probably be generalized to filehandles or something -- I guess that's the same as what Otto was getting at with streams. You could probably easily get carried away, though. Like I was thinking how you could pipe SQL to a database (there's already an implicit redirection of the output of <% %> to "out_method"), get its output, pass to whatever formatter... but in the end, it probably would be just as easy to do it in a <%perl> block. Note for example that something like <% $object->expensive_method(\%args) | cache(expires_in => "10m") %> could also be done from a <%perl> block, leaving <% $cached_val %> within the non-code part of the template. It has to fit with whatever model <% %> is meant to have, not just be implemented because it can be. IMHO the model for <% %> can change, but I think currently it's mainly intended/used for outputting a variable or small expression within a larger body of non-code, like for a quick change of context (like how % at the beginning of a line lets you insert a single line instead of using a block). ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/