modperl: HTML::Template not working inside handler

Discussion in 'Perl Misc' started by gmail@indigorobot.com, Feb 25, 2008.

  1. Guest

    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.
    , Feb 25, 2008
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    > 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
    Ben Morrow, Feb 25, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    757
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    1
    Views:
    684
    Damien
    Feb 22, 2007
  3. Brian Wakem

    Prototype mismatch under ModPerl::PerlRun

    Brian Wakem, Sep 6, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    386
    Brian Wakem
    Sep 6, 2005
  4. it_says_BALLS_on_your forehead
    Replies:
    0
    Views:
    345
    it_says_BALLS_on_your forehead
    Jan 24, 2006
  5. Gabriel
    Replies:
    1
    Views:
    168
    Brian McCauley
    Sep 28, 2006
Loading...

Share This Page