Class method call fails - "unblessed reference"

Discussion in 'Perl Misc' started by Gunnar Strand, Jun 15, 2004.

  1. 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
    Gunnar Strand, Jun 15, 2004
    #1
    1. Advertising

  2. Gunnar Strand

    Anno Siegel Guest

    Gunnar Strand <> wrote in comp.lang.perl.misc:
    > 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
    Anno Siegel, Jun 15, 2004
    #2
    1. Advertising

  3. Anno Siegel wrote:
    > Gunnar Strand <> wrote in comp.lang.perl.misc:
    >
    >>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


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

    Cheers,

    /Gunnar
    Gunnar Strand, Jun 16, 2004
    #3
    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. Ian
    Replies:
    2
    Views:
    344
    Ulrich Petri
    Sep 6, 2003
  2. Pawel_Iks
    Replies:
    3
    Views:
    532
    terminator
    Jul 31, 2007
  3. aidy
    Replies:
    5
    Views:
    237
    Marcin Mielżyński
    Jun 4, 2006
  4. Clint Olsen
    Replies:
    3
    Views:
    242
    Malcolm Dew-Jones
    Dec 18, 2003
  5. Justin C

    Unblessed reference.

    Justin C, Dec 8, 2009, in forum: Perl Misc
    Replies:
    8
    Views:
    188
Loading...

Share This Page