X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FTest%2FValgrind%2FSession.pm;h=8d78d86e730b3802e5bb70612e37b58a045df16e;hb=1032312bd6aa3f16153e3ba3fdf6b4d2531dea8c;hp=ba00ee24e02028b4ac7a7d6c4e6ddc2c97671f9e;hpb=5dd4ffc1370138eb1e9501f82a69f98208e4c0ff;p=perl%2Fmodules%2FTest-Valgrind.git diff --git a/lib/Test/Valgrind/Session.pm b/lib/Test/Valgrind/Session.pm index ba00ee2..8d78d86 100644 --- a/lib/Test/Valgrind/Session.pm +++ b/lib/Test/Valgrind/Session.pm @@ -9,11 +9,11 @@ Test::Valgrind::Session - Test::Valgrind session object. =head1 VERSION -Version 1.17 +Version 1.19 =cut -our $VERSION = '1.17'; +our $VERSION = '1.19'; =head1 DESCRIPTION @@ -22,7 +22,9 @@ It also acts as a dispatcher between the different components. =cut +use Config (); use File::Spec (); +use ExtUtils::MM (); # MM->maybe_command() use Scalar::Util (); use Fcntl (); # F_SETFD @@ -63,7 +65,7 @@ Defaults to the current C environment variable. If a simple scalar C<$valgrind> is passed as the value to C<'valgrind'>, it will be the only candidate. C<@search_dirs> will then be ignored. -If an array refernce C<\@valgrind> is passed, its values will be I to the list of the candidates resulting from C<@search_dirs>. +If an array reference C<\@valgrind> is passed, its values will be I to the list of the candidates resulting from C<@search_dirs>. =item * @@ -111,10 +113,12 @@ sub new { 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; @@ -125,16 +129,17 @@ sub new { } my ($valgrind, $version); - for (@paths) { - next unless -x; - my $output = qx/$_ --version/; - $version = do { + for my $path (@paths) { + next unless defined($path) and MM->maybe_command($path); + my $output = qx/$path --version/; + my $ver = do { local $@; eval { Test::Valgrind::Version->new(command_output => $output) }; }; - if (defined $version) { - next if defined $min_version and $version < $min_version; - $valgrind = $_; + if (defined $ver) { + next if defined $min_version and $ver < $min_version; + $valgrind = $path; + $version = $ver; last; } } @@ -637,7 +642,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved. +Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.