S
Stephan Mann
Hi!
I need to create a double linked tree so I want to use objects and
therefore read the Class::Struct manual and the Perl FAQ entry. One
thing I can't figure out though is how to store a object reference.
The following code works, and stores references in the childs hash:
use strict;
use warnings;
use Data:
umper;
use Class::Struct qw(struct);
struct FooBar => {
foo => '$',
bar => '$',
parent => 'FooBar',
childs => '%',
};
my $aaa = new FooBar(foo => "aaa", bar => "AAA");
my $bbb = new FooBar(foo => "bbb", bar => "BBB");
$bbb->parent($aaa);
$aaa->childs("bbb" => \$bbb);
print Dumper($aaa);
print Dumper($bbb);
print ${$aaa->childs("bbb")}->foo, "\n";
print $bbb->parent->foo, "\n";
According to the manual, I should be able to define
parent => '*FooBar'
and store a object reference in it. But I then can't assign a value any
longer. Both
$bbb->parent($aaa);
$bbb->parent(\$aaa);
give me a "parent argument is wrong class" error. So how do I store a
object reference in a struct?!
tia, stephan
I need to create a double linked tree so I want to use objects and
therefore read the Class::Struct manual and the Perl FAQ entry. One
thing I can't figure out though is how to store a object reference.
The following code works, and stores references in the childs hash:
use strict;
use warnings;
use Data:
use Class::Struct qw(struct);
struct FooBar => {
foo => '$',
bar => '$',
parent => 'FooBar',
childs => '%',
};
my $aaa = new FooBar(foo => "aaa", bar => "AAA");
my $bbb = new FooBar(foo => "bbb", bar => "BBB");
$bbb->parent($aaa);
$aaa->childs("bbb" => \$bbb);
print Dumper($aaa);
print Dumper($bbb);
print ${$aaa->childs("bbb")}->foo, "\n";
print $bbb->parent->foo, "\n";
According to the manual, I should be able to define
parent => '*FooBar'
and store a object reference in it. But I then can't assign a value any
longer. Both
$bbb->parent($aaa);
$bbb->parent(\$aaa);
give me a "parent argument is wrong class" error. So how do I store a
object reference in a struct?!
tia, stephan