* cmd_flag parameter now works correctly.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Parser / Long.pm
index a6a2800..70ad5a1 100644 (file)
@@ -27,28 +27,16 @@ sub build_options {
         unless $getopt->isa('MooseX::Getopt::Session');
 
     my %options;
-
     my @opts;
 
     foreach my $attr (@attrs) {
         my $name = $attr->name;
 
-        my $is_cmd = $attr->does('MooseX::Getopt::Meta::Attribute::Trait');
-
-        my $opt_string = $is_cmd && $attr->has_cmd_flag
-                         ? $attr->cmd_flag
-                         : $name;
-        
-        if ($is_cmd && $attr->has_cmd_aliases && scalar @{ $attr->cmd_aliases }) {
-            $opt_string .= '|' . join '|', @{ $attr->cmd_aliases };
-        };
+        my ($flag, @aliases) = $getopt->_get_cmd_flags_for_attr($attr);
+        my $type = $getopt->_get_cmd_type_for_attr($attr);
 
-        if ($is_cmd && $attr->has_cmd_type || $attr->has_type_constraint) {
-            my $type = $is_cmd && $attr->has_cmd_type ? $attr->cmd_type : $attr->type_constraint;
-            if (MooseX::Getopt::OptionTypeMap->has_option_type($type)) {
-                $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type)
-            };
-        };
+        my $opt_string = join '|', $flag, @aliases;
+        $opt_string .= MooseX::Getopt::OptionTypeMap->get_option_type($type);
 
         $options{$name} = undef;
         push @opts, $opt_string => \$options{$name};