4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
305 |
|
|
306 |
Returns number of nodes in created tree. |
Returns number of nodes in created tree. |
307 |
|
|
308 |
|
There is also longer version if you want to recode your data charset |
309 |
|
into different one (probably UTF-8): |
310 |
|
|
311 |
|
$root->to_jsfind('/full/path/to/index/dir/','ISO-8859-2','UTF-8'); |
312 |
|
|
313 |
=cut |
=cut |
314 |
|
|
315 |
|
my $iconv; |
316 |
|
|
317 |
sub to_jsfind { |
sub to_jsfind { |
318 |
my $self = shift; |
my $self = shift; |
319 |
|
|
320 |
my $path = shift || confess "to_jsfind need path to your index!"; |
my $path = shift || confess "to_jsfind need path to your index!"; |
321 |
|
|
322 |
|
my ($from_cp,$to_cp) = @_; |
323 |
|
if ($from_cp && $to_cp) { |
324 |
|
$iconv = Text::Iconv->new($from_cp,$to_cp); |
325 |
|
} |
326 |
|
|
327 |
$path .= "/" if ($path =~ /\/$/); |
$path .= "/" if ($path =~ /\/$/); |
328 |
carp "create directory for index '$path': $!" if (! -w $path); |
carp "create directory for index '$path': $!" if (! -w $path); |
329 |
|
|
336 |
$_[0] cmp $_[1]; |
$_[0] cmp $_[1]; |
337 |
} |
} |
338 |
|
|
339 |
|
=head3 _recode |
340 |
|
|
341 |
|
This is internal function to recode charset. |
342 |
|
|
343 |
|
=cut |
344 |
|
|
345 |
|
sub _recode { |
346 |
|
my $self = shift; |
347 |
|
my $text = shift || return; |
348 |
|
|
349 |
|
if ($iconv) { |
350 |
|
return $iconv->convert($text) || $text; |
351 |
|
} else { |
352 |
|
return $text; |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
##################################################################### |
##################################################################### |
357 |
|
|
358 |
=head2 jsFind::Node methods |
=head2 jsFind::Node methods |
377 |
|
|
378 |
use Carp; |
use Carp; |
379 |
use File::Path; |
use File::Path; |
380 |
|
use Text::Iconv; |
381 |
|
|
382 |
|
use base 'jsFind'; |
383 |
|
|
384 |
my $KEYS = 0; |
my $KEYS = 0; |
385 |
my $DATA = 1; |
my $DATA = 1; |
777 |
open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!"; |
open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!"; |
778 |
open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!"; |
open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!"; |
779 |
|
|
780 |
print K $key_xml; |
print K $self->SUPER::_recode($key_xml); |
781 |
print D $data_xml; |
print D $self->SUPER::_recode($data_xml); |
782 |
|
|
783 |
close(K); |
close(K); |
784 |
close(D); |
close(D); |