Yes, it's some pretty wacky magic, if I recall correctly. It was years since I wrote it, though, so I don't necessarily remember exactly how it works myself. I think I gave up on making it readable so I made it unreadable instead. Sorry about that.
It converts the template to Perl code, and turns off strictness so it can use name references to actually change global variables in as it enters and leaves scopes. The main trick is this:
$foo="bar";
$$foo=12;
print "$bar\n";
This will print "12". By setting variables this way, the <var>
code can just evaluate whatever argument it is given as Perl code.