#!/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} || $this->usage("bad direct object");
	my $field=$_{field} || '';
	my $session=$_{session} || $this->usage("bad session");
	my @contents=$object->safegetfield($field);
	
	# See if the field can be set. This is a trifle expensive, but
	# it beats running the editor and only then finding out that your
	# hard work can't be saved.
	my ($stat, $msg) = $this->safechange(
		object => $object,
		field => $field,
		(map {( value => $_ )} @contents),
	);
	
	if (! $stat) {
		fail $msg;
	}
	
	# Tell the session to start the edit. It will call edit_finish when
	# done.
	my $status = $session->edit(
		input => join("\n",@contents),
		hint => $object->name." ".$field,
		id => $object->id."->".$field,
	);

	if ($status) {
		$session->write("Edit in progress.");
	}
	else {
		fail "Edit failed.";
	}
}
