package VDR::Object;

use strict;
use warnings;
use base qw[ VDR ];

sub new 
{
	print STDERR "new Object: ".join(' ', @_)."\n";

	my $self = shift;
	my $name = shift;
	my $ref = ref($self) || $self;

	my $this = $ref->SUPER::new;
	$this->{_id} = $this->_initialize($name, @_);
	$this->{_methods} = [];

	no strict 'refs';
	${"VDR::$this->{_id}"} = $this;
	use strict 'refs';

	return $this;
}

sub get
{
	my $id = shift;

	no strict 'refs';
	my $ref = ${"VDR::$id"};
	use strict 'refs';

	return $ref;
}

sub _initialize
{
	my $this = shift;
	my $name = shift;

	$this->send_msg('C', $name, @_);
	return $this->recv_msg('c');
}

sub _automethods
{
	my $this = shift;
	push @{$this->{_methods}}, @_;
}

sub AUTOLOAD
{
	my $this = shift;

	our $AUTOLOAD;
	my $name = $AUTOLOAD;
	$name =~ s/.*://;

	if (grep { $_ eq $name } @{$this->{_methods}}) {
		$name =~ s{(?:^|_)([a-z])}{uc($1)}ge;
		$this->send_msg('M', $this, $name, @_);
	}
}

"this value intentionally left true";
