--- /dev/null
+package WebPAC::Input::TSV;
+
+use warnings;
+use strict;
+
+use WebPAC::Input;
+use base qw/WebPAC::Common/;
+
+use Encode;
+use Data::Dump qw/dump/;
+
+=head1 NAME
+
+WebPAC::Input::TSV - tab separated values
+
+=cut
+
+=head1 FUNCTIONS
+
+=head2 new
+
+ my $input = new WebPAC::Input::TSV(
+ path => '/path/to/records.tsv',
+ );
+
+=back
+
+Default encoding of input file is C<utf-8>
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless($self, $class);
+
+ my $arg = {@_};
+
+ my $log = $self->_get_logger();
+
+ open( my $fh, '<:raw', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");
+
+ $self->{size} = 0;
+
+ while ( my $line = <$fh> ) {
+
+ my $rec;
+ $rec->{'000'} = [ ++$self->{size} ];
+
+ my $col = 'A';
+ $rec->{ $col++ } = Encode::decode_utf8( $_ ) foreach split(/\t/,$line);
+
+ push @{ $self->{_rec} }, $rec;
+
+ };
+
+ $log->debug("loaded ", $self->size, " records");
+
+ $self ? return $self : return undef;
+}
+
+=head2 fetch_rec
+
+Return record with ID C<$mfn> from database
+
+ my $rec = $input->fetch_rec( $mfn, $filter_coderef );
+
+=cut
+
+sub fetch_rec {
+ my ( $self, $mfn, $filter_coderef ) = @_;
+
+ return $self->{_rec}->[$mfn-1];
+}
+
+
+=head2 size
+
+Return number of records in database
+
+ my $size = $input->size;
+
+=cut
+
+sub size {
+ my $self = shift;
+ return $self->{size};
+}
+
+=head1 AUTHOR
+
+Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2010 Dobrica Pavlinusic, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of WebPAC::Input::TSV
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use lib 'lib';
+
+use Test::More tests => 63;
+
+BEGIN {
+use_ok( 'WebPAC::Test' );
+use_ok( 'WebPAC::Input' );
+use_ok( 'Encode' );
+use_ok( 'Devel::Peek' );
+}
+
+my $module = 'WebPAC::Input::TSV';
+diag "testing with $module";
+
+ok(my $input = new WebPAC::Input(
+ module => $module,
+ no_progress_bar => 1,
+ %LOG
+), "new");
+
+ok(my $db = $input->open(
+ path => "$abs_path/data/records-utf8.tsv"
+), "open");
+ok(my $size = $input->size, "size");
+cmp_ok( $size, '==', 11, 'size ok' );
+
+foreach my $mfn ( 1 ... $size ) {
+ my $rec = $input->fetch;
+ ok($rec, "fetch $mfn");
+ cmp_ok($rec->{'000'}->[0], '==', $mfn, 'has mfn');
+ cmp_ok($input->pos, '==', $mfn, "pos $mfn");
+
+ ok( my $txt = $rec->{'E'}, 'E' );
+ diag Dump( $txt ) if $debug;
+ ok( Encode::is_utf8( $txt, 1 ), 'utf8' );
+ diag "rec: ", dump($rec), "\n" if $debug;
+}
+