1 package MooseX::Getopt::OptionTypeMap;
2 # ABSTRACT: Storage for the option to type mappings
4 use Moose 'confess', 'blessed';
5 use Moose::Util::TypeConstraints 'find_type_constraint';
7 my %option_type_map = (
17 my (undef, $type_or_name) = @_;
19 return 1 if exists $option_type_map{blessed($type_or_name) ? $type_or_name->name : $type_or_name};
21 my $current = blessed($type_or_name) ? $type_or_name : find_type_constraint($type_or_name);
24 || confess "Could not find the type constraint for '$type_or_name'";
26 while (my $parent = $current->parent) {
27 return 1 if exists $option_type_map{$parent->name};
35 my (undef, $type_or_name) = @_;
37 my $name = blessed($type_or_name) ? $type_or_name->name : $type_or_name;
39 return $option_type_map{$name} if exists $option_type_map{$name};
41 my $current = ref $type_or_name ? $type_or_name : find_type_constraint($type_or_name);
44 || confess "Could not find the type constraint for '$type_or_name'";
46 while ( $current = $current->parent ) {
47 return $option_type_map{$current->name}
48 if exists $option_type_map{$current->name};
54 sub add_option_type_to_map {
55 my (undef, $type_name, $option_string) = @_;
56 (defined $type_name && defined $option_string)
57 || confess "You must supply both a type name and an option string";
59 if ( blessed($type_name) ) {
60 $type_name = $type_name->name;
62 (find_type_constraint($type_name))
63 || confess "The type constraint '$type_name' does not exist";
66 $option_type_map{$type_name} = $option_string;
69 no Moose::Util::TypeConstraints;
76 See the I<Custom Type Constraints> section in the L<MooseX::Getopt> docs
77 for more info about how to use this module.
79 =method B<has_option_type ($type_or_name)>
81 =method B<get_option_type ($type_or_name)>
83 =method B<add_option_type_to_map ($type_name, $option_spec)>