I've got a pretty good implementation of multimethods on CPAN. I'm biased, but I think it's the best underlying implementation, though I've done almost zero work on making the syntax nice.

use strict; use warnings; use experimental qw( signatures builtin ); use feature qw( say ); use builtin qw( true false ); use Sub::MultiMethod -all, -lexical; use Types::Common -types, -lexical; package Foo { use Class::Tiny }; package Bar { use Class::Tiny }; multifunction frobnicate => ( positional => [ InstanceOf['Foo'] ], code => sub ( $o ) { return 'It was a Foo.' }, ); multifunction frobnicate => ( positional => [ InstanceOf['Bar'] ], code => sub ( $o ) { return 'It was a Bar.' }, ); multifunction frobnicate => ( positional => [ HashRef, ArrayRef ], code => sub ( $h, $a ) { return 'They were a hashref and array +ref.' }, ); multifunction frobnicate => ( named => [ message => Str, truth => Bool ], code => sub ( $arg ) { $arg->truth ? $arg->message : 'Truth wa +s false' }, ); say frobnicate( Foo->new ); say frobnicate( Bar->new ); say frobnicate( {}, [] ); say frobnicate( message => "This will be seen", truth => true + ); say frobnicate( message => "This will NOT be seen", truth => false + ); say frobnicate( { message => "This will be seen", truth => true } + ); say frobnicate( { message => "This will NOT be seen", truth => false } + ); say frobnicate( [], undef, 123 ); # dies; no implementation available

In reply to Re: How to bring in multimethods by tobyink
in thread How to bring in multimethods by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.