From: "Adriano Ferreira" <a.r.ferreira@gmail.com>
Message-ID: <
73ddeb6c0608240620s207124d1mc202aea6a4598576@mail.gmail.com>
p4raw-id: //depot/perl@28758
lib/SelectSaver.t See if SelectSaver works
lib/SelfLoader.pm Load functions only on demand
lib/SelfLoader.t See if SelfLoader works
+lib/SelfLoader-buggy.t See if SelfLoader works
lib/Shell.pm Make AUTOLOADed system() calls
lib/Shell.t Tests for above
lib/shellwords.pl Perl library to split into words with shell quoting
--- /dev/null
+#!./perl
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ }
+}
+
+use SelfLoader;
+
+# this script checks that errors on self-loaded
+# subroutines that affect $@ are reported
+
+eval { buggy(); };
+unless ($@ =~ /^syntax error/) {
+ print "not ";
+}
+print "ok 1 - syntax errors are reported\n";
+
+__END__
+
+sub buggy
+{
+ +>*;
+}
+
+
+=head1 RT 40216
+
+ by Bo Lindbergh <blgl@hagernas.com>, at Aug 22, 2006 5:42 PM
+
+In the example below, there's a syntax error in the selfloaded
+code for main::buggy. When the eval fails, SelfLoader::AUTOLOAD
+tries to report this with "croak $@;". Unfortunately,
+SelfLoader::croak does "require Carp;" without protecting $@,
+which gets clobbered. The program then dies with the
+uninformative message " at ./example line 3".
+
+#! /usr/local/bin/perl
+use SelfLoader;
+buggy();
+__END__
+sub buggy
+{
+ +>*;
+}
+
+=cut
+
our $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x;
our $attr_list = qr{ \s* : \s* (?: $one_attr )* }x;
-sub croak { require Carp; goto &Carp::croak }
-sub carp { require Carp; goto &Carp::carp }
+# in croak and carp, protect $@ from "require Carp;" RT #40216
+
+sub croak { { local $@; require Carp; } goto &Carp::croak }
+sub carp { { local $@; require Carp; } goto &Carp::carp }
AUTOLOAD {
print STDERR "SelfLoader::AUTOLOAD for $AUTOLOAD\n" if $DEBUG;