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

I am writing a small module for my work & trying out OO Perl at the same time. I think I have everything correct but when I run a script accessing it I get the following:

Can't locate object method "new" via package "Config" at /acies/home/ebodine/test2.pl line 20.

Here are the relevant lines in the script:
use Config; my $file = "/somedir/somefile"; my $file_obj = Config->new($file);
Here is the module:
package Config; use strict; $VERSION = 0.1; $DEBUG = 1; # 1 Prints out debug information. sub new { my ($class) = @_; bless { _file => $_[1], }, $class; }
I don't see what I am doing wrong...any monks see what I am missing?? Any help/suggestions would be much appreciated.

Replies are listed 'Best First'.
Re: OO Perl modules on 5.005_3
by mojotoad (Monsignor) on Jul 23, 2002 at 18:10 UTC
    Config.pm is a package distributed with Perl. As such, this module is the first one found when you use Config;. To fix that, either rename your module (in both the package line as well as your use statement) or place your module's directory first in @INC (inside a BEGIN statement).

    I recommend renaming your module -- it avoids confusion. Other modules rely on Config.pm and if they find yours loaded instead, it is likely to break things.

    Matt

      I knew it had to be something that simple, many thanks

      --ERick
Re: OO Perl modules on 5.005_3
by dpuu (Chaplain) on Jul 23, 2002 at 18:13 UTC
    There is a module named Config that is installed as part of Perl. Your "use Config" may be getting this, instead of your own. (you can check this by printing $INC{"Config.pm"}). Try renaming your module. --Dave.