Can't locate object method "new" via package

Discussion in 'Perl Misc' started by smilesonisamal, Dec 20, 2013.

  1. Hi all,
    I am finding an issue in perl v5.10.1. I am getting the following issue.
    I have added the path in @INC in my script.

    Error : Can't locate object method "new" via package

    Can anybody help me in this regard?

    Regards
    Pradeep
     
    smilesonisamal, Dec 20, 2013
    #1
    1. Advertisements

  2. # try


    use strict;
    use warnings;
    use FindBin;
    use lib $FindBin::Bin;
    use MyModule;
    ....
     
    George Mpouras, Dec 20, 2013
    #2
    1. Advertisements

  3. As has been customary for decades please post a small, self-contained
    program that exhibits the problem and that other people can run and
    test.

    jue
     
    Jürgen Exner, Dec 20, 2013
    #3
  4. This statement is a little cryptic. Let's assume that the package name
    is Arthur. In this case, the error message

    Error : Can't locate object method "new" via package Arthur
    (perhaps you forgot to load Arthur)

    means there's a call to a method named new (usually a constructor)
    using Arthur as invocant, eg

    my $dent = Arthur->new();

    but the symbol table of the package Arthur didn't contain an entry for a
    subroutine named new. Usually, the cause is just what the error message
    suggests: It wasn't loaded, a statement a la

    use Arthur;

    is missing. You should provide some more information about your problem
    if that wasn't the cause.
     
    Rainer Weikusat, Dec 20, 2013
    #4
  5. Hello,

    I am having a similar issue. Unsure if I should start a topic or can continue here. Until now, I was using perl 5.12 and my code was working fine. Now we upgraded to fedora19 and perl 5.16, my code errors saying
    Can't locate object method "new" via package "MyModule" .
    I have been using the inheritance concept in MyMdule to use a common constructor from a parent class "ParentModule".

    package ParentModule;
    use SomeModule::API;
    our @ISA = qw(Exporter SomeModule::API);

    sub new{
    my $class = shift;
    my %settings;
    my $self = $class->SUPER::new(\%settings);
    bless $self, $class;
    return $self;
    }

    package MyModule;
    our @ISA = qw(Exporter NetMRI::BVT::BVTCommon);

    #use parent constructor



    test.pl #my script to test the setup
    use MyModule;

    my $obj = MyModule->new(@input);
    $obj->$method;


    Can anyone please help with what has changed from perl 5.12 to 5.16 thats causing this error. Or what change can I make in order to get this working.
    I have even tried writing a constructor in MyModule using SUPER::new, but get the error saying
    Can't locate object method "new" via package "MyModule::SUPER"
     
    poornima lokhande, Jun 5, 2014
    #5
  6. Hello,

    I am having a similar issue. Unsure if I should start a topic or can continue here. Until now, I was using perl 5.12 and my code was working fine. Now we upgraded to fedora19 and perl 5.16, my code errors saying
    Can't locate object method "new" via package "MyModule" .
    I have been using the inheritance concept in MyMdule to use a common constructor from a parent class "ParentModule".

    package ParentModule;
    use SomeModule::API;
    our @ISA = qw(Exporter SomeModule::API);

    sub new{
    my $class = shift;
    my %settings;
    my $self = $class->SUPER::new(\%settings);
    bless $self, $class;
    return $self;
    }

    package MyModule;
    our @ISA = qw(Exporter ParentModule);

    #use parent constructor

    sub method{
    .....

    }


    test.pl #my script to test the setup
    use MyModule;

    my $obj = MyModule->new(@input);
    $obj->method;


    Can anyone please help with what has changed from perl 5.12 to 5.16 thats causing this error. Or what change can I make in order to get this working.
    I have even tried writing a constructor in MyModule using SUPER::new, but get the error saying
    Can't locate object method "new" via package "MyModule::SUPER"
     
    poornima lokhande, Jun 5, 2014
    #6
  7. Since MyModule isn't derived from ParentMode, there's no way it could
    possibly inherit ParentModule methods.
     
    Rainer Weikusat, Jun 5, 2014
    #7
  8. Hello,

    Please take a look at the new piece of code. The deriving of the ParentModule was missed in my previous post.


    -Poornima
     
    poornima lokhande, Jun 8, 2014
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.