Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created September 23, 2016 09:40
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 gfldex/6be94a8e6f86c16ea5fdfd6b1b4e6ba3 to your computer and use it in GitHub Desktop.
Save gfldex/6be94a8e6f86c16ea5fdfd6b1b4e6ba3 to your computer and use it in GitHub Desktop.
use v6;
# by nine
class SQLValue {
has $.str;
method Str() { "quoted(" ~ $.str.Str ~ ")" }
};
multi sub infix:<~>(Str:D $str, SQLValue:D $val) { $str ~ $val.Str }
sub prefix:<sql>(&block) {
my @stringy;
my @handler;
my $h1 = Mu.^find_method("Stringy").wrap(sub ($self) { SQLValue.new(:str($self)) });
my $h2 = Str.^find_method("Stringy").wrap(sub ($self) { SQLValue.new(:str($self)) });
LEAVE { $h1.restore; $h2.restore; };
&block()
}
my $foo = 42;
my $bar = "bar";
say sql{ "foo=$foo or $bar" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment