Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created September 23, 2016 09:28
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/766fbf722565b0d5418ace5e245aa31f to your computer and use it in GitHub Desktop.
Save gfldex/766fbf722565b0d5418ace5e245aa31f 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;
@stringy = Mu.^find_method("Stringy"), Str.^find_method("Stringy");
@handler = @stringy».wrap(sub ($self) { SQLValue.new(:str($self)) }) };
LEAVE for @stringy Z @handler -> $method, $handler { $method.unwrap($handler) };
&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