Hi all,

I have a problem in TT2 the second time, so I think it's time to ask for a
better solution instead of doing crap again and again.

I need a reasonable way to pass code which can be executed to a plugin
function. The background (today) is: I want to create a wrapper around some
List::MoreUtils functions - and most of them wants a code reference as first
argument.

In past I did:
[% PERL %]
my $x = {
  doge => sub { return sub { $_[0] ge $_[1] } },
  dole => sub { return sub { $_[0] le $_[1] } },
  docmp => sub { return sub { $_[0] cmp $_[1] } },
  ...
};
$stash->set( funcs => $x );
[% END %]

[% USE ListMoreUtils # provides VMethods %]
[% my item = mylist.bsearch( funcs.docmp, "foo", [ "bar", "baz", "foo",
"goo" ] ); %]
"foo" was [% item ? "" : "not" %] in list.

or

[% my idx = mylist.firstidx( funcs.numeq, 4, [ 1, 6, 9, 3, 4, 2, 5 ] ); %]
4 is at position [% idx %]

I would prefer do do it a bit smarter - but a function specified as argument
of a function is always called and it's return value is processed to the
plugin function.

Is there
a) a cute way to give code references to a function, or
b) a way to evaluate a MACRO from a function in a plugin?

Thanks,
Jens

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to