Nobody cares!

grantm on 2004-09-29T19:05:08

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 :-)


Grin :-D

Matts on 2004-09-29T20:13:23

Here's my template system that I developed for our quarantine system (used in the non-web parts):
sub 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;
    }
}
It's very trivial, but works really well and is really fast :-)