5 |
use warnings; |
use warnings; |
6 |
use HTML::Entities; |
use HTML::Entities; |
7 |
|
|
8 |
our $VERSION = '0.03'; |
our $VERSION = '0.04'; |
9 |
|
|
10 |
use Exporter 'import'; |
use Exporter 'import'; |
11 |
use Carp; |
use Carp; |
407 |
use Carp; |
use Carp; |
408 |
use File::Path; |
use File::Path; |
409 |
use Text::Iconv; |
use Text::Iconv; |
410 |
|
use POSIX; |
411 |
|
|
412 |
use base 'jsFind'; |
use base 'jsFind'; |
413 |
|
|
777 |
return $d; |
return $d; |
778 |
} |
} |
779 |
|
|
780 |
|
=head2 base62 |
781 |
|
|
782 |
|
Convert number to base62 (used for jsFind index filenames). |
783 |
|
|
784 |
|
my $n = $tree->base62(50); |
785 |
|
|
786 |
|
=cut |
787 |
|
|
788 |
|
sub base62 { |
789 |
|
my $self = shift; |
790 |
|
|
791 |
|
my $value = shift; |
792 |
|
|
793 |
|
confess("need non-negative number") if (! defined($value) || $value < 0); |
794 |
|
|
795 |
|
my @digits = qw( |
796 |
|
0 1 2 3 4 5 6 7 8 9 |
797 |
|
a b c d e f g h i j k l m n o p q r s t u v w x y z |
798 |
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
799 |
|
); |
800 |
|
|
801 |
|
my $base = scalar(@digits); |
802 |
|
my $out = ""; |
803 |
|
my $pow = 1; |
804 |
|
my $pos = 0; |
805 |
|
|
806 |
|
|
807 |
|
if($value == 0) { |
808 |
|
return "0"; |
809 |
|
} |
810 |
|
|
811 |
|
while($value > 0) { |
812 |
|
$pos = $value % $base; |
813 |
|
$out = $digits[$pos] . $out; |
814 |
|
$value = floor($value/$base); |
815 |
|
$pow *= $base; |
816 |
|
} |
817 |
|
|
818 |
|
return $out; |
819 |
|
} |
820 |
|
|
821 |
=head2 to_jsfind |
=head2 to_jsfind |
822 |
|
|
823 |
Create jsFind xml files |
Create jsFind xml files |
828 |
|
|
829 |
=cut |
=cut |
830 |
|
|
|
|
|
831 |
sub to_jsfind { |
sub to_jsfind { |
832 |
my $self = shift; |
my $self = shift; |
833 |
my ($path,$file) = @_; |
my ($path,$file) = @_; |
837 |
confess("path is undefined.") unless ($path); |
confess("path is undefined.") unless ($path); |
838 |
confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file)); |
confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file)); |
839 |
|
|
840 |
|
$file = $self->base62($file); |
841 |
|
|
842 |
my $nr_keys = 0; |
my $nr_keys = 0; |
843 |
|
|
844 |
my ($k, $d, $s) = @$self; |
my ($k, $d, $s) = @$self; |