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.


In reply to Re: use autouse with OOP by btrott
in thread use autouse with OOP by DBX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.