On Mon, Jul 28, 2008 at 4:07 AM, Marc Chantreux <[EMAIL PROTECTED]
> wrote:

> hello,
>
> I tried to register a vmethod to an object using this way:
>
> use strict;
> use warnings;
> use Template;
> use Template::Stash;
>
> $Template::Stash::SCALAR_OPS->{field} = sub {
>    my $self = shift;
>    $self->field(@_);
> }
>
> but it doesn't work: $self can't be a reference to be handled by
> SCALAR_OPS.
>

Sure it can:


sub Foo::field { $_[1] }

$Template::Stash::SCALAR_OPS->{field} = sub { shift->field(@_) };

Template->new->process(\"[% x.field(42) %]", { x => bless({ }, 'Foo') });


This prints "42" for me.


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

Reply via email to