in reply to bless!!

If a constructor is inherited, it needs to bless into a class that is not its own. As in:
package CLASS_B; sub new { my $class = shift; # critical here bless { @_ }, $class; # blesses to maybe CLASS_A } package CLASS_A; @ISA = qw(CLASS_B); ... my $object = CLASS_A->new;
This calls, CLASS_A::new, which inherits to CLASS_B::new, which blesses the hashref into CLASS_A, not CLASS_B. Does that help?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: bless!!
by bakunin (Scribe) on Jan 17, 2004 at 23:14 UTC
    Thank you for pointing out inheritance merlyn!
    I saw something like this a few weeks ago... wish I remembered where exactly.
    package Class_A; sub new { ## the usual: my $class = shift; my $self = {}; bless $self, $class; } sub newB { my $self = {}; bless $self, 'Class_B'; }
    Does this ring any bells?