$mytest = new Test(); $mytest->name('BABA'); $mytest->condition('TYPE1')->value('whatever'); $mytest->special->do_something; $mytest->special->condition('TYPE2')->value('other'); #### package Test; @ISA = ("Condition"); #constructor sub new { my ($class) = @_; my $self = { _name => undef, _condition => undef, }; bless $self,$class; return $self; }; #accessors sub condition { my ($self,$condition) = @_; $self->{_condition} = new Condition() if defined($condition); return $self->{_condition}; }; sub name { my ($self,$name) = @_; $self->{_name} = $name if defined($name); return $self->{_name}; }; package Condition; #constructor sub new { my ($class) = @_; my $self = { _value => undef, _list => undef, }; bless $self,$class; return $self; }; sub value { my ($self,$value) = @_; $self->{_value} = $value if defined($value); return $self->{_value}; }; sub list { my $self = shift; my @list = @_; $self->{_list} = {@list} if defined(@list); return @$self->{_list}; }; #### sub condition { my ($self,$condition) = @_; $self->{_condition} = new Condition() if defined($condition); return $self->{_condition}; };