I play with routines. This all works, but now I get a random return value: 1 at the bottom of the page when I call sub admin_view.
Home.pl
no warnings 'experimental::smartmatch';
use Cwd qw(abs_path);
use feature qw(switch);
use CGI::Simple;
use HTML::Template;
my $cgi = CGI::Simple->new;
my $action = $cgi->url_param('cmd') || '';
my $mode = $ARGV[0];
print $cgi->header;
if($action eq "") {
$mode = "home";
}
if($action eq "admin_view") {
$mode = admin_view;
}
given($mode){
when(admin_view) {
use rawr::template qw(admin_view);
print &admin_view;
}
when(home) {
print "Some home page";
}
default { print "mode not implemented" }
}
Template.pm
package rawr::template;
use strict;
use warnings;
use Exporter qw(import);
use HTML::Template;
our @EXPORT_OK = qw(admin_view);
sub admin_view {
my $template = HTML::Template->new(filename => '/srv/mydomain/www/rawr/tmpl/admin_view.tmpl');
$template->param(ALIAS => "Some User");
$template->param(CONTENT => "Hardcoded Content");
$template->param(DATE => "Date - change me");
$template->param(TITLE => "Hardcoded - change me");
print "Content-Type: text/html\n\n", $template->output;
}
1;
admin_view.tmpl
<table border="1" id="container">
<tr>
<td id="main_content">
<ul>
<li onclick="showmenu(this)">!<b>PROFILE</b>
<ul>
<li><a href="#">Modify</a></li>
<li> Delete</li>
<li> Lock</li>
<br>
</ul>
</li>
<br>
<TMPL_VAR NAME=ALIAS>
<br>
<br>
<TMPL_VAR NAME=DSP>
<br>
</td>
<td id="main_content" class="opacity_box" >
<b><TMPL_VAR NAME=TITLE></b> <TMPL_VAR NAME=DATE>
<br>
<br>
<TMPL_VAR NAME=CONTENT>
<br>
</td>
</tr>
</table>
The template is displayed exactly, but at the bottom of the page I get arbitrary output 1 after the last tag</table>
</table>1
Any solution to the problem? greetings
David source
share