Skip to content

Instantly share code, notes, and snippets.

@gfldex
Last active January 13, 2016 12:30
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/d69c79e516b0cf4d1d88 to your computer and use it in GitHub Desktop.
Save gfldex/d69c79e516b0cf4d1d88 to your computer and use it in GitHub Desktop.
use v6;
class Replacement {
}
use Lib Str;
my $g = Guard.new("");
dd $g ~ "abc";
dd "abc" ~ $g;
use v6;
role ConcatGuard[::T-right] {
has T-right $.attr is rw;
method left-type () is nodal { self.WHAT }
method right-type () is nodal { T-right }
method convert () {...} # --> T-right
method new (T-right) {...}
}
sub EXPORT(::T = Str) {
my $t = T;
class Example is Mu does ConcatGuard[$t] {
method convert(){
$.attr.subst('&lt;','<').subst('&amp;', '&');
}
method new($s) {
self.bless(attr=>$s.subst('&', '&amp;').subst('<', '&lt'));
}
}
multi sub infix:<~>(Example \l, T \r){ note "op1"; };
multi sub infix:<~>(T \l, Example \r){ note "op2"; };
{
Guard => Example,
'&infix:<~>' => &infix:<~>,
# '&infix:<~>' => sub (T \l, Example \r){ l ~ r },
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment