#!/usr/bin/perl
#use Mooix::Thing;
#use Mooix::Root;
run sub {
	my $this=shift;
	%_=@_;
	my $find = lc($_{quote});

	my @results;
	foreach $entry ($this->exchange->list) {
		next unless $entry->listed;
		
		my $location = $entry->location;
		my $top = 0;
		until ($top && ref $location) {
			if ($location->isa($Mooix::Root->abstract->avatar)) {
				$top=1;
			}
			elsif ($location->isa($Mooix::Root->concrete->room) &&
			       !($location->isa($Mooix::Root->concrete->furniture))) {
				$top=1;
			}
			else {
				$location=$location->location;
			}
		}

		if (length $find) {
			next if lc $location->name !~ /\Q$find\E/ &&
			        lc $entry->number  !~ /\Q$find\E/;
		}
	
		my $n=$location->prettyname;
		push @results, ucfirst($n).(" " x (30 - length $n))." ".
		               $entry->number;
	}
	
	if (! @results) {
		@results = "None";
	}
	else {
		unshift @results, "Name".(" " x (30 - length "Name"))." Number";
	}

	$this->msg('read', %_);
	$_{session}->page(@results ? @results : "Nothing.");
}
