From: Vincent Pit Date: Tue, 7 Apr 2015 16:26:07 +0000 (-0300) Subject: Factor most of the ARGV filtering logic into its own sub X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScalar-Vec-Util.git;a=commitdiff_plain;h=dd9de87457a5c03961779add970e9d0f103d334f Factor most of the ARGV filtering logic into its own sub --- diff --git a/Makefile.PL b/Makefile.PL index ac429aa..49e3969 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -72,24 +72,35 @@ sub check_exe { return $exe; } -my $pp; -for my $i (0 .. $#ARGV) { - my $arg = $ARGV[$i]; - if ($arg =~ /^PP=(.*)/) { - my $val = $1; - if (do { no warnings 'numeric'; int $val } or $val =~ /^(?:y|yes)$/i) { - print "Forcing the pure-Perl implementation from the arguments passed to Makefile.PL.\n"; - $pp = 1; - last; +sub filter_argv { + my ($var, $code) = @_; + + my $ret; + + for my $i (0 .. $#ARGV) { + my $arg = $ARGV[$i]; + if ($arg =~ /^\Q$var\E=(.*)/) { + my $val = $1; + $ret = $code->($val); + $ARGV[$i] = undef; + last if $ret; } - $ARGV[$i] = undef; } -} -@ARGV = grep defined, @ARGV; + @ARGV = grep defined, @ARGV; + + return $ret; +} my ($cc, $ld); -unless ($pp) { +my $pp = filter_argv PP => sub { + my ($val) = @_; + return (do { no warnings 'numeric'; int $val } or $val =~ /^(?:y|yes)$/i) + ? 1 : 0; +}; +if ($pp) { + print "Forcing the pure-Perl implementation from the arguments passed to Makefile.PL.\n"; +} else { $cc = check_exe('C compiler', 'CC', 'cc', 'CC'); if (defined $cc) { my ($vol, $dir, $file) = File::Spec->splitpath($cc);