On Fri, Oct 07, 2005 at 11:12:43PM -0400, Vivek Khera wrote:
>
> On Oct 7, 2005, at 4:47 PM, Bill Moseley wrote:
>
> >Any way to get to the stash from a virtual method? That is:
> >
> > [% some_var.some_vmethod %]
> >
> >Then in some_vmethod() I'd like to have access to the stash.
>
> when you create the some_var object, it is passed the $context. Save
> that reference in your object, then your some_vmethod() can get to it
> via $self, and from $context get to the stash.
In this case some_var is just a scalar.
[%
SET some_var = "foo";
SET other ="bar";
some_var.vmethod; # "prints "foo bar"
%]
Having "some_var" be an object is the way to go, of course. But, I
already have a scalar and wanted to do something to it based on
another value in the stash.
Something wishful like:
$Template::Stash::SCALAR_OPS->{vmethod} = sub {
my ( $value, $context ) = @_
my $bar = $context->stash->get('bar')
return "$value $bar";
};
That's a bit ugly, though.
--
Bill Moseley
[EMAIL PROTECTED]
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates