#!/usr/bin/perl
# Show what's in the portfolio.
#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 $pobj=$this;
	if (ref $_{direct_object}) {
		$pobj=$_{direct_object};
	}
	if (! ref $pobj->portfolio) {
		fail "No portfolio.";
	}

	my @pobjs = $pobj->portfolio->list;
	my @refstrings = $this->refstring(@pobjs);
	
	my @ret;
	my $maxlen=0;
	for (my $x = 0; $x < @pobjs; $x++) {
		my $obj=$pobjs[$x];
		my $name=$obj->name;
		if ($maxlen < length $name) {
			$maxlen=length $name;
		}
		push @ret, [ $name, "($refstrings[$x])" ];
	}
	@ret = map { "\t".$_->[0].(' ' x (2 + $maxlen - length($_->[0]))).$_->[1] } @ret;
	if (@ret) {
		$_{session}->page("The portfolio:", @ret);
	}
	else {
		$_{session}->page("The portfolio is empty.");
	}
}
