* Handle hyphen punctuation mark in cmd_flag and cmd_aliases.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Parser / Descriptive.pm
index ff05c8f..44035f1 100644 (file)
@@ -25,6 +25,13 @@ has format => (
     default => 'usage: %c %o',
 );
 
+# Usage object
+has usage => (
+    is => 'rw',
+    isa => 'Maybe[Getopt::Long::Descriptive::Usage]',
+    predicate => 'has_usage',
+);
+
 
 sub build_options {
     my $self = shift;
@@ -45,11 +52,13 @@ sub build_options {
         my ($flag, @aliases) = $getopt->_get_cmd_flags_for_attr($attr);
         my $type = $getopt->_get_cmd_type_for_attr($attr);
 
-        $cmd_flags_to_names{$flag} = $name;
-
         my $opt_string = join '|', $flag, @aliases;
         $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type) if $type;
 
+        # opt_string is unmangled; parsed options key is mangled
+        $flag =~ tr/-/_/;
+        $cmd_flags_to_names{$flag} = $name;
+
         my $doc;
         $doc = $attr->documentation if $attr->has_documentation;
         $doc = ' ' unless $doc;
@@ -89,11 +98,14 @@ sub build_options {
         $getopt->extra_argv( $extra_argv );
     };
 
+    # Store usage object
+    $self->usage( $usage );
+
     # Convert cmd_flags back to names in options hashref
     $new_options = { map { $cmd_flags_to_names{$_} => $new_options->{$_} } keys %$new_options };
 
-    # Include old options and usage object
-    $new_options = { usage => $usage, %$options, %$new_options };
+    # Include old options
+    $new_options = { %$options, %$new_options };
 
     $getopt->status( ! $warnings );
     $getopt->options( $new_options );