--- trunk/PlusPlus.pm 2004/12/05 14:32:40 12 +++ trunk/PlusPlus.pm 2004/12/05 14:35:54 13 @@ -4,7 +4,7 @@ use strict; use warnings; -our $VERSION = '0.05'; +our $VERSION = '0.06'; use Carp; use File::Temp qw/ tempdir /; @@ -90,15 +90,24 @@ croak "need $_" unless $self->{$_}; } - if (! -e $self->{'index_dir'}) { - mkdir $self->{'index_dir'} || confess "can't create index ",$self->{'index'},": $!"; + my $index_dir = $self->{'index_dir'}; + + if ($index_dir !~ m#^/#) { + chomp(my $cwd = `pwd`); + $index_dir = "$cwd/$index_dir"; + print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'}); + $self->{'index_dir'} = $index_dir; + } + + if (! -e $index_dir) { + mkdir $index_dir || confess "can't create index ",$self->{'index'},": $!"; } # default executables $self->{'index'} ||= 'index'; $self->{'search'} ||= 'search'; - print STDERR "## new index_dir: ",$self->{'index_dir'}," index: ",$self->{'index'}, " search: ",$self->{'search'},"\n" if ($self->{'debug'}); + print STDERR "## new index_dir: ",$index_dir," index: ",$self->{'index'}, " search: ",$self->{'search'},"\n" if ($self->{'debug'}); $self ? return $self : return undef; } @@ -239,6 +248,27 @@ return @results; } +=head2 finish_update + +This method will close index. + + $i->finish_update; + +It will be called on DESTROY when $i goes out of scope. + +=cut + +sub finish_update { + my $self = shift; + + $self->_close_index; +} + +sub DESTROY { + my $self = shift; + $self->finish_update; +} + =head1 PRIVATE METHODS Private methods implement internals for creating temporary file needed for @@ -263,7 +293,7 @@ chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!"; - my $opt = "-v 4"; + my $opt = "-v " . ($self->{'debug'} || '0'); unless ($self->{'use_stopwrods'}) { open(STOP, '>', "_stopwords_") || carp "can't create empty stopword file, skipping\n"; @@ -274,6 +304,7 @@ my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; + print STDERR "## open index $open_cmd\n" if ($self->{'index'}); open($self->{'index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!";