| Class-Classgen-classgen documentation | Contained in the Class-Classgen-classgen distribution. |
Creature - base class for Creature::Bird and Creature::Dog (/examples).
Example showing inheritance.
Name: <your name here>
email: <your email address here>
Copyright (c) 2000, <your name here>. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
| Class-Classgen-classgen documentation | Contained in the Class-Classgen-classgen distribution. |
# --- Generated by classgen 3.0 on Mon Mär 20 22:10:10 MET 2000 --- ;# --- created 18.3.2000 by Michael Schlueter -------------------- ;# ;# a Creture is the base class for other individuals ;# ;# --------------------------------------------------------------- ; package Creature; use strict; ; sub new { my $self = shift; my $type = ref($self)||$self; # instance-variables: my $name; #somecreaturesaregivenaname my $pos; #theactualpositionofthiscreature $self=bless { _name => $name, _pos => $pos, }, $type; #$self->inherit_from($self->your_base::new()); return $self; } # --- methods specific for this class --------------------- sub specific { my ($self) = @_; } sub breath { my ($self) = @_; # to be implemented yet } sub move { my ($self, $pos) = @_;specific $self->set_pos($pos); # just a simple thing } sub make_noise { my ($self, $noise) = @_; print $self->get_name(), ": $noise\n"; } sub meet { my ($self, $creature) = @_; # somewhat lazy, no class check made here $self->set_pos( $creature->get_pos() ); } # --- inheritance methode ----------------------------------- sub inherit_from { my ($self, $base_blessed) = @_; my @l = keys %$base_blessed; foreach (@l) { $self->{$_} = $base_blessed->{$_}; } } # --- accessor methods ----------------------------------- sub get_name { my ($self) = @_; $self->{_name}; } sub get_pos { my ($self) = @_; $self->{_pos}; } # --- manipulator methods -------------------------------- sub clear_name { my ($self) = @_; my $v = $self->set_name(undef); } sub clear_pos { my ($self) = @_; my $v = $self->set_pos(undef); } sub set_name { my ($self, $value) = @_; $self->{_name} = $value; } sub set_pos { my ($self, $value) = @_; $self->{_pos} = $value; } 1; __END__