#!/usr/bin/perl
# This needs to be stackless, because thinglists are set up as part of
# object creation, and the stack often has a caller on it who owns the
# object, but not the object's contents list or whatever.
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;

	# If a parameter is passed, only allow running by the new
	# method of this object's parent.
	if (@_) {
		require Mooix::CallStack;
		import Mooix::CallStack;
		if (! Mooix::CallStack::calledby($this->parent, "new")) {
			$this->croak("invalid caller");
		}
	}
	
	#$this->super(@_) || $this->croak("super failed");
	
	if ($_{onchange}) {
		$this->onchange($_{onchange});
	}
	
	unless ($this->defines('list')) {
		# Start the list off empty.
		$this->list("");

		# It needs to be sticky since it contains a list of references.
		my $mode=01644;
		if ($_{unprotected}) {
			$mode=01664;
		}
		chmod($mode, $this->fieldfile("list")) or
			$this->croak("chmod list");
	}
		
	return $this;
}
