A less-well-known feature of use and require is that it gives a "hint" to the compiler that My::Module might be a class name so that "new My::Module" gets parsed okay. You don't need this hint unless you also have a subroutine "new" in the current package.

$ perl use strict; my $o= new My::Module; ^D Can't locate object method "new" via package "My::Module" $ perl use strict; sub new; my $o= new My::Module; ^D Bareword "My::Module" not allowed while "strict subs" in use $ perl use strict; BEGIN { $My::Module::VERSION= 1.0; } sub new; my $o= new My::Module; ^D Can't locate object method "new" via package "My::Module" $
So I'd suggest you start moving away from the "new My::Module" syntax as you can see how fragile it is.

As others have said, autouse.pm has an out-right bug in it.

You problem implies that use autouse My::Module => qw(new); predeclares "sub new;" instead of (or in addition to) "sub My::Module::new". It took me a bit to spot the problem. autouse.pm is not meant for use with OO modules and the routines you list get exported. My::Module doesn't normally export new() for good reason!

To get something like autouse.pm except for OO modules is actually much less work than what autouse.pm does. See (tye)Re: $PERL_USE=$PERL_USE: but use the better version in the reply.

If you want something that only does AutoNew for a particular package:

sub My::Module::new { require My::Module; undef &My::Module::new; goto &My::Module::new; }

        - tye (but my friends call me "Tye")

In reply to (tye)Re: use autouse with OOP by tye
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.