Click here to get back home

modperl: HTML::Template not working inside handler

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
modperl: HTML::Template not working inside handler gmail 02-25-2008
Posted by gmail on February 25, 2008, 2:33 pm
Please log in for more thread options
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.

Posted by Ben Morrow on February 25, 2008, 6:01 pm
Please log in for more thread options

Quoth gmail@indigorobot.com:
> 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


Similar ThreadsPosted
mod_perl 2.0 and apache 2.2 Undefined subroutine &ModPerl::ROOT::ModPerl::Registry error January 24, 2006, 3:43 pm
HTML::Template October 24, 2007, 12:50 am
Dreamweaver (or some such) and HTML::Template? March 7, 2005, 9:38 am
Converting my index.pl(cgi) to html::template one April 26, 2005, 7:03 pm
HTML::template Module in perl April 6, 2007, 7:26 am
HTML::Template module in perl April 9, 2007, 4:29 am
perl html template error March 11, 2008, 10:24 am
Framework help: Can HTML::Template do this? If not, what CPAN module can? September 8, 2005, 1:02 pm
LWP::Simple getstore not working inside of hash :( January 3, 2005, 10:13 pm
Replace text inside html tags? January 30, 2005, 2:01 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap