Skip to content

Commit

Permalink
an arrayref might be the second argument when using @argv
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 19, 2017
1 parent b2cfdc9 commit 3e8c6ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -148,10 +148,10 @@ sub files {
}

sub getopt {
my $opts = ref $_[1] eq 'ARRAY' ? splice @_, 1, 1 : [];
my ($array, $opts) = map { ref $_[0] eq 'ARRAY' ? shift : $_ } \@ARGV, [];
my $save = Getopt::Long::Configure(qw(default no_auto_abbrev no_ignore_case),
@$opts);
GetOptionsFromArray ref $_[0] eq 'ARRAY' ? @_ : (\@ARGV, @_);
GetOptionsFromArray $array, @_;
Getopt::Long::Configure($save);
}

Expand Down
6 changes: 3 additions & 3 deletions t/mojo/util.t
Expand Up @@ -137,9 +137,9 @@ is $whatever, 'Whatever!', 'right string';
is_deeply $array, ['stuff'], 'right structure';
{
local @ARGV = ('--charset', 'UTF-16', 'test');
getopt 'c|charset=s' => \my $charset;
is $charset, 'UTF-16', 'right string';
is_deeply \@ARGV, ['test'], 'right structure';
getopt 'c|charset=s' => \my @charset;
is_deeply \@charset, ['UTF-16'], 'right structure';
is_deeply \@ARGV, ['test'], 'right structure';
}

# unindent
Expand Down

0 comments on commit 3e8c6ae

Please sign in to comment.