[Petal] local defines

Jean-Michel Hiver jhiver at mkdoc.com
Mon Apr 7 15:39:14 BST 2003


On Mon 07-Apr-2003 at 01:58:16PM +0100, Fergal Daly wrote:
> How closely is Petal supposed to match TAL? It seems there is no way to have a 
> local define. This doc
> 
> <doc>
>   <outer petal:define="var string:a">
>     <inner petal:define="var string:b">
>       <tag petal:content="var" />
>     </inner>
>     <tag petal:content="var" />
>   </outer>
> </doc>
> 
> gives output of
> 
> <doc>
>         <tag>
>                 <tag>
>                         <tag>b</tag>
>                 </tag>
>                 <tag>b</tag>
>         </tag>
> </doc>

The variables are scoped, but only inside loops / repeat statements.
TAL doesn't seem to say much about scoping, so I think this behavior is
more related to ZPT than TAL.

What do other people on the list think?
Is this behavior critical for what you want to do with Petal?


For now, if you MUST have scoping *everywhere*, you could do the
following:

1/ Go and take a look at Petal::CodeGenerator

2/ To see how the scoping is done, look at the _for() class method

3/ Subclass Petal::CodeGenerator and redefine the method for which you
want to add scoping, for instance _include(), _var(), _if(), _eval(),
etc.

Then you can simply change Petal's code generator backend by setting the
$Petal::CodeGenerator variable to the name of the class that you want to
use, i.e.

use My::Generator;
$Petal::CodeGenerator = 'My::Generator';

Indeed you can change the default value in the code and then run the
test suite to see if everything works as it's supposed to.


Happy Petal Hacking!
-- 
Building a better web - http://www.mkdoc.com/
---------------------------------------------
Jean-Michel Hiver
jhiver at mkdoc.com  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


More information about the Petal mailing list