[Templates] Re: How to know if an object method was called from a template

Randal L. Schwartz merlyn@stonehenge.com
Sun, 11 Feb 2007 14:47:50 -0800


>>>>> "Robin" =3D=3D Robin Smidsr=F8d <robin@smidsrod.no> writes:

Robin> But my next question is then, how can I go about to set this variable
Robin> automatically when $tt->process() is called? This way I don't have to
Robin> change the many occurences of $tt->process() in my code. Are there s=
ome
Robin> variable in the tt init code which could be set to a callback which =
is
Robin> automatically run whenever I execute $tt->process?

BEGIN {
  package My::Template;
  use base qw(Template);

  sub process {
    my ($self) =3D @_;  # don't shift, because we goto...

    local $RUNNING =3D 1; # check $My::Template::RUNNING now
    my $super =3D $self->can("SUPER::process") or die "$self can't process";
    goto &$super;

  }
}

my $tt =3D My::Template->new(...);
$tt->process(...);

--=20
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl trainin=
g!