[cgiapp] Settng Template path

Stephen Carville stephen.carville at gmail.com
Wed Jan 16 14:06:05 EST 2008


I'm trying out CGI++Application plus HTML::Template as a
replacement/upgrade for a current report generation system but I'm
havinmg a problem with settng the template path:

I create a module called DailyFloodSummary.pm:

 #!/usr/bin/perl
 package DailyFloodSummary;
 use base 'CGI::Application';
 use strict;
 use warnings;
 use HTML::Template;

 # Constants
 my $TMPL_DIR = "/var/www/perl/html_templates";

 #######################################
 # Setup
 #
 sub setup {
   my $self = shift;

   $self->tmpl_path($TMPL_DIR);
   $self->run_modes(
      '0' => 'show_search_form',
      '1' => 'show_results_list'
   );

   $self->start_mode('0');

   $self->mode_param('level');
 }

 #######################################
 # show the search form
 #
 sub show_search_form {
   my $self = shift;
   my ($cgi,$date,$time);
   my ($header,$body,$trailer,$output);

   # open the header template
   $header = $self->load_tmpl("header.tmpl");

   # current date and time from library routines
   ($date,$time) = web_get_today();

   $header->param(todaysdate => "$date $time");

   $output = $header->output;

   return $output;
 }

I call it from dfs.cgi

#!/usr/bin/perl

use strict;
use warnings;

use lib ".";
use DailyFloodSummary;

my $app = DailyFloodSummary->new();

$app->run();

I get the following error list:

Error executing run mode '0': HTML::Template->new() : Cannot open
included file header.tmpl : file not found. at
/usr/lib/perl5/site_perl/5.8.8/HTML/Template.pm line 1658
        HTML::Template::_init_template('HTML::Template=HASH(0x1f738f80)')
called at /usr/lib/perl5/site_perl/5.8.8/HTML/Template.pm line 1238
        HTML::Template::_init('HTML::Template=HASH(0x1f738f80)')
called at /usr/lib/perl5/site_perl/5.8.8/HTML/Template.pm line 1124
        HTML::Template::new('HTML::Template', 'filename',
'header.tmpl', 'path', 'ARRAY(0x1f83f1a0)') called at
/usr/lib/perl5/site_perl/5.8.8/HTML/Template.pm line 1182
        HTML::Template::new_file('HTML::Template', 'header.tmpl',
'path', 'ARRAY(0x1f83f1a0)') called at
/usr/lib/perl5/site_perl/5.8.8/CGI/Application.pm line 1464
        CGI::Application::load_tmpl('DailyFloodSummary=HASH(0x1f5e12e0)',
'header.tmpl') called at DailyFloodSummary.pm line 40
        DailyFloodSummary::show_search_form('DailyFloodSummary=HASH(0x1f5e12e0)')
called at /usr/lib/perl5/site_perl/5.8.8/CGI/Application.pm line 152
        eval {...} called at
/usr/lib/perl5/site_perl/5.8.8/CGI/Application.pm line 151
        CGI::Application::run('DailyFloodSummary=HASH(0x1f5e12e0)')
called at ./dfs.cgi line 11
 at ./dfs.cgi line 11

Any idea what I am doing wrong?

-- 
Stephen Carville


More information about the cgiapp mailing list