I have elected to use the OUTPUT configuration directive at time
that
I create my template object:
# our $varinquestion;
sub init {
my $config = {
OUTPUT => \%myoutput_handler,
};
return Template->new($config);
};
In my PerlHandler I know / set $varinquestion. I'd like
my output handler to have access to it.
sub handler {
# $varinquestion = something();
$vars={
varinquestion = $varinquestion,
};
$tt->process($vars);
sub myoutput_handler {
my ($output, $tt, $vars) = @_;
# if ($varinquestion) {
if ($vars->{'varinquestion'}) {
then
};
Commenting out the package variable and going with passed through
$vars block - when I do prefer.
Randal L. Schwartz wrote
>
> >>>>> "Jay" == Jay Lawrence <[EMAIL PROTECTED]> writes:
>
> Jay> I really like the OUTPUT => sub { } config option for
templates. The *only*
> Jay> thing is I'd like to pass a variable into the calling
routine to avoid
> Jay> using a package global.
>
> I don't understand why you think the only two choices are "the
way it is"
> and "package globals". What's wrong with using a lexical in
the closure?
>
> my %vars = (fred => 1, barney => 3);
> my $tt = Template->new( ... );
> ...
> $tt->process($template, \%vars,
> sub { my $o = shift; ... $tt ...; ... $vars{fred} ... ; }
> );
>
> Look ma, no package vars. Just lexicals.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1
503 777 0095
> <[EMAIL PROTECTED]> <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 training!