r718@llin: dpavlin | 2006-06-26 17:37:28 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 26 Jun 2006 16:39:42 +0000 (16:39 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 26 Jun 2006 16:39:42 +0000 (16:39 +0000)
 remove Text::Iconv and use Encode

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@535 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Search/Estraier.pm

index 53043ea..61c0024 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 
 use Search::Estraier;
-use Text::Iconv;
+use Encode qw/from_to/;
 use Data::Dumper;
 
 =head1 NAME
@@ -13,11 +13,11 @@ WebPAC::Search::Estraier - search Hyper Estraier full text index
 
 =head1 VERSION
 
-Version 0.06
+Version 0.07
 
 =cut
 
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 
 =head1 SYNOPSIS
 
@@ -94,11 +94,8 @@ sub new {
        $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 @@ sub search {
        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 @@ sub search {
                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 @@ sub confess {
        }
 }
 
+=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<WebPAC::Common>, but without