"Single parameters to get_options_from_argv() must be a HASH ref"
) if ref $_[0] and ref $_ ne 'HASH';
- my $options = {
- %{ $class->get_options_from_configfile },
- @_ == 1 ? %{ $_[0] } : @_
- };
-
- my $getopt = defined $options->{getopt}
- ? $options->{getopt}
- : $class->_default_getopt_session->new(
- classes_filter => sub { $_ eq $class },
- options => $options,
- );
+ my %args = @_ == 1 ? %{ $_[0] } : @_;
+
+ my $getopt = defined $args{getopt}
+ ? $args{getopt}
+ : $class->_default_getopt_session->new(
+ classes_filter => sub { $_ eq $class },
+ );
+
+ # Combine explicit options and resend to session object
+ my %options = (
+ %{ $getopt->options }, # options from getopt session
+ $class->get_options_from_configfile, # options from --configfile
+ %args, # options from @_
+ );
+ $getopt->options( { %options } );
# Call Getopt parser only once.
$getopt->build_options if not $getopt->has_status;
- my $new_options = {
- %$options, # explicit options to ->new
+ # Combine final options
+ my %new_options = (
+ %options, # explicit options
%{ $getopt->options }, # options from CLI
- getopt => $getopt,
- };
+ getopt => $getopt, # session object itself
+ );
- return $new_options;
+ return wantarray ? %new_options : \%new_options;
};
sub get_options_from_configfile {
my $class = shift;
- my $options = {};
+ my %options;
if ( $class->meta->does_role('MooseX::ConfigFromFile') ) {
local @ARGV = @ARGV;
};
if ( defined $configfile ) {
- $options = $class->get_config_from_file($configfile);
+ %options = %{ $class->get_config_from_file($configfile) };
};
};
- return $options;
+ return wantarray ? %options : \%options;
};