#!/usr/bin/perl use strict; use warnings; use diagnostics; use template; my $app = sub { my $html = get_html(); return [ 200, ['Content-Type' => 'text/html'], [$html], ]; }; sub get_html{ # open template file open(my $reader,'< :encoding(UTF-8)',"/library/webserver/documents/html.html"); my $input; do{$input .= $_} while(<$reader>); # Initialize HTML template my $template = Template->new(); my $vars = {greeting => 'Howdy, Cowboy!',debt => '$1.50',sender => 'John Wayne'}; my $html; $template->process(\$input,$vars,\$html) || die "Template process failed: ", $template->error(), "\n"; return $html; }