Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Roles to require private methods #4397

Closed
p6rt opened this issue Jul 13, 2015 · 4 comments
Closed

Allow Roles to require private methods #4397

p6rt opened this issue Jul 13, 2015 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Jul 13, 2015

Migrated from rt.perl.org#125606 (status was 'resolved')

Searchable as RT125606$

@p6rt
Copy link
Author

p6rt commented Jul 13, 2015

From @japhb

Since Roles compose their private methods into a Class (and thus Roles can
see each other's private methods), a Role ought to be able to require that
some other Role (or the Class) supply a particular private method, just as
they can for public methods.

See http://irclog.perlgeek.de/perl6/2015-07-11#i_10881271 :

19​:12 japhb m​: role A { method !foo { say "success!" } }; role B { method
!foo { ... }; method bar { self!foo } }; class C does A does B { };
C.new.bar();
19​:12 camelia rakudo-moar 58a5ed​: OUTPUT«===SORRY!===␤Private method 'foo'
must be resolved by class C because it exists in multiple roles (B, A)␤»
19​:12 japhb Is there any reason that one of the two above can't be made to
work?
19​:12 (Personally I think the last one should DWIM.)
19​:13 masak japhb​: I guess it comes down to how private methods from a role
compose into a class.

And then http://irclog.perlgeek.de/perl6/2015-07-13#i_10886690 :

12​:17 yoleaux 11 Jul 2015 21​:02Z <japhb> jnthn​: What are your thoughts on
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881267 and
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881334 ? Having no good
resolution kinda gets in the way of a nice refactoring (for now, I'm
copying the required private methods into each role that would want to
consume them, and then changing the names to not collide between the roles
which is ... blech.)
[...]
12​:19 jnthn .tell japhb I think the one at
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881271
should indeed DWYM; feel free to file a ticket on that

@p6rt
Copy link
Author

p6rt commented Jul 26, 2015

From @moritz

Hi,

On Mon Jul 13 08​:30​:23 2015, gjb@​google.com wrote​:

Since Roles compose their private methods into a Class (and thus Roles can
see each other's private methods), a Role ought to be able to require that
some other Role (or the Class) supply a particular private method, just as
they can for public methods.

See http://irclog.perlgeek.de/perl6/2015-07-11#i_10881271 :

19​:12 japhb m​: role A { method !foo { say "success!" } }; role B { method
!foo { ... }; method bar { self!foo } }; class C does A does B { };
C.new.bar();
19​:12 camelia rakudo-moar 58a5ed​: OUTPUT«===SORRY!===␤Private method 'foo'
must be resolved by class C because it exists in multiple roles (B, A)␤»
19​:12 japhb Is there any reason that one of the two above can't be made to
work?
19​:12 (Personally I think the last one should DWIM.)
19​:13 masak japhb​: I guess it comes down to how private methods from a role
compose into a class.

And then http://irclog.perlgeek.de/perl6/2015-07-13#i_10886690 :

12​:17 yoleaux 11 Jul 2015 21​:02Z <japhb> jnthn​: What are your thoughts on
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881267 and
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881334 ? Having no good
resolution kinda gets in the way of a nice refactoring (for now, I'm
copying the required private methods into each role that would want to
consume them, and then changing the names to not collide between the roles
which is ... blech.)
[...]
12​:19 jnthn .tell japhb I think the one at
http://irclog.perlgeek.de/p​erl6/2015-07-11#i_10881271
should indeed DWYM; feel free to file a ticket on that

Fixed with rakudo/rakudo@6c2ad869fc and test added with Raku/roast@2edb3c91da

This works now​:

role A { method !foo(A​:D​:) { say "success!" } };
role B { method !foo { ... } };
class C does B does A { method bar {self!foo } };

C.new.bar();

Putting method bar into role B does *not* work, it executes the stub code. But that is a separate bug (properly over-eager optimization), which I'll try to fix, and if I fail, I hope I'll remember to file a separate issue.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jul 26, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Jul 26, 2015
@p6rt
Copy link
Author

p6rt commented Jul 26, 2015

@moritz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant