--- trunk/lib/WebPAC/Search/Estraier.pm 2006/05/10 13:56:28 457 +++ trunk/lib/WebPAC/Search/Estraier.pm 2006/06/26 16:39:42 535 @@ -4,7 +4,7 @@ use strict; use Search::Estraier; -use Text::Iconv; +use Encode qw/from_to/; use Data::Dumper; =head1 NAME @@ -13,11 +13,11 @@ =head1 VERSION -Version 0.06 +Version 0.07 =cut -our $VERSION = '0.06'; +our $VERSION = '0.07'; =head1 SYNOPSIS @@ -94,11 +94,8 @@ $self->{db}->set_url($self->{'url'}); $self->{db}->set_auth($self->{'user'}, $self->{'passwd'}); - my $encoding = $self->{'encoding'} || 'ISO-8859-2'; - $log->info("using encoding $encoding"); - - $self->{'iconv'} = new Text::Iconv('UTF-8', $encoding) or - $log->die("can't create conversion from UTF-8 to $encoding"); + $self->{'encoding'} ||= 'ISO-8859-2'; + $log->info("using encoding ",$self->{encoding}); $self ? return $self : return undef; } @@ -153,12 +150,12 @@ if ( ref($args->{add_attr}) eq 'ARRAY' ) { $log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) ); map { - $cond->add_attr( $self->{iconv}->convert( $_ ) ); + $cond->add_attr( $self->convert( $_ ) ); $log->debug(" + $_"); } @{ $args->{add_attr} }; }; - $cond->set_phrase( $self->{iconv}->convert($q) ) if ($q); + $cond->set_phrase( $self->convert($q) ) if ($q); $cond->set_options( $args->{options} ) if ($args->{options}); $cond->set_order( $args->{order} ) if ($args->{order}); @@ -193,7 +190,7 @@ foreach my $attr (@{ $args->{get_attr} }) { my $val = $doc->attr( $attr ); #$log->debug("attr $attr = ", $val || 'undef'); - $hash->{$attr} = $self->{iconv}->convert( $val ) if (defined($val)); + $hash->{$attr} = $self->convert( $val ) if (defined($val)); } if ($hash) { @@ -235,6 +232,24 @@ } } +=head2 convert + +convert internal encoding to UTF-8 + + my $utf8 = $self->convert( $text ); + +=cut + +sub convert { + my $self = shift; + + my $text = shift || return; + + from_to($text, $self->{encoding}, 'UTF-8'); + return $text; +} + + =head2 _get_logger For compatibility with same method from L, but without