modperl: HTML::Template not working inside handler

G

gmail

Hello everyone,

I'm working on coding up a mod_perl handler, but am unable to get
HTML::Template to output. Below is my current code:

# file:MyHandler.pm
#------------------------------------------------------------------
package MyHandler;

#Load some helpful functions
use strict; #strict tolerance for code
use warnings; #extra warnings in the log
use Carp; #verbose logging
use diagnostics; #more verbose logging

#Loadup some functions for later use
use HTML::Template;

#Loadup functions involved in being a handler
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Request;
use Apache2::Const -compile => qw(OK);

#------------------------------------------------------------------
#
# Subroutines
#

sub handler {
my $hdlr = shift;
$hdlr->content_type('text/html');
$hdlr->print("Handler started<br />");

my $template = HTML::Template->new( filename => "/templates/
main.tmpl");
$hdlr->print("outputting template...<br />");
$template->output();

$hdlr->print("after main, now sending Apache 'OK'<br />");
return Apache2::Const::OK;
}
1;


all of the $hdlr->print statements are printed in the web browser, but
the contents of "/templates/main.tmpl" are not printed. I don't see
any errors in the Apache logs.
 
B

Ben Morrow

Quoth (e-mail address removed):
Hello everyone,

I'm working on coding up a mod_perl handler, but am unable to get
HTML::Template to output. Below is my current code:

# file:MyHandler.pm
#------------------------------------------------------------------
package MyHandler;

#Load some helpful functions
use strict; #strict tolerance for code
use warnings; #extra warnings in the log
use Carp; #verbose logging
use diagnostics; #more verbose logging

#Loadup some functions for later use
use HTML::Template;

#Loadup functions involved in being a handler
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Request;
use Apache2::Const -compile => qw(OK);

#------------------------------------------------------------------
#
# Subroutines
#

sub handler {
my $hdlr = shift;
$hdlr->content_type('text/html');
$hdlr->print("Handler started<br />");

my $template = HTML::Template->new( filename => "/templates/
main.tmpl");
$hdlr->print("outputting template...<br />");
$template->output();

HTML::Template is writing to STDOUT. You need to tell it to write to the
handler; possibly

$template->output(print_to => $hdlr);

?

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top