in reply to use autouse with OOP
When I run this I get:use autouse 'Net::SSH::Perl' => 'Net::SSH::Perl::new'; my $ssh = Net::SSH::Perl->new;
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.autouse into different package attempted at a.pl line 4 BEGIN failed--compilation aborted at a.pl line 4
The following patch seems to fix the behavior:
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.--- 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 {
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.
|
|---|