Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:00:11+00:00 2026-05-31T18:00:11+00:00

I need multemethod dispatch with Moose objects. I’m doing this with Class::Multimethods::Pure . I

  • 0

I need multemethod dispatch with Moose objects. I’m doing this with Class::Multimethods::Pure. I chose this instead of MooseX::MultiMethods because it depends on MooseX::Method::Signatures which can’t install on my system because it fails its tests. I don’t mind if you have an alternative approach to suggest.

The following works fine with types and subtypes:

package Foo::Type;
use Moose;

package Foo::SubType;
use Moose;
extends 'Foo::Type';

package main;
use Class::Multimethods::Pure;

multi hello => ('Foo::Type') => sub {
    my ( $foo ) = @_;
    print $foo;
};

hello( Foo::SubType->new );

But the scenario I now need to handle is where the declared type is actually a Moose Role:

package Foo::Role;
use Moose::Role;

package Foo::Type;
use Moose;
with 'Foo::Role';

package main;
use Class::Multimethods::Pure;

multi hello => ('Foo') => sub {
    my ( $foo ) = @_;
    print $foo;
};

hello( Foo::Type->new );

But this can’t recognise the role:

No method found for args (Foo::Type=HASH(0x22ac854))

The documentation says it can be extended in various ways, including adding Perl 6-ish roles. But it’s a little sketchy for me and I’m looking for a more detailed example. Has anyone tried this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:00:12+00:00Added an answer on May 31, 2026 at 6:00 pm

    My solution was to convert the roles to abstract base classes using MooseX::ABC. In this way, they could be recognised as a class type.

    On a side note, I managed to get MooseX::MultiMethods working on another system. It does work with roles, but it can’t figure out which to use if we define a multimethod that takes the class and another multimethod that takes the role. Incidentally, MooseX::ABC resolved this issue also since it gave me a hierarchical structure which the roles did not really have.

    package Foo::Role;
    use Moose::Role;
    
    package Foo::Type;
    use Moose;
    with 'Foo::Role';
    
    package Merger;
    use Moose;
    use MooseX::MultiMethods;
    
    multi method hello (Foo::Role $foo) {
        print 'Foo::Role: '.$foo;
    }
    multi method hello (Foo::Type $foo) {
        print 'Foo::Type: '.$foo;
    }
    
    package main;
    my $merger = Merger->new;
    my $f = Foo::Type->new;
    $merger->hello( $f );
    # Ambiguous match for multi method hello: (Foo::Role $foo), (Foo::Type $foo) 
    # with value [ Merger{  }, Foo::Type{  } ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with implementing a pure abstract class via inheritance , using namespace to
Need some help about with Memcache. I have created a class and want to
need a little help with this one. I have a form that I am
Need some insight on how this works I have the following piece of code
Need to know if I need to worry about people using this on my
Need to launch a new ASP.NET site on this server but need to be
Need a div to partially show the image behind it, is this even possible?
Need some advise on what I am doing wrong during client JSON parsing... Tips
need to return an array like this for example: array(30 => 'Mercedes Benz 310
Need for two dimensional array of objects that could be something like: myContainer<myObject*> *a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.