develooper Front page | perl.perl6.language | Postings from February 2019

Submethods in roles

From:
Vadim Belman
Date:
February 6, 2019 23:31
Subject:
Submethods in roles
Message ID:
3DB08C4A-455F-4E21-BDC8-07228B0736AC@lflat.org
Hello,

I'm working on a fix for https://github.com/rakudo/rakudo/issues/2250. While the problem itself is easily tracks down to add_method not reporting a error, the general fix requires clear understanding of what happens to submethods when a role consumes another role. While things are pretty straightforward for methods, which are copied over from the source role to the target, for submethods not everything is so clear as I see it. Let's consider the following setup:

role R1 { submethod foo { "R1::foo" } }
role R2 does R1 { }
class Foo does R2 { submethod foo { "Foo::foo" } }

Imagine a code which would like to execute all submethods of all classes and roles. Normally, it would traverse mro and all role concretizations of each class from mro. In the example above such code would call submethod foo() from R1 twice: for R2 and R1 itself! Of course, there is a workaround for this as foo from R1 will have its .package set to R1. But what sense does such copying makes? When a role gets applied to class it does make some sense when we talk about BUILD/TWEAK/DESTROY. Though if https://github.com/rakudo/rakudo/issues/2241 gets implemented then even this use case will be obsoleted.

So, to have a comprehensive fix for #2250 I need to know how to handle submethods when a role is applied to a role: either I leave them untouched where they're (and this would be my choice); or I get them copied alongside with methods.

Best regards,
Vadim Belman



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About