package Object; =pod This is a base class for objects. =cut sub new { my $pkg = shift; my $self = bless {}, $pkg; return $self; } sub add_listener { my ($self, $listener) = @_; $self->{__listeners}{$listener} = $listener; } sub remove_listener { my ($self, $listener) = @_; delete $self->{__listeners}{$listener}; } sub send { my ($self, $message) = @_; for my $listener (keys %{$self->{__listeners}}) { $listener->receive($message, $self); } } 1