Created
September 23, 2016 09:28
-
-
Save gfldex/766fbf722565b0d5418ace5e245aa31f 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; | |
@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