develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [ID 20010704.005] autouse isn't -w safe

Thread Previous
From:
Michael G Schwern
Date:
July 4, 2001 12:06
Subject:
Re: [ID 20010704.005] autouse isn't -w safe
Message ID:
20010704150609.J20340@blackrider
On Wed, Jul 04, 2001 at 06:44:51PM -0000, sam@airtrout.tregar.com wrote:
> I searched the archives and found some discussion of this problem.  It
> seems like it was fixed in 5.004, perhaps.  Regardless, it's
> definitely broken in 5.6.1:
> 
> $ perl -we 'use autouse Carp => qw(carp croak); carp("1"); croak("2");'
> Subroutine carp redefined at /usr/local/lib/perl5/5.6.1/autouse.pm line 57.
> 1 at -e line 1
> Subroutine croak redefined at /usr/local/lib/perl5/5.6.1/autouse.pm line 57.
> 2 at -e line 1

Already noted and fixed.  The fix should appear in 5.8.0 and 5.6.2.
If you can't wait, here's the patch (all you really need is that "no
warnings qw(redefine)")


--- autouse.pm	Tue Jun 12 16:28:01 2001
+++ autouse.pm	Fri Jun 29 00:43:02 2001
@@ -3,7 +3,7 @@
 #use strict;		# debugging only
 use 5.003_90;		# ->can, for my $var
 
-$autouse::VERSION = '1.02';
+$autouse::VERSION = '1.03';
 
 $autouse::DEBUG ||= 0;
 
@@ -39,7 +39,7 @@
 
 	my $closure_import_func = $func;	# Full name
 	my $closure_func = $func;		# Name inside package
-	my $index = index($func, '::');
+	my $index = rindex($func, '::');
 	if ($index == -1) {
 	    $closure_import_func = "${callpkg}::$func";
 	} else {
@@ -54,6 +54,7 @@
 		die if $@;
 		vet_import $module;
 	    }
+            no warnings 'redefine';
 	    *$closure_import_func = \&{"${module}::$closure_func"};
 	    print "autousing $module; "
 		  ."imported $closure_func as $closure_import_func\n"
@@ -95,28 +96,40 @@
 
 If the module C<Module> is already loaded, then the declaration
 
-  use autouse 'Module' => qw(func1 func2($;$) Module::func3);
+  use autouse 'Module' => qw(func1 func2($;$));
 
 is equivalent to
 
   use Module qw(func1 func2);
 
-if C<Module> defines func2() with prototype C<($;$)>, and func1() and
-func3() have no prototypes.  (At least if C<Module> uses C<Exporter>'s
-C<import>, otherwise it is a fatal error.)
+if C<Module> defines func2() with prototype C<($;$)>, and func1() has
+no prototypes.  (At least if C<Module> uses C<Exporter>'s C<import>,
+otherwise it is a fatal error.)
 
 If the module C<Module> is not loaded yet, then the above declaration
-declares functions func1() and func2() in the current package, and
-declares a function Module::func3().  When these functions are called,
-they load the package C<Module> if needed, and substitute themselves
-with the correct definitions.
+declares functions func1() and func2() in the current package.  When
+these functions are called, they load the package C<Module> if needed,
+and substitute themselves with the correct definitions.
+
+=begin _deprecated
+
+   use Module qw(Module::func3);
+
+will work and is the equivalent to:
+
+   use Module qw(func3);
+
+It is not a very useful feature and has been deprecated.
+
+=end _deprecated
+
 
 =head1 WARNING
 
 Using C<autouse> will move important steps of your program's execution
 from compile time to runtime.  This can
 
-=over
+=over 4
 
 =item *
 



-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
Maybe they hooked you up with one of those ass-making magazines.
	-- brian d. foy as misheard by Michael G Schwern

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About