2 package MooseX::Getopt::OptionTypeMap;
5 use Moose::Util::TypeConstraints 'find_type_constraint';
8 our $AUTHORITY = 'cpan:STEVAN';
10 my %option_type_map = (
20 my (undef, $type_name) = @_;
21 return 1 if exists $option_type_map{$type_name};
23 my $current = find_type_constraint($type_name);
26 || confess "Could not find the type constraint for '$type_name'";
28 while (my $parent = $current->parent) {
29 return 1 if exists $option_type_map{$parent->name};
37 my (undef, $type_name) = @_;
39 return $option_type_map{$type_name}
40 if exists $option_type_map{$type_name};
42 my $current = find_type_constraint($type_name);
45 || confess "Could not find the type constraint for '$type_name'";
47 while (my $parent = $current->parent) {
48 return $option_type_map{$parent->name}
49 if exists $option_type_map{$parent->name};
56 sub add_option_type_to_map {
57 my (undef, $type_name, $option_string) = @_;
58 (defined $type_name && defined $option_string)
59 || confess "You must supply both a type name and an option string";
60 (find_type_constraint($type_name))
61 || confess "The type constraint '$type_name' does not exist";
62 $option_type_map{$type_name} = $option_string;
65 no Moose; no Moose::Util::TypeConstraints; 1;
74 MooseX::Getopt::OptionTypeMap - Storage for the option to type mappings
78 See the I<Custom Type Constraints> section in the L<MooseX::Getopt> docs
79 for more info about how to use this module.
83 These are all class methods and should be called as such.
87 =item B<has_option_type ($type_name)>
89 =item B<get_option_type ($type_name)>
91 =item B<add_option_type_to_map ($type_name, $option_spec)>
97 All complex software has bugs lurking in it, and this module is no
98 exception. If you find a bug please either email me, or add the bug
103 Stevan Little E<lt>stevan@iinteractive.comE<gt>
105 =head1 COPYRIGHT AND LICENSE
107 Copyright 2007 by Infinity Interactive, Inc.
109 L<http://www.iinteractive.com>
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.