[Templates] Question about overloading Stash->get()

[prev] [thread] [next] [Date index for 2005/01/17]

From: Andrew Williams
Subject: [Templates] Question about overloading Stash->get()
Date: 21:18 on 17 Jan 2005
I want to automatically html escape unsafe chars in any value that is
displayed to the user. i.e. [% foo %] should have < and >'s escaped.

I have this working more or less with the following code:

sub get 
{
    my ($self, $ident, $args) = @_;

    my $unsafe_chars = "<>()#&\"\'";

    my ($result) = $self->SUPER::get($ident, $args);

    if(!length(ref($result)))
    {
        $result = HTML::Entities::encode($result, $unsafe_chars);
    }


    return $result;
}


I'm using the ref check to see if the underlying var is something other than a
scalar.

The problem I'm having is that macro blocks and assignemnts seem to use get as
well.  Is there any way inside the get method to test to see what context it's
getting called in?

I've spent some time googling for info on this but I can't find any
information  about getting the context inside of get().  

If this is a FAQ somewhere please beat me on the head and point me in the
right direction.  Thanks.

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] Question about overloading Stash->get()
Andrew Williams 21:18 on 17 Jan 2005

Re: [Templates] Question about overloading Stash->get()
merlyn (Randal L. Schwartz) 08:40 on 18 Jan 2005

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52