Commit | Line | Data |
8034a232 |
1 | |
2 | package MooseX::Getopt::OptionTypeMap; |
3 | |
4 | use Moose 'confess'; |
5 | use Moose::Util::TypeConstraints 'find_type_constraint'; |
6 | |
7 | our $VERSION = '0.01'; |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
10 | my %option_type_map = ( |
11 | 'Bool' => '!', |
12 | 'Str' => '=s', |
13 | 'Int' => '=i', |
14 | 'Float' => '=f', |
15 | 'ArrayRef' => '=s@', |
16 | 'HashRef' => '=s%', |
17 | ); |
18 | |
19 | sub has_option_type { exists $option_type_map{$_[1]} } |
20 | sub get_option_type { $option_type_map{$_[1]} } |
21 | sub add_option_type_to_map { |
22 | my (undef, $type_name, $option_string) = @_; |
23 | (defined $type_name && defined $option_string) |
24 | || confess "You must supply both a type name and an option string"; |
25 | (find_type_constraint($type_name)) |
26 | || confess "The type constraint '$type_name' does not exist"; |
27 | $option_type_map{$type_name} = $option_string; |
28 | } |
29 | |
30 | no Moose; no Moose::Util::TypeConstraints; 1; |
31 | |
32 | __END__ |
33 | |
34 | |
35 | =pod |
36 | |
37 | =head1 NAME |
38 | |
39 | MooseX::Getopt::OptionTypeMap - Storage for the option to type mappings |
40 | |
41 | =head1 DESCRIPTION |
42 | |
43 | See the I<Custom Type Constraints> section in the L<MooseX::Getopt> docs |
44 | for more info about how to use this module. |
45 | |
46 | =head1 METHODS |
47 | |
48 | These are all class methods and should be called as such. |
49 | |
50 | =over 4 |
51 | |
52 | =item B<has_option_type ($type_name)> |
53 | |
54 | =item B<get_option_type ($type_name)> |
55 | |
56 | =item B<add_option_type_to_map ($type_name, $option_spec)> |
57 | |
58 | =back |
59 | |
60 | =head1 BUGS |
61 | |
62 | All complex software has bugs lurking in it, and this module is no |
63 | exception. If you find a bug please either email me, or add the bug |
64 | to cpan-RT. |
65 | |
66 | =head1 AUTHOR |
67 | |
68 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
69 | |
70 | =head1 COPYRIGHT AND LICENSE |
71 | |
72 | Copyright 2007 by Infinity Interactive, Inc. |
73 | |
74 | L<http://www.iinteractive.com> |
75 | |
76 | This library is free software; you can redistribute it and/or modify |
77 | it under the same terms as Perl itself. |
78 | |
79 | =cut |