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);
	}
}

sub receive {
	my ($self, $message, $peer) = @_;
	# what now?
}

sub set {
	my ($self, $property, $value) = @_;
	#TODO ensure it is a valid property
	$self->{$property} = $value;
	$self->send(["property_change", $property, $value]);
	#TODO - use an object for the message? so it can be serialized?
}

sub get {
	my ($self, $property) = @_;
	return $self->{$property};
}

1
