Class method call fails - "unblessed reference"

G

Gunnar Strand

Hi,

I am trying to write test cases using Test::Unit, and one of the
test object starts like this:

1 package Test::TestProfileSettings;
2
3 use Cmpm::profile::Settings;
4 use Test::Unit::TestCase;
5 use base qw( Test::Unit::TestCase );
6
7 sub new {
8 my $class = shift;
9 my $self = $class -> SUPER::new( @_ );
10 return $self;
11 }
12
13 sub test_settings1 {
14 my $self = shift;
15 my $s = Cmpm::profile::Settings -> new;
16 print STDERR "\$s = $s\n";
...more code below, but this is the only method...

I use a TestSuite to run several test objects. If I run one certain
test case before the one above, then perl complains:

Test/TestProfileSettings.pm:15 - test_settings1(Test::TestProfileSettings)
Can't call method "new" on unblessed reference

It seems odd to me that perl would consider the class name to be
an unblessed reference. If the test cases run in a different order,
then all passes without any errors. Has anyone seen this before,
and has any idea on what could be wrong?

Kind Regards,

/Gunnar
 
A

Anno Siegel

Gunnar Strand said:
Hi,

I am trying to write test cases using Test::Unit, and one of the
test object starts like this:

1 package Test::TestProfileSettings;
2
3 use Cmpm::profile::Settings;
4 use Test::Unit::TestCase;
5 use base qw( Test::Unit::TestCase );
6
7 sub new {
8 my $class = shift;
9 my $self = $class -> SUPER::new( @_ );
10 return $self;
11 }
12
13 sub test_settings1 {
14 my $self = shift;
15 my $s = Cmpm::profile::Settings -> new;
16 print STDERR "\$s = $s\n";
...more code below, but this is the only method...

I use a TestSuite to run several test objects. If I run one certain
test case before the one above, then perl complains:

Test/TestProfileSettings.pm:15 - test_settings1(Test::TestProfileSettings)
Can't call method "new" on unblessed reference

It seems odd to me that perl would consider the class name to be
an unblessed reference. If the test cases run in a different order,
then all passes without any errors. Has anyone seen this before,
and has any idea on what could be wrong?

This looks as if there was a sub named Settings in package Cmpm::profile.
If that sub returned an unblessed reference, you would get the behavior
you describe. Is that a possibility?

Anno
 
G

Gunnar Strand

Anno said:
This looks as if there was a sub named Settings in package Cmpm::profile.
If that sub returned an unblessed reference, you would get the behavior
you describe. Is that a possibility?

Anno

Yes, you are correct. A thousands thanks, Anno! I have been struggling
with this problem for some time.

Cheers,

/Gunnar
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top