From: Vincent Pit Date: Tue, 9 Sep 2008 22:00:54 +0000 (+0200) Subject: Search for the first file and fallback to the first module if there's not X-Git-Tag: v0.06~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Valgrind.git;a=commitdiff_plain;h=1a45e7f9e0b3b355dbfe3a3e70d638880aa2b264 Search for the first file and fallback to the first module if there's not --- diff --git a/lib/Test/Valgrind.pm b/lib/Test/Valgrind.pm index eb9fcb4..e8925d8 100644 --- a/lib/Test/Valgrind.pm +++ b/lib/Test/Valgrind.pm @@ -114,14 +114,23 @@ sub import { croak 'Optional arguments must be passed as key => value pairs' if @_ % 2; my %args = @_; if (!defined $args{run} && !$run) { - my ($file, $next); + my ($file, $pm, $next); my $l = 0; while ($l < 1000) { $next = (caller $l++)[1]; last unless defined $next; - $file = $next; + next unless $next ne '-e' and $next !~ /^\s*\(\s*eval\s*\d*\s*\)\s*$/ + and -f $next; + if ($next =~ /\.pm$/) { + $pm = $next; + } else { + $file = $next; + } + } + unless (defined $file) { + $file = $pm; + return unless defined $pm; } - return if not $file or $file eq '-e'; my $callers = $args{callers}; $callers = 12 unless defined $callers; $callers = int $callers;