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

Hi, When I execute the perl program it returns: Can't locate object method "load" via package "conf" (perhaps you forgot to load "conf"?) at socket.pm line 9. - socket.pm:
package socket; use strict; use IO::Socket; use conf; use irc; my $conf = load conf;
- conf.pm:
package conf; use strict; use irc; my %conf; sub load { my $proto = shift; my $self = ref($proto) || $proto; my $this = \%conf; bless($this, $self); return $this; }
Where is the problem? I don't know why it returns this problem... %conf is not empty. Thanks.

Edit by castaway: added code tags.

20040103 Edit by BazB: Changed title from 'problem with modules'

Replies are listed 'Best First'.
Re: Module problem: can't locate object method
by !1 (Hermit) on Jan 03, 2004 at 16:25 UTC

    I think it will be helpful if you make certain that there's no other conf module that perl might be trying to load. Check the path of conf.pm and then run:

    perl -mconf -le'print $INC{"conf.pm"}'

    If the paths don't match, then you might want to consider putting use lib "directory_of_module"; before use conf; in socket.pm to move the directory to the beginning of @INC. If the paths do match then you have a different problem. Check to make certain that you don't have a typo in the package declaration of conf.pm. For instance:

    package cpnf; # ^-- typo, now we can't find package conf ...

    Beyond that, does the subroutine appear after an __END__ or __DATA__? Hopefully something in this rant is useful.

    Update: Cleaned up and provided an example.

Re: Module problem: can't locate object method
by cLive ;-) (Prior) on Jan 03, 2004 at 18:46 UTC
    A few things off the top of my head. Use
    conf->load();
    to explicitly call the method without ambiguity.

    If you're under mod_perl, my %conf will cause you no end of trouble if you try to declare it globally.

    Adding in use warnings might give you an extra pointer or two.

    Errr, what else? I assume the path to conf.pm can be found in @INC ? Kinda obvious, I know, but worth asking. If not, add

    use lib '/path/to/module/dir';
    before the use conf statement.

    .02

    cLive ;-)

Re: Module problem: can't locate object method
by TomDLux (Vicar) on Jan 03, 2004 at 15:22 UTC

    Try using the conf::new() conf->new() form. The other way around, as you have it, is generally discouraged.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      A reply falls below the community's threshold of quality. You may see it by logging in.