--- Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/27 05:07:01 178 +++ Webpacus/lib/Webpacus/Model/WebPAC.pm 2005/11/27 15:14:54 179 @@ -69,7 +69,7 @@ $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); # save config parametars in object - foreach my $f (qw/db_path template_path hits_on_page/) { + foreach my $f (qw/db_path template_path hits_on_page webpac_encoding out_encoding/) { $self->{$f} = $c->config->{hyperestraier}->{$f} || $c->config->{webpac}->{$f}; $log->debug("self->{$f} = " . $self->{$f}); @@ -109,26 +109,6 @@ } -=head2 iconv_on_save - - my $out = $m->iconv_on_save( $content ); - -Convert data saved to disk in Webpac encoding. - -=cut - -sub iconv_on_save { - my $self = shift; - my $content = shift || return; - - $self->{iconv_save} ||= new Text::Iconv( - $self->config->{webpac}->{out_encoding}, - $self->config->{webpac}->{webpac_encoding}, - ); - - return $self->{iconv_save}->convert( $content ); -} - =head2 search @@ -277,7 +257,7 @@ $m->save_html( '/full/path/to/file', $content ); -It will use C to convert content encoding back to +It will use C to convert content encoding back to Webpac codepage, recode JavaScript Unicode entities (%u1234), strip extra newlines at beginning and end, and save to C and if that succeeds, just rename @@ -296,17 +276,19 @@ $content =~ s/^[\n\r]+//s; $content =~ s/[\n\r]+$/\n/s; - my $iconv_on_save = new Text::Iconv( - $self->config->{webpac}->{out_encoding}, - $self->config->{webpac}->{webpac_encoding}, + my ($from, $to) = ( + $self->{out_encoding}, + $self->{webpac_encoding}, ); - $self->{log}->debug( "content BEFORE : $content" ); - no utf8; - $content = $iconv_on_save->convert( $content ) || die "no content?"; - $self->{log}->debug( "content AFTER: $content" ); + $self->{log}->debug("using iconv to convert from $from to $to encoding"); + + my $iconv_on_save = new Text::Iconv($from, $to) + || $self->{log}->fatal("can't create iconv for saving"); + + $content = $iconv_on_save->convert( $content ) || die "no content?"; - write_file($path . '.new', $content) || die "can't save ${path}.new $!"; + write_file($path . '.new', {binmode => ':raw' }, $content) || die "can't save ${path}.new $!"; rename $path . '.new', $path || die "can't rename to $path: $!"; } @@ -325,7 +307,7 @@ die "no path?" unless ($path); - my $content = read_file($path) || die "can't read $path: $!"; + my $content = read_file($path, {binmode => ':raw' }) || die "can't read $path: $!"; #$content = $q->escapeHTML($iconv_utf8->convert($content)); $content = $self->{iconv}->convert($content);