bliako has asked for the wisdom of the Perl Monks concerning the following question:

I have hit a wall with the template system Text::Xslate. I can't find how to modify an array element or append to a hash or array. It keeps telling me it is forbidden.

I can do this: : my $arr=[1,2,3]; but I can not do this : $arr[1] = 12; Neither this: my $y = {a=>1,b=>2}; $y['c'] = 3; All is forbidden!

Do I miss something or is this kind of thing discouraged and I have to rethink it? But I need to transform even a little bit the data sent to the template.

Replies are listed 'Best First'.
Re: Text::Xslate : append to hash or array?
by choroba (Cardinal) on May 12, 2020 at 13:04 UTC
    This issue might be related.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Does not look promising. Reality check: is asking the template system to transform a bit (just a bit) the data, like adding another key-value pair to an input hash something that is discouraged? and my design is bad?

        Those questions are independent. In a pure View all action upon data is discouraged. Whether or not that is good or bad depends on one’s philosophy. I primarily use Text::Xslate now and, as you’ve found, it is quite irritating and unperly sometimes to have to be so careful about what to send it; it plays badly with some default DBIx::Class behavior for example. It is the a proverbial slippery slope between Text::Xslate which says, No! and Template::Toolkit which says, Yes, a million times, yes! No one really wants to hear …Maybe…

Re: Text::Xslate : append to hash or array?
by pryrt (Abbot) on May 12, 2020 at 14:26 UTC
    EDIT: my answer was irrelevant, as Text::Xslate does introduce new syntax. Sorry. Original post now mostly hidden by spoiler (leaving last line visible for easy context for the reply)


    Or does Text::Xslate bring in some new syntax (or were those inside of text that Text::Xslate uses in a non-perlish way?) -- If that's the case, then feel free to ignore me.