Skip to content

Instantly share code, notes, and snippets.

@arnsholt
Last active December 25, 2015 23:49
Show Gist options
  • Save arnsholt/7059777 to your computer and use it in GitHub Desktop.
Save arnsholt/7059777 to your computer and use it in GitHub Desktop.
Rakudo/JVM rolw mixin shenanigans
my role Foo {
has $!setup;
method postcircumfix:<( )>($args) {
#say self.?bar // 'not what we want';
if nqp::can(self, 'bar') { say self.bar }
else { say 'no what we want' }
}
}
my role Bar[Str $name] {
method bar() { $name }
}
multi trait_mod:<is>(Routine $r, :$foo!) {
say $r.^name;
$r does Foo;
say $r.^name;
}
multi trait_mod:<is>(Routine $r, :$bar!) {
say $r.^name;
$r does Bar[$bar];
say $r.^name;
}
sub test() is foo is bar('what we want') { * }
test();
say &test.^name;
# vim:ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment