package A2B::Types;

use A2B::Table;
use IO::File;

use strict;
use vars qw(@ISA $ELEMENT_TYPE);

@ISA = qw(A2B::Table);

$ELEMENT_TYPE = "A2B::Type";

sub new {
	my $pkg = shift;
	my $self = $pkg->SUPER::new(fields => [qw(type extension)]);

	$self->load_mimetypes("/etc/a2b/mime.types");
	$self->load_mimetypes("/etc/mime.types");
#	use Data::Dumper;
#	print STDERR Dumper($self);
	
	return $self;
}

sub load_mimetypes {
	my ($self, $file) = @_;
	my $fh = IO::File->new($file) or
		die "cannot open $file";
	while (my $line = $fh->getline) {
		if (my ($type, $extensions) = $line =~ m{^(\S+/\S+)\s+(.*)}) {
			my @extensions = split /\s+/, $extensions;
			for my $extension (@extensions) {
				$self->add_row([$type, lc($extension)]);
			}
		}
	}
}

1
