From: Vincent Pit Date: Mon, 13 Apr 2009 13:39:27 +0000 (+0200) Subject: Only load version.pm when needed in Test::Valgrind::Session so that it's not mandator... X-Git-Tag: v1.01~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=023a29965a41dc85c2250bd8c673b9d5b69746ba;p=perl%2Fmodules%2FTest-Valgrind.git Only load version.pm when needed in Test::Valgrind::Session so that it's not mandatory at configure time --- diff --git a/lib/Test/Valgrind/Session.pm b/lib/Test/Valgrind/Session.pm index 6c09793..b95c1d6 100644 --- a/lib/Test/Valgrind/Session.pm +++ b/lib/Test/Valgrind/Session.pm @@ -30,8 +30,6 @@ BEGIN { require Fcntl; # F_SETFD require POSIX; # SIGKILL - - require version; } use base qw/Test::Valgrind::Carp/; @@ -82,6 +80,11 @@ Defaults to none. =cut +my $build_version = sub { + require version; + version->new($_[0]); +}; + sub new { my $class = shift; $class = ref($class) || $class; @@ -102,15 +105,19 @@ sub new { $class->_croak('Empty valgrind candidates list') unless @paths; my $min_version = delete $args{min_version}; - defined and not ref and $_ = version->new($_) for $min_version; + defined and not ref and $_ = $build_version->($_) for $min_version; my ($valgrind, $version); for (@paths) { next unless -x; my $ver = qx/$_ --version/; if ($ver =~ /^valgrind-(\d+(\.\d+)*)/) { - $version = version->new($1); - next if $min_version and $version < $min_version; + if ($min_version) { + $version = $build_version->($1); + next if $version < $min_version; + } else { + $version = $1; + } $valgrind = $_; last; } @@ -138,13 +145,24 @@ The path to the selected C executable. The L object associated to the selected C. +=cut + +sub version { + my ($self) = @_; + + my $version = $self->{version}; + $self->{version} = $version = $build_version->($version) unless ref $version; + + return $version; +} + =head2 C Read-only accessor for the C option. =cut -eval "sub $_ { \$_[0]->{$_} }" for qw/valgrind version no_def_supp/; +eval "sub $_ { \$_[0]->{$_} }" for qw/valgrind no_def_supp/; =head2 C