force utf-8 encoding on all data comming from file
[webpac2] / lib / WebPAC / Input / CSV.pm
index 112b9f0..7dcf582 100644 (file)
@@ -7,6 +7,7 @@ use WebPAC::Input;
 use base qw/WebPAC::Common/;
 
 use Text::CSV;
+use Encode;
 use Data::Dump qw/dump/;
 
 =head1 NAME
@@ -15,7 +16,7 @@ WebPAC::Input::CSV - support for CSV Export Format
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 FUNCTIONS
 
@@ -50,7 +51,7 @@ sub new {
 
        my $log = $self->_get_logger();
 
-       open( my $fh, '<:encoding(utf-8)', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");
+       open( my $fh, '<:raw', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");
 
        my $csv = Text::CSV->new({ binary => 1 });
 
@@ -66,7 +67,7 @@ sub new {
                $rec->{'000'} = [ ++$self->{size} ];
 
                my $col = 'A';
-               $rec->{ $col++ } = $_ foreach @$line;
+               $rec->{ $col++ } = Encode::decode_utf8( $_ ) foreach @$line;
 
                push @{ $self->{_rec} }, $rec;
 
@@ -86,9 +87,7 @@ Return record with ID C<$mfn> from database
 =cut
 
 sub fetch_rec {
-       my $self = shift;
-
-       my ( $mfn, $filter_coderef ) = @_;
+       my ( $self, $mfn, $filter_coderef ) = @_;
 
        return $self->{_rec}->[$mfn-1];
 }