#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	
	# Make sure that this command is not spoofed, just in case.
        if ($_{avatar} != $this) {
		fail "No!"; 
	}
	
	my $object=$_{direct_object} or $this->usage("bad direct object");
	my $field=$_{field} or $this->usage("bad field");
	my $val=$_{quote};

	my @vals;
	if (exists $_{number}) {
		my $index=$_{number};
		@vals=$object->$field;
		splice @vals, $index - 1, 1; # perl arrays are 0-based
	}
	my $error;

	my @params;
	if (@vals) {
		push @params, map { (value => $_) } @vals;
	}
	else {
		push @params, unset => 1;
	}

	my ($stat, $msg) = $this->safechange(
		object => $object,
		field => $field,
		@params
	);

	
	if (! $stat) {
		fail $msg;
	}
	else {
		$_{session}->write("Unset.");
	}
}
