I need to have a role with a little bit of special functionality implemented through a Metamodel
class of mine inheriting from Metamodel::ParametricRoleHOW
. One way to apply it is by using a trait. But I want a nice syntax sugar like we can do with classes:
special Mine {
...
}
Ok, I add the following into my module:
my package EXPORTHOW {
package DECLARE {
constant special = My::Metamodel::SpecialRoleHOW;
}
}
and everything runs smoothly... No, it is not:
class Foo does Mine {
...
}
and I end up with:
Could not instantiate role 'Mine':
A very brief inspection of Actions.nqp
revealed that roles have special handling, but only and only when role
keyword is used for package declaration. Hence, I conclude that the only way to have the syntax sugar – is to mixin my own rule into the main grammar and simulate the role declaration. Luckily, package_def
relies upon $*PKGDECL
and it makes such simulation possible.
Am I right in the conclusion? Or a simpler way exists to achieve the goal?
role
– it won't act properly. On IRC Jonathan confirmed this and said that he would change this behavior when have a chance. I'm working on a slang workaround for this meanwhile. – Vadim Belman