From: Michael G. Schwern Date: Wed, 30 May 2001 14:39:06 +0000 (+0100) Subject: Re: [PATCH lib/autouse.pm t/pragma/autouse.t] (was Re: [ID 20010528.001] use autouse... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5a02ccb1df652f2b0dd47663c285921ec8e27bd2;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH lib/autouse.pm t/pragma/autouse.t] (was Re: [ID 20010528.001] use autouse 'URI::Escape' => qw(URI::Escape::uri_escape) failed) Message-ID: <20010530143906.E670@blackrider.blackstar.co.uk> p4raw-id: //depot/perl@10318 --- diff --git a/lib/autouse.pm b/lib/autouse.pm index 15335b7..d320195 100644 --- a/lib/autouse.pm +++ b/lib/autouse.pm @@ -39,7 +39,7 @@ sub import { 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 { @@ -96,21 +96,33 @@ autouse - postpone load of modules until a function is used If the module C 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 defines func2() with prototype C<($;$)>, and func1() and -func3() have no prototypes. (At least if C uses C's -C, otherwise it is a fatal error.) +if C defines func2() with prototype C<($;$)>, and func1() has +no prototypes. (At least if C uses C's C, +otherwise it is a fatal error.) If the module C 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 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 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); + +Its not a very useful feature and has been deprecated. + +=end _deprecated + =head1 WARNING diff --git a/t/pragma/autouse.t b/t/pragma/autouse.t index 3dc5483..ecc1289 100644 --- a/t/pragma/autouse.t +++ b/t/pragma/autouse.t @@ -6,12 +6,17 @@ BEGIN { } use Test; -BEGIN { plan tests => 9; } +BEGIN { plan tests => 10; } BEGIN { require autouse; eval { - "autouse"->import('List::Util' => 'List::Util::first'); + "autouse"->import('List::Util' => 'List::Util::first(&@)'); + }; + ok( !$@ ); + + eval { + "autouse"->import('List::Util' => 'Foo::min'); }; ok( $@, qr/^autouse into different package attempted/ );