I actually just pass a wrapped ref() in an anonymous sub in the parameter hash passed to the template.

Mark Mills wrote:

Thomas, Mark - BLS CTR wrote:

I wrote:

Is there any way to work around the lack of a ref() vmethod in TT2?


I worked around it this way:

[% IF var.keys %]
    [%# hash %]
[% ELSIF var.0 %]
    [%# array %]
[% ELSE %]
    [% var %]
[% END %]

Hopefully there aren't any weird boundary cases that would throw this off.

- Mark.



Following my usual pattern of favorite features, you could simply add vmethods that report the ref values you want:


$Template::Stash::LIST_OPS->{ref} = sub {
       return "ARRAY";
};

$Template::Stash::HASH_OPS->{ref} = sub {
       return "HASH";
};

$Template::Stash::SCALAR_OPS->{ref} = sub {
       return "";
};


and then [% blah.ref() %] would do basically what you'd expect. That is one cheap hack but it is at least a bit cleaner than a staged IF.


--mark mills
Xodiax Engineering

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates



_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to