添加到收藏    打印

CGI::Application部署范例

CGI::Application已经在系统各Perl版本安装,详情参见:Perl云主机版本说明

在相应域名的htdocs目录下,建立三个文件:index.pl, HelloWorldCgiApp.pm, helloworld.tmpl.html

helloworld.tmpl.html代码:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title><TMPL_VAR NAME=THAT_FAMOUS_STRING></title>
</head>
<body>
<b><TMPL_VAR NAME=THAT_FAMOUS_STRING></b>
</body>
</html>

HelloWorldCgiApp.pm代码:

package HelloWorldCgiApp;
use base qw(CGI::Application::FastCGI);
use HTML::Template;
use strict;

sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->run_modes(
'mode1' => 'helloworld_cgi_app',
);
$self->tmpl_path('./');
}

sub helloworld_cgi_app {
my $self = shift;
my $that_famous_string = 'Hello, world!';
my $template = $self->load_tmpl(
'helloworld.tmpl.html',
cache => 1,
);
$template->param(
THAT_FAMOUS_STRING => $that_famous_string,
);
my $html_output = $template->output;
return $html_output;
}
1;

index.pl代码:

#!/bin/env perl5.18
use strict;
use lib qw(.);
use HelloWorldCgiApp;
my $helloworld = HelloWorldCgiApp->new();
$helloworld->run();

设置index.pl权限为755



此答案有用么?

建议阅读