in reply to How to bring in multimethods

As expected, frobnicate cannot be imported - "there can be only one".

I don't understand this sentence, but I also don't see anything in Methods.pm that would allow it to be exported. What happens if you use Exporter to make frobnicate exportable? A brief look at the implementation of multimethods suggests it should work fine.

Replies are listed 'Best First'.
Re^2: How to bring in multimethods
by karlgoethebier (Abbot) on Sep 21, 2023 at 09:49 UTC

    When I call it with Exporter like this:

    package Methods { use strict; use warnings; use feature qw(isa); use Logic::Easy; use Exporter qw(import) no warnings qw(redefine); our @EXPORT_OK = qw(frobnicate); sub frobnicate : Multi(frobnicate) { SIG [$o] where {$o isa 'Foo'}; qq(foo); } sub frobnicate : Multi(frobnicate) { SIG [$o] where {$o isa 'Bar'}; qq(bar); } 1; } __END__
    #!/usr/bin/env perl use strict; use warnings; use lib q(.); use Bar; use Foo; use Methods qw(frobnicate); use feature qw(say); my $gizmo = Foo->new(); my $mojo = Bar->new(); # dd $gizmo, $mojo; say frobnicate($_) for ($gizmo, $mojo); __END__

    I get:

    karl@h3002993:~/src/perl/mmdemo$ ./run.pl Logic::Easy control failed at Methods.pm line 16. at Methods.pm line 16. </p>

    The same result with say frobnicate($gizmo);. With say frobnicate($mojo); i get bar.

    With the loop and Methods::frobnicate($_) i get the expected result.

    «The Crux of the Biscuit is the Apostrophe»