package TSV::Writer;

use IO::File;

use strict;

sub new {
	my $package = shift;
	my $file = shift;
	unless (ref $file) {
		$file = IO::File->new($file, "w") ||
			die "cannot create file `$file'";
	}
	my $self = bless {
		file => $file,
	}, $package;
}

sub write {
	my $self = shift;
	my $row = shift;

	unless (defined $row) {
		$self->close;
		return;
	}

	my $line = (join "\t", @$row) . "\n";
	my $fh = $self->{file};

	print $fh $line;

	# TODO escaping
}

sub close {
	my $self = shift;
	$self->{file}->close;
}

1
