Skip to content

Instantly share code, notes, and snippets.

@moritz
Created October 5, 2011 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/1264326 to your computer and use it in GitHub Desktop.
Save moritz/1264326 to your computer and use it in GitHub Desktop.
mini template -- neither small nor inspiring
my $template = q[
<title>%title</title>
<p>%body</p>
];
sub tmpl($template, &filter = -> $x { $x }, *%args) {
$template.subst(:g, /'%'(\w+)/,
-> $/ {
%args.exists($0)
?? filter(%args{$0})
!! die("No value provided for '$1'")
}
);
}
say tmpl($template, &uc, title => 'HAI', body => 'foo.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment