1MooseX::Types::VariantTUasbelre(C3o)ntributed Perl DocumMeonotsaetXi:o:nTypes::VariantTable(3)
2
3
4
6 MooseX::Types::VariantTable - Type constraint based variant table
7
9 # see also MooseX::Types::VariantTable::Declare for a way to
10 # declare variant table based methods
11
12 use MooseX::Types::VariantTable;
13
14 my $dispatch_table = MooseX::Types::VariantTable->new(
15 variants => [
16 { type => "Foo", value => \&foo_handler },
17 { type => "Bar", value => \&bar_handler },
18 { type => "Item", value => \&fallback },
19 ],
20 );
21
22 # look up the correct handler for $thingy based on the type constraints it passes
23 my $entry = $dispatch_table->find_variant($thingy);
24
25 # or use the 'dispatch' convenience method if the entries are code refs
26 $dispatch_table->dispatch( $thingy, @args );
27
29 This object implements a simple dispatch table based on Moose type
30 constraints.
31
32 Subtypes will be checked before their parents, meaning that the order
33 of the declaration does not matter.
34
35 This object is used internally by Moose::Meta::Method::VariantTable and
36 MooseX::Types::VariantTable::Declare to provide primitive multi sub
37 support.
38
40 ambigious_match_callback
41 A code reference that'll be executed when find_variant found more than
42 one matching variant for a value. It defaults to something that simply
43 croaks with an error message like this:
44
45 Ambiguous match %s
46
47 where %s contains a list of stringified types that matched.
48
50 new
51 add_variant $type, $value
52 Registers $type, such that $value will be returned by
53 "find_variant" for items passing $type.
54
55 Subtyping is respected in the table.
56
57 find_variant $value
58 Returns the registered value for the most specific type that $value
59 passes.
60
61 dispatch $value, @args
62 A convenience method for when the registered values are code
63 references.
64
65 Calls "find_variant" and if the result is a code reference, it will
66 "goto" this code reference with the value and any additional
67 arguments.
68
69 has_type $type
70 Returns true if an entry for $type is registered.
71
72 has_parent $type
73 Returns true if a parent type of $type is registered.
74
76 The meta method composes in multiple inheritence but not yet with roles
77 due to extensibility issues with the role application code.
78
79 When Moose::Meta::Role can pluggably merge methods variant table
80 methods can gain role composition.
81
83 Yuval Kogman <nothingmuch@woobling.org>
84
85 Florian Ragwitz <rafl@debian.org>
86
88 Copyright (c) 2008 Yuval Kogman. All rights reserved
89 This program is free software; you can redistribute
90 it and/or modify it under the same terms as Perl itself.
91
92
93
94perl v5.36.0 2023-01-20 MooseX::Types::VariantTable(3)