package obj;

use strict; use warnings;

use Carp;
use util;

our $AUTOLOAD;

sub new {
	my ($pkg, @args) = @_;
	my $this = {keys=>[], @args};
	bless $this, $pkg;
	for (my $i = 0; $i<@args; $i+=2) {
		push @{$this->keys}, $args[$i];
	}
#	$this->SUPER::new(%args);
	return $this;
}

sub AUTOLOAD {
	my ($this, @args) = @_;
	my $member = $AUTOLOAD;
	my $pkg = 'main';
	if ($member =~ s/(.*):://) {
		$pkg = $1;
	}

	if (my $sub = $pkg->can($member)) {
		return $this->$sub(@args);
	} elsif ($this->isa("HASH") && exists $this->{$member}) {
		if (@args == 0) {
			return $this->{$member};
		} elsif (@args == 1) {
			($this->{$member}) = @args;
			return $this;
		}
	}
	for ($this, @args) {
		($_ = "$_") =~ s/=.*//;
	}
	die "unknown: $this $member @args\n";
}

sub DESTROY {}

1
