#!/usr/bin/perl
#use Mooix::Thing;

eval "use Lingua::EN::Inflect q{PL}";
if ($@) {
	eval { sub PL { return $_[0]."s" } }
}

run sub {
	my $this=shift;
	%_=@_;
	my $obj=$_{direct_object};
	my $command=$_{quote};
	my $cmdfile="$command.cmd";
	
	# Make sure that this command is not spoofed, just in case.
        if ($_{avatar} != $this) {
		fail "No!"; 
	}
	
	if (length $obj->fieldfile($cmdfile)) {
		fail "There is already a command \"$command\" defined on that object.";
	}
	my ($ret1, $msg1, $ret2, $msg2) = $this->safechange(
		object => $obj,
		field => $cmdfile,
		value => "verb, direct_object(this)(nearby) : generic",

		object => $obj,
		field => $command.".msg",
		value => "see: \$this ".PL($command),
	);
	if (! $ret1) {
		fail $msg1;
	}
	elsif (! $ret2) {
		fail $msg2;
	}
	$_{session}->write("Command added. Set $command.msg to customize.");
}
