#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $avatar=$_{avatar} || $this->croak("what, no avatar?");

	# look in, on, under, etc.
	my $preposition=lc($_{do_preposition});
	if (length $preposition && $preposition ne 'at' && 
 	    ! grep { $_ eq $preposition } $this->valid_prepositions) {
                fail "Nothing there.";
        }
	
	my $msg='look';
	if (! $this->closed || $this->transparent) {
		my @contents;
		foreach ($this->contents->list) {
			if (! $_->hidden) {
				push @contents, $_;
			}
			elsif ($_->defines("detail")) {
				$_{details} .= " ".$_->detail;
			}
		}

		# The contents of some containers are visible to just plain
		# look.
		foreach (@contents) {
			my @visi = $_->visiblecontents;
			if (@visi) {
				push @contents, @visi;
			}
		}
		
		# Don't bother if the avatar is the only contents, since that
		# looks silly (and it'd gets the 'is/are' grammar wrong, too.
		if (@contents && (@contents > 1 || $contents[0] != $avatar)) {			
			# This can be used for '$contents $are here.' as a
			# message, getting the number of the noun right.
			$_{are}=(@contents > 1) ? 'are' : 'is';
			$_{contents}=$avatar->prettylist(@contents);
			$msg='look_contents';
		}
	}
	elsif ($this->closed) {
		$msg='look_closed';
	}
	
	$this->msg($msg, %_);
}
