Ok, so I created a new templating module and mentioned an intention to upload it to CPAN and nobody flamed me. What does a guy have to do to get some attention round here :-)
It's very trivial, but works really well and is really fastsub do_template {
my $filename = shift;
my %data = @_;
my $subst = sub {
my $param = shift;
if (exists($data{$param})) {
my $ret = $data{$param};
return defined($ret) ? $ret : "";
}
else {
carp("no template value for $param");
return "";
}
};
$filename = "$TEMPLATE_ROOT/$filename";
open(my $fh, $filename) || die "email_template: open($filename) failed: $!";
local $/;
my $text = <$fh>;
close($fh);
$text =~ s/\$(\w+)\$/$subst->($1)/ge;
if (wantarray) {
return split(/\r?\n\r?\n/, $text, 2);
}
else {
return $text;
}
}