#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $entry=$_{quote};
	my $avatar=$_{avatar};
	my $session=$_{session};
	
	$entry=~s/[^\w\s]//g;
	if (! length $entry) {
		fail "You should supply a word to read in quotes, like: read about \"love\" in ".$this->name.".";
	}
	
	# Only show entry if the avatar manages to read it.
	if (grep { $_ == $avatar } $this->msg('read', %_)) {
		my $pid = open(DICT, "-|");
		if ($pid) {
			my @lines=<DICT>;
			close DICT;
			if (! @lines) {
				fail "The words just won't come clear.";
			}
			$session->page(@lines);
		}
		else {
			# NB: dict currently only looks at the last -d,
			# so multiple ones cannot be used.
			my @dbopts = map { ("-d", $_) }
			             grep length,
			             map { s/[^\w\s\*]//g; $_ }
			             $this->database;
			exec "dict", @dbopts, $entry;
		}
	}
}
