xslate / p5-Text-Xslate

Scalable template engine for Perl5
https://metacpan.org/release/Text-Xslate
Other
121 stars 47 forks source link

Why is assignment within templates discouraged? #201

Open cxw42 opened 4 years ago

cxw42 commented 4 years ago

Assignment within templates is forbidden in Kolon and discouraged by the docs for TTerse. Why is that? The only explanation I have found is a comment that it was for the sake of simplicity.

Context: I am looking for a sandboxed DSL in which people can implement business logic. The target users of the DSL are not Perl programmers, so Safe is not an option, and neither are many of the other template engines (e.g., Text::MicroTemplate, referenced in the linked comment). TTerse looks like it might do the job very nicely! However, I would like to understand whether assignment is at risk of disappearing in a future release before committing to TTerse.

Thank you in advance for your insights!

hadjiprocopis commented 4 years ago

I have similar issue here with Text::Xslate (via Perl and Mojolicious).

I can do this:

my $arr=[1,2,3];

but I can not do this :

$arr[1] = 12;

I can do this:

my $y = {a=>1,b=>2};

But I can not do this:

$y['c'] = 3;

or even this:

$y['a'] = 3;

All is forbidden!

After hearing so much about Text::Xslate I thought I give it a try. And after converting all my templates to this system, BAM! it hits me Forbidden, Forbidden, Forbidden.

Can anyone shed any light on this? I am in the middle of a project and just found out my car has triangular wheels.