In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/a7caeb5ea5f808dade098c97e87d3354b994f68f?hp=5b95d1b1b5e7cb1ddfe987a377507d21b7d91587>
- Log ----------------------------------------------------------------- commit a7caeb5ea5f808dade098c97e87d3354b994f68f Author: Father Chrysostomos <spr...@cpan.org> Date: Sun Feb 11 12:40:09 2018 -0800 Test for _at_level functions with fh commit 25ebbc22701a587d60124611ae3b072d2d47883a Author: Slaven Rezić <sla...@rezic.de> Date: Sun Feb 11 12:36:07 2018 -0800 warnings: Omit handle when $. is 0 otherwise the new _at_level functions end up including ‘at <handle> line 0’. [Commit message by the committer.] ----------------------------------------------------------------------- Summary of changes: lib/warnings.pm | 2 +- regen/warnings.pl | 2 +- t/lib/warnings/9enabled | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/warnings.pm b/lib/warnings.pm index ea88daf891..911c5aad5a 100644 --- a/lib/warnings.pm +++ b/lib/warnings.pm @@ -448,7 +448,7 @@ sub __chk # If we have an explicit level, bypass Carp. if ($has_level and @callers_bitmask) { my $stuff = " at " . join " line ", (caller $i)[1,2]; - $stuff .= ", <" . *${^LAST_FH}{NAME} . "> line $." if ${^LAST_FH}; + $stuff .= ", <" . *${^LAST_FH}{NAME} . "> line $." if $. && ${^LAST_FH}; die "$message$stuff.\n" if $results[0]; return warn "$message$stuff.\n"; } diff --git a/regen/warnings.pl b/regen/warnings.pl index a94a7522e8..ef2d16999b 100644 --- a/regen/warnings.pl +++ b/regen/warnings.pl @@ -765,7 +765,7 @@ sub __chk # If we have an explicit level, bypass Carp. if ($has_level and @callers_bitmask) { my $stuff = " at " . join " line ", (caller $i)[1,2]; - $stuff .= ", <" . *${^LAST_FH}{NAME} . "> line $." if ${^LAST_FH}; + $stuff .= ", <" . *${^LAST_FH}{NAME} . "> line $." if $. && ${^LAST_FH}; die "$message$stuff.\n" if $results[0]; return warn "$message$stuff.\n"; } diff --git a/t/lib/warnings/9enabled b/t/lib/warnings/9enabled index bbef5e8d41..7a9acd4bb8 100644 --- a/t/lib/warnings/9enabled +++ b/t/lib/warnings/9enabled @@ -1436,3 +1436,21 @@ Died: A fatal syntax warning at - line 25. A syntax warning at - line 23. A utf8 warning at - line 25. Died: A fatal utf8 warning at - line 23. +######## +# NAME _at_level with filehandle +use warnings; +# Create temp file for testing handles. +open oUt, ">tmp" or die $!; +print oUt "foo\nbar\n"; +close oUt; +sub bimp { + open FH, "tmp"; + <FH>; <FH>; + warnings::warn_at_level("syntax", 0, "Foo warning"); + close FH; + warnings::warn_at_level("syntax", 0, "Bar warning"); +}; +bimp; +EXPECT +Foo warning at - line 13, <FH> line 2. +Bar warning at - line 13. -- Perl5 Master Repository