#!/usr/bin/perl
use Mooix::Thing;

my %fields;

sub getfields {
	my $this=shift;
	my $inherit=shift;
	
	opendir (THINGDIR, $this->[0]) || $this->croak("opendir");
	map { $fields{$_} = 1 } grep { $_ ne '.' and $_ ne '..' } readdir THINGDIR;
	closedir THINGDIR;
	getfields($this->parent, $inherit) if $inherit && ref $this->parent;
}

run sub {
	my $this=shift;
	%_=@_;
	my $inherit = exists $_{inherit} ? $_{inherit} : 1;
	
	getfields($this, $inherit);
	return keys %fields;
}
