in reply to Re^2: Undef value in Template Toolkit
in thread Undef value in Template Toolkit

This sounds like an XY problem(?). I would argue that manipulating data within templates is generally a mistake. Caring about what form unviewable data is within a view also seems like a mismatch to the context.

Replies are listed 'Best First'.
Re^4: Undef value in Template Toolkit
by DreamT (Pilgrim) on Aug 21, 2019 at 06:52 UTC
    I get your point. Indeed at XY problem, given that there probably are better solutions for this
    The goal here was to create a "mapper" from one data source (a data structure from another system) to another (a data structure that "fits" in my system). Something like this:
    [% destination.header.address.surname = source.orderData.custI +nfo.surname %] [% destination.header.timestamps.created = methods.tounixtime(sour +ce.orderData.orderDate) %]

    This results in a hash structure that is converted to the format my system expects. I.e. So yes, I'm using Template Toolkit to manipulate/process data.

    I would agree that TT isn't a good solution for this from a developers point of view. But the end result is _exactly_ what I'm looking for, a simple "configuration file" where the intended user (a system admin that sometimes dynamically needs to change/add fields) can do what he/she needs. If I could find a better solution for it, I would use it ;-)

      Maybe Data::Diver might help? With that extra context it's only slightly disturbing; the TT syntax makes for a clean-ish approach for doing that.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Re^4: Undef value in Template Toolkit
by Anonymous Monk on Aug 20, 2019 at 19:36 UTC
    I am generally uncomfortable with "program logic in a template," because that's not where I expect to find it.
      In general, I agree. But for this case (a simple field mapper, see my other reply in this thread) it felt like a good idea. (Maybe there are better alternatives than TT though...)

      You are generally uncomfortable with logic. And programming.