MooseX...ethods(3pm)
π MooseX::MultiMethods
okay bestie, so this is MooseX::MultiMethods(3pm) β straight out of the User Contributed Perl Documentation section, so you know it's the people's manpage π
β¨ VERSION β¨
version 0.10 β tiny number, huge energy π
π SYNOPSIS π
here's the whole vibe, literally a rock-paper-scissors-lizard-spock situation and it's iconic:
package Paper; use Moose;
package Scissors; use Moose;
package Rock; use Moose;
package Lizard; use Moose;
package Spock; use Moose;
package Game;
use Moose;
use MooseX::MultiMethods;
multi method play (Paper $x, Rock $y) { 1 }
multi method play (Paper $x, Spock $y) { 1 }
multi method play (Scissors $x, Paper $y) { 1 }
multi method play (Scissors $x, Lizard $y) { 1 }
multi method play (Rock $x, Scissors $y) { 1 }
multi method play (Rock $x, Lizard $y) { 1 }
multi method play (Lizard $x, Paper $y) { 1 }
multi method play (Lizard $x, Spock $y) { 1 }
multi method play (Spock $x, Rock $y) { 1 }
multi method play (Spock $x, Scissors $y) { 1 }
multi method play (Any $x, Any $y) { 0 }
my $game = Game->new;
$game->play(Paper->new, Rock->new); # 1, Paper covers Rock
$game->play(Spock->new, Paper->new); # 0, Paper disproves Spock
$game->play(Spock->new, Scissors->new); # 1, Spock smashes Scissors
eleven whole multi method play variants, all chillin' in one package, and the last one is the Any, Any fallback that just returns 0 when nobody wins. it's giving main character energy fr fr π¦
π DESCRIPTION π
so the way this works, bestie: this module does multi method dispatch based on Moose type constraints. the way it pulls that off is by handing you a multi keyword that extends the method keyword that MooseX::Method::Signatures already gives you. it's a glow-up, not a replacement π
and here's the moment-to-moment tea β when you invoke a method that's been declared as multi:
- a matching variant gets searched for across all the declared multi variants β it's looking at the parameters you passed and the declared type constraints π΅οΈββοΈ
- if a variant has been found, it will be invoked. slay β¨
- if no variant could be found, an exception will be thrown. π no silent failure, no pretending, it WILL tell you.
lowkey the important part: no match = exception. that's not a vibe, that's the rules π
π AUTHOR π
Florian Ragwitz <rafl@debian.org>
give them their flowers π
πΈ COPYRIGHT AND LICENSE πΈ
This software is copyright (c) 2010 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, babe π«Ά perl v5.36.0, dated 2022-12-13 β thanks for coming to my ted talk, now go dispatch some methods ππ
π¦ where this page comes from
- debian bookworm: libmoosex-multimethods-perl 0.10-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-multimethods-perl 0.10-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-multimethods-perl 0.10-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-multimethods-perl 0.10-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-multimethods-perl 0.10-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms