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

Unable to use Multi Methods in Roles #36

Open
tobyink opened this issue Jan 9, 2021 · 3 comments
Open

Unable to use Multi Methods in Roles #36

tobyink opened this issue Jan 9, 2021 · 3 comments

Comments

@tobyink
Copy link
Owner

tobyink commented Jan 9, 2021

Migrated from rt.cpan.org #123849 (status was 'open')

Requestors:

From [email protected] on 2017-12-09 20:07:52
:

Hi there-

It appears that multi subs/methods don't work properly when being composed in roles (Moo::Role).

I did a little digging, and it seems that rather than methods being registered under the package name of a role's consumer, they are registered under the package name of the role itself. So when it comes time to look up a method in the dispatch table, we're looking in the wrong package name, and get this error:

"did not match any known signature for multi sub"

I'm not especially familiar with how Moo::Role works behind the scenes, and so maybe this is unfixable, or undesired. But it seems that if it were fixable, maybe Kavorka::Multi::__gather_candidates would be the place to do it...?

Do you have any thoughts on this?

(Big fan of Kavorka - thank you!)

Ryan Lang

@tobyink
Copy link
Owner Author

tobyink commented Jan 9, 2021

From [email protected] on 2017-12-09 20:14:33
:

Example in code:

package My::Role;

use Moo::Role;
use Types::Standard qw/ArrayRef HashRef/;
use Kavorka qw/multi method/;

multi method process (ArrayRef $x) { say "here" }
multi method process (HashRef $x) { say "there" }

package My::Consumer;

use Moo;
with 'My::Role';

PACKAGE->process( [] ); # blows up here: Arguments to My::Role::process did not match any known signature for multi sub
PACKAGE->process( {} );

On Sat Dec 09 15:07:52 2017, RLANG wrote:

Hi there-

It appears that multi subs/methods don't work properly when being
composed in roles (Moo::Role).

I did a little digging, and it seems that rather than methods being
registered under the package name of a role's consumer, they are
registered under the package name of the role itself. So when it
comes time to look up a method in the dispatch table, we're looking in
the wrong package name, and get this error:

"did not match any known signature for multi sub"

I'm not especially familiar with how Moo::Role works behind the
scenes, and so maybe this is unfixable, or undesired. But it seems
that if it were fixable, maybe Kavorka::Multi::__gather_candidates
would be the place to do it...?

Do you have any thoughts on this?

(Big fan of Kavorka - thank you!)

Ryan Lang

1 similar comment
@tobyink
Copy link
Owner Author

tobyink commented Jan 9, 2021

From [email protected] on 2017-12-09 20:14:33
:

Example in code:

package My::Role;

use Moo::Role;
use Types::Standard qw/ArrayRef HashRef/;
use Kavorka qw/multi method/;

multi method process (ArrayRef $x) { say "here" }
multi method process (HashRef $x) { say "there" }

package My::Consumer;

use Moo;
with 'My::Role';

PACKAGE->process( [] ); # blows up here: Arguments to My::Role::process did not match any known signature for multi sub
PACKAGE->process( {} );

On Sat Dec 09 15:07:52 2017, RLANG wrote:

Hi there-

It appears that multi subs/methods don't work properly when being
composed in roles (Moo::Role).

I did a little digging, and it seems that rather than methods being
registered under the package name of a role's consumer, they are
registered under the package name of the role itself. So when it
comes time to look up a method in the dispatch table, we're looking in
the wrong package name, and get this error:

"did not match any known signature for multi sub"

I'm not especially familiar with how Moo::Role works behind the
scenes, and so maybe this is unfixable, or undesired. But it seems
that if it were fixable, maybe Kavorka::Multi::__gather_candidates
would be the place to do it...?

Do you have any thoughts on this?

(Big fan of Kavorka - thank you!)

Ryan Lang

@tobyink
Copy link
Owner Author

tobyink commented Jan 9, 2021

From [email protected] on 2018-06-26 10:01:15
:

To be honest, I've never really given the concept much thought, but multi methods in roles could be cool.

Different roles might even define different signatures for the same method and the class could compose both.

I do think this should be supported.

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