=cut
+use Config ();
use File::Spec ();
+use ExtUtils::MM (); # MM->maybe_command()
use Scalar::Util ();
use Fcntl (); # F_SETFD
if (defined $vg and not ref $vg) {
@paths = ($vg);
} else {
- push @paths, @$vg if $vg and ref $vg eq 'ARRAY';
+ push @paths, @$vg if defined $vg and ref $vg eq 'ARRAY';
my $dirs = delete $args{search_dirs};
- $dirs = [ File::Spec->path ] unless $dirs;
- push @paths, map File::Spec->catfile($_, 'valgrind'), @$dirs
+ $dirs = [ File::Spec->path ] unless defined $dirs;
+ my $exe_name = 'valgrind';
+ $exe_name .= $Config::Config{exe_ext} if defined $Config::Config{exe_ext};
+ push @paths, map File::Spec->catfile($_, $exe_name), @$dirs
if ref $dirs eq 'ARRAY';
}
$class->_croak('Empty valgrind candidates list') unless @paths;
}
my ($valgrind, $version);
- for (@paths) {
- next unless -x;
- my $output = qx/$_ --version/;
+ for my $path (@paths) {
+ next unless defined($path) and MM->maybe_command($path);
+ my $output = qx/$path --version/;
$version = do {
local $@;
eval { Test::Valgrind::Version->new(command_output => $output) };
};
if (defined $version) {
next if defined $min_version and $version < $min_version;
- $valgrind = $_;
+ $valgrind = $path;
last;
}
}