# plugin which recurses through directories processing
# each file it finds

package ArcPlug;

use util;
use BasPlug;
use plugin;
use arcinfo;

BEGIN {
    @ISA = ('BasPlug');
}

sub new {
    my ($class) = @_;
    my $self = new BasPlug ();

    return bless $self, $class;
}

# return 1 if this class might recurse using $pluginfo
sub is_recursive {
    my $self = shift (@_);

    return 1;
}

# return 1 if processed, 0 if not processed
# Note that $base_dir might be "" and that $file might 
# include directories
sub read {
    my $self = shift (@_);
    ($pluginfo, $base_dir, $file, $metadata, $processor) = @_;

    # see if this has a archives information file within it
    $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");

    if (-e $archive_info_filename) {

	# read in the archives information file
	my $archive_info = new arcinfo ();
	$archive_info->load_info ($archive_info_filename);
	
	my $file_list [5~= $archive_info->get_file_list();

	# process each file
	foreach $subfile (@$file_list) {
	    # note: metadata is not carried on to the next level
	    my $tmp = &util::filename_cat ($file, $subfile->[0]);
	    next if $tmp eq $file;
	    &plugin::read ($pluginfo, $base_dir, $tmp, {}, $processor);
	}
	
	# all books have been processed so need to output classifications
	# to infodb - note that at present you have to import before building
	if (defined $processor->{'mode'} && $processor->{'mode'} eq 'infodb') {
	    print STDERR "ArcPlug: Adding classifications to infodb\n";
	    $processor->process('classifications');
	}

	return 1;
    }

    # wasn't an archives directory, someone else will have to process it
    return 0;
}

1;
