summaryrefslogtreecommitdiff
path: root/dist/autouse
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-11-20 23:46:48 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-11-21 00:32:32 -0800
commit799fd3b94fb5c431b24ee141e32a0b09d56f303c (patch)
tree5904101734c7d8b82fa4850ab89e14140768db5f /dist/autouse
parent53e2b4984825f4be9303a134996decfc9fb895ed (diff)
downloadperl-799fd3b94fb5c431b24ee141e32a0b09d56f303c.tar.gz
Restore autouse’s exemption from redef warnings
This also restores the subroutine redefinition warning for newly-cre- ated XSUBs outside the autouse package. See below. This commit added the exemption to fix a known bug, that loading a module and importing from it would cause a redefinition warning if there were an autouse stub: perl-5.004_03-1092-g2f34f9d commit 2f34f9d4825ac9262ece854fc4c50479f4838ff8 Author: Ilya Zakharevich <ilya@math.berkeley.edu> Date: Mon Mar 2 16:36:02 1998 -0500 Make autouse -w-safe p4raw-id: //depot/perl@781 The subroutine redefinition warning occurs in three places. This commit removed the autouse exemption from two of them. I can’t see how it wasn’t a mistake, as <5104D4DBC598D211B5FE0000F8FE7EB202D49EE9@mbtlipnt02.btlabs.bt.co.uk> (the apparent source of the patch, makes no mention of it: perl-5.005_02-2920-ge476b1b commit e476b1b5c29f354cf8dad61a9fc6d855bdfb5b7d Author: Gurusamy Sarathy <gsar@cpan.org> Date: Sun Feb 20 22:58:09 2000 +0000 lexical warnings update, ability to inspect bitmask in calling scope, among other things (from Paul Marquess) p4raw-id: //depot/perl@5170 This commit refactored things to remove some compiler warnings, but in doing so reversed the logic of the condition, causing redefini- tion warnings for newly-created XSUBs to apply only to subs from the autouse package: perl-5.8.0-5131-g66a1b24 commit 66a1b24beb76ea873ad4caa57ee3ab9df945afbf Author: Andy Lester <andy@petdance.com> Date: Mon Jun 6 05:11:07 2005 -0500 Random cleanups #47 Message-ID: <20050606151107.GC7022@petdance.com> p4raw-id: //depot/perl@24735 I’ve basically reinstated the changes in 2f34f9d4, but with tests this time. It may not make sense for autouse to be exempt for newATTRSUB and newXS, but keeping the logic surrounding the warning as close as possible to being the same could allow future refactorings to merge them.
Diffstat (limited to 'dist/autouse')
-rw-r--r--dist/autouse/t/autouse.t33
-rw-r--r--dist/autouse/t/lib/MyTestModule2.pm12
2 files changed, 44 insertions, 1 deletions
diff --git a/dist/autouse/t/autouse.t b/dist/autouse/t/autouse.t
index 53e1740df9..59374c2057 100644
--- a/dist/autouse/t/autouse.t
+++ b/dist/autouse/t/autouse.t
@@ -8,7 +8,7 @@ BEGIN {
}
}
-use Test::More tests => 12;
+use Test::More tests => 15;
BEGIN {
require autouse;
@@ -69,3 +69,34 @@ autouse->import("MyTestModule" => 'test_function');
my $ret = test_function();
is( $ret, 'works' );
+# Test that autouse is exempt from all methods of triggering the subroutine
+# redefinition warning.
+SKIP: {
+ skip "Fails in 5.15.5 and below (perl bug)", 2 if $] < 5.0150051;
+ use warnings; local $^W = 1;
+ my $w;
+ local $SIG{__WARN__} = sub { $w .= shift };
+ use autouse MyTestModule2 => 'test_function2';
+ *MyTestModule2::test_function2 = \&test_function2;
+ require MyTestModule2;
+ is $w, undef,
+ 'no redefinition warning when clobbering autouse stub with new sub';
+ undef $w;
+ import MyTestModule2 'test_function2';
+ is $w, undef,
+ 'no redefinition warning when clobbering autouse stub via *a=\&b';
+}
+SKIP: {
+ skip "Fails from 5.10 to 5.15.5 (perl bug)", 1
+ if $] < 5.0150051 and $] > 5.0099;
+ use Config;
+ skip "no B", 1 unless $Config{extensions} =~ /\bB\b/;
+ use warnings; local $^W = 1;
+ my $w;
+ local $SIG{__WARN__} = sub { $w .= shift };
+ use autouse B => "sv_undef";
+ *B::sv_undef = \&sv_undef;
+ require B;
+ is $w, undef,
+ 'no redefinition warning when clobbering autouse stub with new XSUB';
+}
diff --git a/dist/autouse/t/lib/MyTestModule2.pm b/dist/autouse/t/lib/MyTestModule2.pm
new file mode 100644
index 0000000000..e2b551b2a7
--- /dev/null
+++ b/dist/autouse/t/lib/MyTestModule2.pm
@@ -0,0 +1,12 @@
+package MyTestModule2;
+use warnings;
+
+@ISA = Exporter;
+require Exporter;
+@EXPORT_OK = 'test_function2';
+
+sub test_function2 {
+ return 'works';
+}
+
+1;