Subject: | can't use the SUPER pseudo-class |
Class-InsideOut-1.06
Unfortunately, the following code doesn't work well. In short, the
field "parenttype" in this code is undef.
Of course, if the statement "$self->SUPER::new()" is replaced
with "TestA->new()", then the code works well.
However, in this case using the SUPER pseudo-class isn't suitable,
the use of "use base qw(TestA)" is meaningless at all. It's no
longer "inheritance".
package TestA;
use strict;
use warnings;
use Class::InsideOut qw( :std );
{
public type => my %type;
sub new {
my $class = shift;
my $self = ref $class || $class;
$self = register($self);
$type{id $self} = 'A';
return $self;
}
}
package TestB;
use strict;
use warnings;
use Class::InsideOut qw( :std );
use base qw(TestA);
use Smart::Comments;
{
public parenttype => my %parenttype;
public type => my %type;
sub new {
my $class = shift;
my $self = ref $class || $class;
$self = register($self);
my $testa = $self->SUPER::new(); # Must "$self->SUPER::new()"
be replaced with "TestA->new()" ?
$parenttype{id $self} = $testa->type();
$type{id $self} = 'B';
return $self;
}
}
package main;
use strict;
use warnings;
my $testb = TestB->new();
print $testb->parenttype(), "\n";
print $testb->type(), "\n";
__END__