After reading Audrey's blog post
mentioning GHC's upcoming quasiquoting feature (as well as that quasiquoting paper
), I quickly hacked up a (simple) quasiquoting mechanism for Perl, hence the Filter::QuasiQuote module already on CPAN:
I'm looking forward to using sensible filters in my production code (e.g. OpenResty
) and eliminating ugly Perl code for with embedded DSL. For example, instead of writing
my $sql = "alter table " . quote_identifer($table) . " drop column " . quote($column) . ";";
I can simply write
my $sql = [:sql| alter table $table drop column $column; |];
Also, a JSON-like DSL can be used to describe valid Perl data structures and to generate the Perl code doing validation.
Filter::QuasiQuote supports subclassing, so the OpenResty::QuasiQuote::SQL module mentioned above could be derived from it. Also, multiple concrete filter classes could be composed in a single Perl source file. Just put a series of use statements together:
and it should work. Because it's required that filters always return Perl source aligned in a single line, line numbers won't get corrupted.
Of course, lots of nice consequences of the Haskell quasiquotations will be lost in my implementation, such as type safety. But the Perl version is much more flexible and powerful (by some definition)
It's still in alpha and could be buggy. Feel free to report bugs or send wishlist to the CPAN RT site or directly to me