#!/usr/bin/perl
#use Mooix::Thing;
#use Mooix::Root;
run sub {
	my $this=shift;
	%_=@_;
	my $oldversion=$_{oldversion} || $this->croak("missing oldversion");

	if (60 > $oldversion) {
		$this->create(id => "messagefilters",
		              parent => $Mooix::Root->abstract->filterlist,
                              owner => $this)
		      unless $this->defines("messagefilters");
	}
	
	if (52 > $oldversion) {
		# The permissions of the contents list used to be group
		# writable to allow any method to change it. But the
		# physics object changed that; remove the group write bit,
		# so that only the physics system can move things around.
		if ($this->contents && $this->contents->defines("list")) {
			$this->contents->setmode(field => 'list',
				mode => 1644);
		}
	}
	
	if (37 > $oldversion) {
		# Containers now track mass, and need to be updated to take
		# the mass of all of their contents into account.
		# First, make sure that any containers that are inside this
		# one have been upgraded, to make sure that their mass
		# value is correct. Then just sum the masses and save it.
		my $container=$Mooix::Root->concrete->container;
		my $mass=$this->basemass;
		
		foreach my $obj ($this->contents->list) {
			next unless ref $obj;
			if ($obj->isa($container)) {
				$obj->upgrade(@_, recursive => 1);
			}
			$mass+=$obj->mass;
		}
		$this->physics->changemass(
			object => $this,
			delta => ($mass - $this->mass)
		);
		# Make sure it is set, even if it is the same as inherited
		# value for now. Don't do this if called recurively, since
		# the stack wouldn't allow it.
		if (! $_{recursive}) {
			$this->_mass($mass);
		}
	}
	
	return $this->super(@_) unless $_{recursive};
}
