[Templates] register vmethods?
Sean McAfee
eefacm at gmail.com
Tue Jul 29 05:17:47 BST 2008
On Mon, Jul 28, 2008 at 3:13 PM, Marc Chantreux <marc.chantreux at biblibre.com
> wrote:
> hello Sean,
>
> I'm afraid it does the same ...
>
I'm not sure what you mean. Here's a less abbreviated example:
use Template;
use Template::Stash;
use strict;
package Object;
sub new {
my ($class, $addend) = @_;
bless { addend => $addend }, $class;
}
sub field {
my ($self, $arg) = @_;
return $arg + $self->{addend};
}
package main;
$Template::Stash::HASH_OPS->{dofield} = sub {
my ($fielder, $num) = @_;
return $fielder->field($num + 2);
};
my $obj = Object->new(1);
my $t = Template->new;
$t->process(\'[% obj.dofield(3) %]', { obj => $obj })
or die $t->error;
This prints "6", showing that the hash vmethod "dofield" has dispatched to
the "field" method of $obj.
--Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080728/3f0f9e87/attachment.htm
More information about the templates
mailing list