1 package WebPAC::Input::CSV;
7 use base qw/WebPAC::Common/;
11 use Data::Dump qw/dump/;
15 WebPAC::Input::CSV - support for CSV Export Format
19 our $VERSION = '0.02';
25 Returns new low-level input API object
27 my $input = new WebPAC::Input::CSV(
28 path => '/path/to/records.csv',
41 Default encoding of input file is C<utf-8>
52 my $log = $self->_get_logger();
54 open( my $fh, '<:raw', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");
56 my $csv = Text::CSV->new({ binary => 1 });
61 my $line = $csv->getline( $fh );
64 $log->logdie( "can't parse CSV file ", $csv->error_diag ) unless $line;
67 $rec->{'000'} = [ ++$self->{size} ];
70 $rec->{ $col++ } = Encode::decode_utf8( $_ ) foreach @$line;
72 push @{ $self->{_rec} }, $rec;
76 $log->debug("loaded ", $self->size, " records");
78 $self ? return $self : return undef;
83 Return record with ID C<$mfn> from database
85 my $rec = $input->fetch_rec( $mfn, $filter_coderef );
90 my ( $self, $mfn, $filter_coderef ) = @_;
92 return $self->{_rec}->[$mfn-1];
98 Return number of records in database
100 my $size = $input->size;
106 return $self->{size};
111 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
113 =head1 COPYRIGHT & LICENSE
115 Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
117 This program is free software; you can redistribute it and/or modify it
118 under the same terms as Perl itself.
122 1; # End of WebPAC::Input::CSV