#File Tree.pm, module for class Tree
package Tree;
sub new {
	my($type) = $_[0];     
	my($self) = {};     
	$self->{'root'} = $_[1];    
	bless($self, $type);     
	return($self);
}

sub tellroot {
	my($self)=$_[0];
	print "Root is $self->{'root'}.\n";
}

sub cruisetree {
	my($self) = $_[0];	#Find yourself
	#*** Now call method onedir with self->onedir, NEVER &onedir ***
	$self->onedir($self->{'root'});	#note called with instance
}

sub onedir {
	my($self) = $_[0];	#Find yourself
	my($dirname) = $_[1];	#Directory passed in

	#*** Below this point there's nothing OOP, EXCEPT ***
	#*** EXCEPT for the line commented %%%% O O P %%%% ***
	opendir(DIR, $dirname);
	my(@Names) = readdir(DIR);
	closedir(DIR);

	# Blow off possible trailing backslash before appending one.
	# Don't want 2 consecutive backslashes.
	if($dirname =~ /(.*)\\$/)
	{$dirname = $1;}

	# Loop thru directory, handle files and directories
	my($Name);
	foreach $Name (@Names) {
		chomp($Name);
		my($Path) = "$dirname\\$Name";
		if( -d $Path ) {	# if path represents a directory
			if(($Name ne "..") && ($Name ne ".")) {
				print "Directory $Path...\n";
				$self->onedir($Path);	#%%%% O O P %%%%
			}
		} else {	# if path represents a file
			print "	File $Path\n"
		}
	}
	return;
}

return(1);	#package files must always return 1.

