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

	if (! ref $_{destination}) {
		$this->croak("destination required");
	}

	my @data=$this->data;
	return unless @data;
	
	my @s=$this->parse(
		destination => $_{destination},
		(map {( line => $_ )} @data),
	);

	# Check for problems and populate package object from data.
	my @err=$this->check(@s);
	if (@err) {
		foreach (@err) {
			$_{session}->write($_);
		}
		return;
	}

	# Separate out the first object, which is for this package and was
	# already used by check, above, and return the rest.
	my @ret;
	my ($object, $first);
	for (my $i=0; $i < @s; $i+=2) {
		if ($s[$i] eq 'object') {
			$object=$s[$i+1];
			$first=$object unless defined $first;
		}

		if ($object ne $first) {
			push @ret, $s[$i], $s[$i+1];
		}
	}
	return @ret;
}
