1MooseX::MultiMethods(3)User Contributed Perl DocumentatioMnooseX::MultiMethods(3)
2
3
4
6 MooseX::MultiMethods - Multi Method Dispatch based on Moose type
7 constraints
8
10 version 0.10
11
13 package Paper; use Moose;
14 package Scissors; use Moose;
15 package Rock; use Moose;
16 package Lizard; use Moose;
17 package Spock; use Moose;
18
19 package Game;
20 use Moose;
21 use MooseX::MultiMethods;
22
23 multi method play (Paper $x, Rock $y) { 1 }
24 multi method play (Paper $x, Spock $y) { 1 }
25 multi method play (Scissors $x, Paper $y) { 1 }
26 multi method play (Scissors $x, Lizard $y) { 1 }
27 multi method play (Rock $x, Scissors $y) { 1 }
28 multi method play (Rock $x, Lizard $y) { 1 }
29 multi method play (Lizard $x, Paper $y) { 1 }
30 multi method play (Lizard $x, Spock $y) { 1 }
31 multi method play (Spock $x, Rock $y) { 1 }
32 multi method play (Spock $x, Scissors $y) { 1 }
33 multi method play (Any $x, Any $y) { 0 }
34
35 my $game = Game->new;
36 $game->play(Paper->new, Rock->new); # 1, Paper covers Rock
37 $game->play(Spock->new, Paper->new); # 0, Paper disproves Spock
38 $game->play(Spock->new, Scissors->new); # 1, Spock smashes Scissors
39
41 This module provides multi method dispatch based on Moose type
42 constraints. It does so by providing a "multi" keyword that extends the
43 "method" keyword provided by MooseX::Method::Signatures.
44
45 When invoking a method declared as "multi" a matching variant is being
46 searched in all the declared multi variants based on the passed
47 parameters and the declared type constraints. If a variant has been
48 found, it will be invoked. If no variant could be found, an exception
49 will be thrown.
50
52 Florian Ragwitz <rafl@debian.org>
53
55 This software is copyright (c) 2010 by Florian Ragwitz.
56
57 This is free software; you can redistribute it and/or modify it under
58 the same terms as the Perl 5 programming language system itself.
59
60
61
62perl v5.12.1 2010-01-03 MooseX::MultiMethods(3)