This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #39739] Exporter::Heavy ignores custom $SIG{__WARN__} handlers
authorTony Cook <tony@develop-help.com>
Thu, 18 Jul 2013 06:03:19 +0000 (16:03 +1000)
committerTony Cook <tony@develop-help.com>
Fri, 26 Jul 2013 00:59:05 +0000 (10:59 +1000)
dist/Exporter/lib/Exporter/Heavy.pm
dist/Exporter/t/warn.t

index 724028a..21b67c1 100644 (file)
@@ -38,8 +38,13 @@ sub _rebuild_cache {
 
 sub heavy_export {
 
 
 sub heavy_export {
 
+    # Save the old __WARN__ handler in case it was defined
+    my $oldwarn = $SIG{__WARN__};
+
     # First make import warnings look like they're coming from the "use".
     local $SIG{__WARN__} = sub {
     # First make import warnings look like they're coming from the "use".
     local $SIG{__WARN__} = sub {
+       # restore it back so proper stacking occurs
+       local $SIG{__WARN__} = $oldwarn;
        my $text = shift;
        if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
            require Carp;
        my $text = shift;
        if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
            require Carp;
index 49a109c..3010964 100644 (file)
@@ -34,6 +34,6 @@ package main;
 
     local $SIG{__WARN__} = sub { push @warn, join "", @_ };
     eval { Foo->import(":quux") };
 
     local $SIG{__WARN__} = sub { push @warn, join "", @_ };
     eval { Foo->import(":quux") };
-    ok(grep(/"quux" is not defined/, @warn), "# TODO warnings captured");
+    ok(grep(/"quux" is not defined/, @warn), "warnings captured");
 }
 
 }