From: Graham Knop Date: Fri, 10 May 2013 13:33:46 +0000 (-0400) Subject: test path of compiling file rather than direct caller X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fcompiling_file;p=p5sagit%2Fstrictures.git test path of compiling file rather than direct caller --- diff --git a/lib/strictures.pm b/lib/strictures.pm index fb019d4..d986072 100644 --- a/lib/strictures.pm +++ b/lib/strictures.pm @@ -30,6 +30,16 @@ sub import { strict->import; warnings->import(FATAL => 'all'); + my $caller_file; + my $depth = 0; + while (my @caller = caller(++$depth)) { + if ($caller[3] =~ /::BEGIN$/) { + # older perls report the BEGIN in the wrong file + $caller_file = $depth > 1 ? (caller($depth-1))[1] : $caller[1]; + $caller_file = $caller[1]; + } + } + my $extra_tests = do { if (exists $ENV{PERL_STRICTURES_EXTRA}) { if (_PERL_LT_5_8_4 and $ENV{PERL_STRICTURES_EXTRA}) { @@ -38,7 +48,7 @@ sub import { } $ENV{PERL_STRICTURES_EXTRA}; } elsif (! _PERL_LT_5_8_4) { - !!((caller)[1] =~ /^(?:t|xt|lib|blib)/ + !!($caller_file =~ /^(?:t|xt|lib|blib)/ and $Smells_Like_VCS) } };