From: Roderick Schertler Date: Thu, 13 Mar 1997 23:40:51 +0000 (-0500) Subject: fix for Exporter's $SIG{__WARN__} handler X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2768ea1aeef34f42d096f198fbe629c8374ca429;p=p5sagit%2Fp5-mst-13.2.git fix for Exporter's $SIG{__WARN__} handler Exporter's $SIG{__WARN__} handler is too zealous. It fails here: $ cat t require Carp; package Foo; @ISA = qw(Exporter); @EXPORT_OK = @EXPORT_FAIL = qw(foo); sub export_fail { my $self = shift; Carp::carp("carp from export_fail"); return (); } package main; import Foo 'foo'; $ perl5.00393 t carp from export_fail at t line 16 at t line 16 This is because the carp() inside export_fail triggers Exporter's __WARN__ handler which calls carp() a second time which adds the second " at t line 16". I was surprised to learn that carp() adds its string to an error message which ends with a newline, I thought it followed warn()'s lead on that. I checked 5.003 and it was the same there, too, though. Also, shouldn't Exporter's __WARN__ handler increment $Carp::CarpLevel rather than setting it to 1? I didn't include that in the patch because I'm not sure, but it seems the right thing to do to me. p5p-msgid: 2282.858296451@eeyore.ibcinc.com --- diff --git a/lib/Exporter.pm b/lib/Exporter.pm index abdb1e7..72a1401 100644 --- a/lib/Exporter.pm +++ b/lib/Exporter.pm @@ -12,9 +12,13 @@ sub export { # First make import warnings look like they're coming from the "use". local $SIG{__WARN__} = sub { my $text = shift; - $text =~ s/ at \S*Exporter.pm line \d+.*\n//; - local $Carp::CarpLevel = 1; # ignore package calling us too. - Carp::carp($text); + if ($text =~ s/ at \S*Exporter.pm line \d+.*\n//) { + local $Carp::CarpLevel = 1; # ignore package calling us too. + Carp::carp($text); + } + else { + warn $text; + } }; local $SIG{__DIE__} = sub { Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT") @@ -246,7 +250,7 @@ In other files which wish to use ModuleName: =head1 DESCRIPTION The Exporter module implements a default C method which -many modules choose inherit rather than implement their own. +many modules choose to inherit rather than implement their own. Perl automatically calls the C method when processing a C statement for a module. Modules and C are documented