Can't locate object method "new" via package

S

smilesonisamal

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
 
G

George Mpouras

# try


use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
use MyModule;
....
 
J

Jürgen Exner

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
 
R

Rainer Weikusat

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

poornima lokhande

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"
 
P

poornima lokhande

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"
 
R

Rainer Weikusat

poornima lokhande said:
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.
 
P

poornima lokhande

Hello,

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


-Poornima
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top