The snippet that
bikeNomad posted does work when your
module name doesn't have a '::' in it, but I get errors when I try
to use a module that isn't a top-level namespace:
use autouse 'Net::SSH::Perl' => 'Net::SSH::Perl::new';
my $ssh = Net::SSH::Perl->new;
When I run this I get:
autouse into different package attempted at a.pl line 4
BEGIN failed--compilation aborted at a.pl line 4
Looking into this a bit more, this is happening because autouse
looks for the first occurrence of '::' in the function name, then
compares everything before that to the module name you passed
in. In my opinion it should be looking for the *last* occurrence
of '::'. This is autouse with both 5.005_03 and 5.6.1.
The following patch seems to fix the behavior:
--- autouse.pm.old Thu Jun 14 12:08:05 2001
+++ autouse.pm Thu Jun 14 12:08:11 2001
@@ -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 {
But I haven't really explored all of the implications of this, as
yet. :) Just be aware of this issue if you have the same problem.
Personally, I don't use autouse for OOP (or really at all), because
I tend to just require the module before I need to use it.