From: Robin Barker Date: Tue, 24 Feb 2009 09:57:23 +0000 (+0000) Subject: remove explicit caller depth in deprecate.pm by searching caller stack for use/requir... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d4be36a8ea2b96180ed1c8dd5001a069eb7348d6;p=p5sagit%2Fp5-mst-13.2.git remove explicit caller depth in deprecate.pm by searching caller stack for use/require Module.pm --- diff --git a/lib/deprecate.pm b/lib/deprecate.pm index 23c045b..068c1b9 100644 --- a/lib/deprecate.pm +++ b/lib/deprecate.pm @@ -20,10 +20,23 @@ sub import { next if $site eq $priv; if ("$priv/$expect_leaf" eq $file) { + my $call_depth=1; + my @caller; + while (@caller = caller $call_depth++) { + last if $caller[7] # use/require + and $caller[6] eq $expect_leaf; # the package file + } + unless (@caller) { + require Carp; + Carp::cluck(<<"EOM"); +Can't find use/require $expect_leaf in caller stack +EOM + next; + } + # This is fragile, because it - # 1: depends on the number of call stacks in if.pm - # 2: is directly poking in the internals of warnings.pm - my ($call_file, $call_line, $callers_bitmask) = (caller 3)[1,2,9]; + # is directly poking in the internals of warnings.pm + my ($call_file, $call_line, $callers_bitmask) = @caller[1,2,9]; if (defined $callers_bitmask && (vec($callers_bitmask, $warnings::Offsets{deprecated}, 1)