Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: use autouse with OOP

by btrott (Parson)
on Jun 14, 2001 at 23:10 UTC ( [id://88576]=note: print w/replies, xml ) Need Help??


in reply to use autouse with OOP

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://88576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found