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 arrayref.' }, ); multifunction frobnicate => ( named => [ message => Str, truth => Bool ], code => sub ( $arg ) { $arg->truth ? $arg->message : 'Truth was 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