diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-08-31 17:47:23 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-09-01 11:32:07 -0700 |
commit | 25502127feba592f2312380b350122c445020707 (patch) | |
tree | 114d7f6ac5b79b5922af4dded2493bc732952083 /pp_ctl.c | |
parent | ecadf9b7005812a5eb20b351ef9bcd042c7e3daf (diff) | |
download | perl-25502127feba592f2312380b350122c445020707.tar.gz |
[perl #115768] improve (caller)[2] line numbers
warn and die have special code (closest_cop) to find a nulled
nextstate op closest to the warn or die op, to get the line number
from it. This commit extends that capability to caller, so that
if (1) {
foo();
}
sub foo { warn +(caller)[2] }
shows the right line number.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -1811,6 +1811,7 @@ PP(pp_caller) const HEK *stash_hek; I32 count = 0; bool has_arg = MAXARG && TOPs; + const COP *lcop; if (MAXARG) { if (has_arg) @@ -1854,7 +1855,11 @@ PP(pp_caller) PUSHTARG; } mPUSHs(newSVpv(OutCopFILE(cx->blk_oldcop), 0)); - mPUSHi((I32)CopLINE(cx->blk_oldcop)); + lcop = closest_cop(cx->blk_oldcop, cx->blk_oldcop->op_sibling, + cx->blk_sub.retop, TRUE); + if (!lcop) + lcop = cx->blk_oldcop; + mPUSHi((I32)CopLINE(lcop)); if (!has_arg) RETURN; if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { |