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};
};
+sub _get_cmd_flags_for_attr {
+ my ($self, $attr) = @_;
+
+ my $flag = $attr->name;
+
+ my @aliases;
+
+ if ($attr->does('MooseX::Getopt::Meta::Attribute::Trait')) {
+ $flag = $attr->cmd_flag if $attr->has_cmd_flag;
+ @aliases = @{ $attr->cmd_aliases } if $attr->has_cmd_aliases;
+ };
+
+ return ($flag, @aliases);
+};
+
+
+sub _get_cmd_type_for_attr {
+ my ($self, $attr) = @_;
+
+ my $type;
+
+ $type = $attr->type_constraint if $attr->has_type_constraint;
+
+ if ($attr->does('MooseX::Getopt::Meta::Attribute::Trait')) {
+ $type = $attr->cmd_type if $attr->has_cmd_type;
+ };
+
+ return $type;
+};
+
+
1;
around '_compute_getopt_attrs' => sub {
my $next = shift;
- my ( $class, @args ) = @_;
- grep {
- $_->isa("MooseX::Getopt::Meta::Attribute")
+ my ($class, @args) = @_;
+
+ return grep {
+ $_->does('MooseX::Getopt::Meta::Attribute::Trait')
} $class->$next(@args);
};