X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Getopt.git;a=blobdiff_plain;f=lib%2FMooseX%2FGetopt%2FOptionTypeMap.pm;h=69ac55e34077dc0f045a314998e142c9422062ab;hp=a443d9d865e77b8a216839cc1385e20e830f943b;hb=f63e631037a9d743d874ae465e8b0a8d541c16c2;hpb=23575d4623f4f5357c62c5f5ff57053abf357e35 diff --git a/lib/MooseX/Getopt/OptionTypeMap.pm b/lib/MooseX/Getopt/OptionTypeMap.pm index a443d9d..69ac55e 100644 --- a/lib/MooseX/Getopt/OptionTypeMap.pm +++ b/lib/MooseX/Getopt/OptionTypeMap.pm @@ -16,8 +16,34 @@ my %option_type_map = ( 'HashRef' => '=s%', ); -sub has_option_type { exists $option_type_map{$_[1]} } -sub get_option_type { $option_type_map{$_[1]} } +sub has_option_type { + my (undef, $type_name) = @_; + return 1 if exists $option_type_map{$type_name}; + + my $current = find_type_constraint($type_name); + while (my $parent = $current->parent) { + return 1 if exists $option_type_map{$parent->name}; + $current = $parent; + } + + return 0; +} + +sub get_option_type { + my (undef, $type_name) = @_; + return $option_type_map{$type_name} + if exists $option_type_map{$type_name}; + + my $current = find_type_constraint($type_name); + while (my $parent = $current->parent) { + return $option_type_map{$parent->name} + if exists $option_type_map{$parent->name}; + $current = $parent; + } + + return; +} + sub add_option_type_to_map { my (undef, $type_name, $option_string) = @_; (defined $type_name && defined $option_string) @@ -76,4 +102,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut