karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, please consider this:
package Foo { use strict; use warnings; use Class::Tiny; 1; } __END__
package Bar { use strict; use warnings; use Class::Tiny; 1; } __END__
package Methods { use strict; use warnings; use feature qw(isa); use Logic::Easy; no warnings qw(redefine); 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; use feature qw(say); my $gizmo = Foo->new(); my $mojo = Bar->new(); # dd $gizmo, $mojo; say Methods::frobnicate($_) for ($gizmo, $mojo); __END__
As expected, frobnicate cannot be imported - "there can be only one". Also with Methods->frobnicate() it does not work. Remains only Methods::frobnicate() - as to see. Or is there something else I have overlooked?
«The Crux of the Biscuit is the Apostrophe»
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to bring in multimethods
by tobyink (Canon) on Sep 21, 2023 at 10:14 UTC | |
by karlgoethebier (Abbot) on Sep 21, 2023 at 10:35 UTC | |
|
Re: How to bring in multimethods
by hv (Prior) on Sep 20, 2023 at 18:07 UTC | |
by karlgoethebier (Abbot) on Sep 21, 2023 at 09:49 UTC | |
|
Re: How to bring in multimethods
by LanX (Saint) on Sep 20, 2023 at 14:45 UTC | |
by karlgoethebier (Abbot) on Sep 20, 2023 at 15:48 UTC | |
by karlgoethebier (Abbot) on Sep 20, 2023 at 15:17 UTC |