Created
September 23, 2016 09:40
-
-
Save gfldex/6be94a8e6f86c16ea5fdfd6b1b4e6ba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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