package GenObj; # the following methods can be generated # automatically with one of the Class:: # modules... # these are the EXPECTED inherited methods # of GenObj objects sub set_name { $_[0]{name} = $_[1] } sub get_name { $_[0]{name} } sub set_age { $_[0]{age} = $_[1] } sub get_age { $_[0]{age} } my $CHILD = 'a'; sub new { no strict 'refs'; # naughty things transpire my $class = shift; my $obj = bless {}, "${class}::$CHILD"; @{"${class}::${CHILD}::ISA"} = ($class); for (map s/^-//, @_) { *{"${class}::${CHILD}::get_$_"} = \&{"${class}::Sub::get_$_"}; *{"${class}::${CHILD}::set_$_"} = \&{"${class}::Sub::set_$_"}; } return $obj; ); package GenObj::Sub; # these are the specialized methods # to be inherited on demand sub set_name { $_[0]{name} = condense($_[1]) } sub get_name { expand($_[0]{name}) } sub set_age { $_[0]{age} = age2sec($_[1]) } sub get_age { sec2age($_[0]{age}) } # these are some utility functions # as called above sub condense; sub expand; sub age2sec; sub sec2age; 1;