#!/usr/bin/perl
#use Mooix::Thing;
#use Mooix::Root;
run sub {
	my $this=shift;

	my @ret;
OBJ:	foreach my $obj (@_) {
		my $id = $obj->id;
		$id=~s/\/\.\//\//g; # remove "./" components
		
		# First look in avatars.
		foreach my $avatar ($Mooix::Root->system->sessionmanager->avatars->list) {
			next if $avatar == $this; # shorter in refpath below
			my $aid=$avatar->id;
			if ($id =~ /^\Q$aid\E((?:\/+|$).*)/) {
				push @ret, "~".$avatar->name.$1;
				next OBJ;
			}			
		}

		# Then the refpath.
		my @refpath = grep { ref $_ } map {
			if (/^\./) {
				$_ = Mooix::Thing->get($this->id."/$_");
			}
			elsif (/^\//) {
				$_ = Mooix::Thing->get($Mooix::Root->id."/$_");
			}
			$_;
		} $this->refpath;
		foreach my $r (@refpath) {
			my $rid=$r->id;
			$rid=~y/\//\//s;	# neaten up the path
			$rid=~s/(\/|\.)*$//;	# so the match works
			if ($id =~ /^\Q$rid\E\/(.*)/) {
				push @ret, $1;
				next OBJ;
			}
		}

		# No short reference available.
		push @ret, $id;
	}
		
	return map { "mooix:$_" } @ret;
}
