Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Perl modules and "new"

by mreeske (Initiate)
on May 01, 2003 at 19:40 UTC ( [id://254782]=perlquestion: print w/replies, xml ) Need Help??

mreeske has asked for the wisdom of the Perl Monks concerning the following question:

I am working on an extensive project that heavily exploits object-oriented Perl. Recently I have been having trouble creating objects via the "new" method between the many different modules. Up until now I have been able to use the prefix form of
my $object = new Some::Random::Module();
and everything worked fine. However, after a few module additions, I have been getting this error:
Undefined subroutine &Some::Random::Module called at /perlmodules/Anot +her/Different/Module.pm line 92.
To correct this error I simply have to change my above syntax to
my $object = Some::Random::Module->new();
and everything continues on fine. This error has been continually poping up over the course of today and is trying my patience-- is there a reason why I must use one syntax over another, and is there any technical difference between the two syntaxes?


The collection of modules in the project has many interdependencies between them. I have tried different combinations of use, require and BEGIN, and the problem never completely goes away. Yes, I have checked to make sure that all of the correct files have the appropriate use/require statements in them.

Replies are listed 'Best First'.
Re: Perl modules and "new"
by bart (Canon) on May 01, 2003 at 19:46 UTC
    It's a known problem. See for example this note by Abigail. Simon Cozens recently wrote a blog entry about the same problem. I'll post the link as soon as I find it.

    Update: I found where I found it: this journal entry on use.perl.org, pointing to here. (And in case you didn't know, Simon Cozens is one of the Perl Gods.)

Re: Perl modules and "new"
by dragonchild (Archbishop) on May 01, 2003 at 19:49 UTC
    The first is called the indirect syntax. The second is the direct syntax. The first is less preferable because it requires the compiler to make guesses as to what new() function you want to use. The second makes it very clear to the compiler what's going on.

    I don't know about you, but I don't like making the compiler guess.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Perl modules and "new"
by crenz (Priest) on May 01, 2003 at 21:45 UTC

    I started a thread on this because I was wondering about it myself, and got a lot of really helpful answers. See OO style: Placement of "new".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found