package autouse;
#use strict; # debugging only
-use 5.003_90; # ->can, for my $var
+use 5.006; # use warnings
-$autouse::VERSION = '1.02';
+$autouse::VERSION = '1.06';
$autouse::DEBUG ||= 0;
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 {
my $load_sub = sub {
unless ($INC{$pm}) {
- eval {require $pm};
- die if $@;
+ require $pm;
vet_import $module;
}
+ no warnings qw(redefine prototype);
*$closure_import_func = \&{"${module}::$closure_func"};
print "autousing $module; "
."imported $closure_func as $closure_import_func\n"
};
if (defined $proto) {
- *$closure_import_func = eval "sub ($proto) { &\$load_sub }";
+ *$closure_import_func = eval "sub ($proto) { goto &\$load_sub }"
+ || die;
} else {
*$closure_import_func = $load_sub;
}
sub vet_import ($) {
my $module = shift;
if (my $import = $module->can('import')) {
- croak "autoused module has unique import() method"
+ croak "autoused module $module has unique import() method"
unless defined(&Exporter::import)
- && $import == \&Exporter::import;
+ && ($import == \&Exporter::import ||
+ $import == \&UNIVERSAL::import)
}
}
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