Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created March 19, 2009 03:24
Show Gist options
  • Save taiyoh/81568 to your computer and use it in GitHub Desktop.
Save taiyoh/81568 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Text::MicroTemplate qw/:all/;
use YAML qw/Dump/;
my $text = << '...';
<?= $hoge ?>
<?= $fuga ?>
...
my $mt = Text::MicroTemplate->new(
template => $text,
);
my $code = $mt->code;
my $args = { hoge => 'hoge', fuga => 'fuga' };
my @arg_keys = keys %$args;
my $arg_text = join '', map { "my \$$_ = shift;" } @arg_keys;
my $renderer = eval "sub { $arg_text $code->(); }" or die $@;
my $html = $renderer->(map { $args->{$_} } @arg_keys);
print $html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment