Can't locate object method "new" via package

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

  1. Guest

    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
    , Dec 20, 2013
    #1
    1. Advertising

  2. # try


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

  3. wrote:
    >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?


    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. writes:
    > 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?


    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. poornima lokhande <> writes:
    > 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;


    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GMI
    Replies:
    3
    Views:
    502
    Tad McClellan
    Jun 19, 2005
  2. Pam
    Replies:
    7
    Views:
    328
  3. Replies:
    1
    Views:
    423
    Bart Lateur
    Jun 1, 2007
  4. kj
    Replies:
    3
    Views:
    305
  5. Arindam
    Replies:
    10
    Views:
    519
    Justin C
    Jul 19, 2010
Loading...

Share This Page