Subject: | CAP::AnyTemplate uses huge amounts of memory with HTML::Template::Expr |
Hello
CGI::Application::Plugin::Anytemplate with HTML::Template::Expr uses a
heck of a lot of memory - growing to 100s MB when outputting templates
in loop. My environment:
Parse::RecDescent 1.94
HTML::Template 2.8
HTML::Template::Expr 0.06
CGI::Application::Plugin::AnyTemplate 0.17
Test case:
TestExpr.pm
===========
package TestExpr;
use base 'CGI::Application';
use CGI::Application::Plugin::AnyTemplate;
use Data::Dumper;
use strict;
sub cgiapp_init {
my $self = shift;
$self->template->config(
default_type => 'HTMLTemplateExpr',
);
}
sub setup {
my $self = shift;
$self->start_mode('test_case');
$self->run_modes(['test_case']);
}
sub test_publish {
my $self = shift;
my $template = $self->template->load(file => 'test');
$template->param('title', 'This is my title');
$template->param('summary', 'Just some summary text');
# not required, but this illustrates what I'm doing ... publishing
# to the filsystem
open (my $fh, '>', '/tmp/output.html');
print $fh ${$template->output};
close $fh;
1;
}
sub test_case {
my $self = shift;
foreach my $j (0..50000) {
$self->test_publish();
}
return 'ok';
}
1;
instance.pl - run from the command line
===========
#!/usr/local/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Application::Dispatch;
CGI::Application::Dispatch->dispatch(
CGIAPP_DISPATCH_DEFAULT => 'test_case',
CGIAPP_DISPATCH_RM => 1,
TABLE => {
test_case => 'TestExpr',
}
);
test.html
=========
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>HTML::Template::Expr Test</title>
</head>
<body>
Title: <tmpl_var title>
Summary: <tmpl_var summary>
</body>
</html>
regards
Dan