This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #77384] Passing a ref to warn doesn't append file and line
authorFather Chrysostomos <sprout@cpan.org>
Sun, 6 Mar 2011 02:11:52 +0000 (18:11 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 6 Mar 2011 02:38:47 +0000 (18:38 -0800)
This commit makes pp_warn stringify the warning if there is no
$SIG{__WARN__} handler. See the RT ticket for the discussion.

pp_sys.c
t/op/warn.t

index 73a5c8a..30a2645 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -449,7 +449,9 @@ PP(pp_warn)
     else {
        exsv = newSVpvs_flags("Warning: something's wrong", SVs_TEMP);
     }
-    warn_sv(exsv);
+    if (SvROK(exsv) && !PL_warnhook)
+        Perl_warn(aTHX_ "%"SVf, SVfARG(exsv));
+    else warn_sv(exsv);
     RETSETYES;
 }
 
index bcb12a6..4a927e2 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan 21;
+plan 22;
 
 my @warnings;
 my $wa = []; my $ea = [];
@@ -141,4 +141,11 @@ fresh_perl_like(
  'Wide character in warn (not print)'
 );
 
+fresh_perl_like(
+ 'warn []',
+  qr/^ARRAY\(0x[\da-f]+\) at /a,
+  { },
+ 'warn stringifies in the absence of $SIG{__WARN__}'
+);
+
 1;