# HelloWordCgiApp.pm package HelloWorldCgiApp; use lib qw(/home/redantig/perl); use base 'CGI::Application'; use HTML::Template; use strict; # Run at startup sub setup { my $self = shift; $self->start_mode('mode1'); $self->run_modes( 'mode1' => 'helloworld_cgi_app', ); # Use current path as template path, # i.e. the template is in the same directory as this script $self->tmpl_path('./'); } # HTML::Template-style "Hello, World!" sub helloworld_cgi_app { # The application object my $self = shift; # The message my $that_famous_string = 'Hello, world!'; # Open the html template # NOTE 1: load_tmpl() is a CGI::Application method, not a HTML::Template method. # NOTE 2: Setting the 'cache' flag caches the template if used with mod_perl. my $template = $self->load_tmpl( 'helloworld.tmpl.html', cache => 1, ); # Fill in some parameters $template->param( THAT_FAMOUS_STRING => $that_famous_string, ); # Parse the template my $html_output = $template->output; return $html_output; } 1; # so the 'require' or 'use' succeeds