use vars qw/$template/;
$template = undef;
#calls foo
foo()
#outputs page
print $template->output;
sub foo {
$template = HTML::Template->new(filename => 'test.tmpl');
# fill in some parameters in the template
$template->param(home => $ENV{HOME});
$template->param(path => $ENV{PATH});
}
####
our $template;
$template = undef;
#calls foo
foo()
#outputs page
print $template->output;
sub foo {
$template = HTML::Template->new(filename => 'test.tmpl');
# fill in some parameters in the template
$template->param(home => $ENV{HOME});
$template->param(path => $ENV{PATH});
}
####
package Page;
use HTML::Template;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
$self->setTemplate('default.tmpl');
return $self;
}
sub setTemplate {
my $self = shift;
my $file = shift;
# You really should validate the template filename here.
$self{template} = HTML::Template->new(filename => $file);
}
sub template {
my $self = shift;
return $self->{template};
}
sub output {
my $self = shift;
return $selft->template->output;
}
1;
####
use Page;
my $p = Page->new;
$p->setTemplate('test.tmpl');
$p->template->param(home => $ENV{HOME});
$p->template->param(path => $ENV{path});
$p->output;