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
# 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")
=head1 DESCRIPTION
The Exporter module implements a default C<import> 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<import> method when processing a
C<use> statement for a module. Modules and C<use> are documented