/[SWISH-PlusPlus]/trunk/PlusPlus.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/PlusPlus.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Sun Dec 5 13:30:57 2004 UTC revision 13 by dpavlin, Sun Dec 5 14:35:54 2004 UTC
# Line 4  use 5.008004; Line 4  use 5.008004;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
7  our $VERSION = '0.05';  our $VERSION = '0.06';
8    
9  use Carp;  use Carp;
10  use File::Temp qw/ tempdir /;  use File::Temp qw/ tempdir /;
# Line 90  sub new { Line 90  sub new {
90                  croak "need $_" unless $self->{$_};                  croak "need $_" unless $self->{$_};
91          }          }
92    
93          if (! -e $self->{'index_dir'}) {          my $index_dir = $self->{'index_dir'};
94                  mkdir $self->{'index_dir'} || confess "can't create index ",$self->{'index'},": $!";  
95            if ($index_dir !~ m#^/#) {
96                    chomp(my $cwd = `pwd`);
97                    $index_dir = "$cwd/$index_dir";
98                    print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'});
99                    $self->{'index_dir'} = $index_dir;
100            }
101    
102            if (! -e $index_dir) {
103                    mkdir $index_dir || confess "can't create index ",$self->{'index'},": $!";
104          }          }
105    
106          # default executables          # default executables
107          $self->{'index'} ||= 'index';          $self->{'index'} ||= 'index';
108          $self->{'search'} ||= 'search';          $self->{'search'} ||= 'search';
109    
110          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'});
111    
112          $self ? return $self : return undef;          $self ? return $self : return undef;
113  }  }
# Line 239  sub search { Line 248  sub search {
248          return @results;          return @results;
249  }  }
250    
251    =head2 finish_update
252    
253    This method will close index.
254    
255      $i->finish_update;
256    
257    It will be called on DESTROY when $i goes out of scope.
258    
259    =cut
260    
261    sub finish_update {
262            my $self = shift;
263    
264            $self->_close_index;
265    }
266    
267    sub DESTROY {
268            my $self = shift;
269            $self->finish_update;
270    }
271    
272  =head1 PRIVATE METHODS  =head1 PRIVATE METHODS
273    
274  Private methods implement internals for creating temporary file needed for  Private methods implement internals for creating temporary file needed for
# Line 263  sub _init_indexer { Line 293  sub _init_indexer {
293    
294          chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!";          chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!";
295    
296          my $opt = "-v 4";          my $opt = "-v " . ($self->{'debug'} || '0');
297    
298          unless ($self->{'use_stopwrods'}) {          unless ($self->{'use_stopwrods'}) {
299                  open(STOP, '>', "_stopwords_") || carp "can't create empty stopword file, skipping\n";                  open(STOP, '>', "_stopwords_") || carp "can't create empty stopword file, skipping\n";
# Line 274  sub _init_indexer { Line 304  sub _init_indexer {
304    
305          my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -';          my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -';
306    
307            print STDERR "## open index $open_cmd\n" if ($self->{'index'});
308    
309          open($self->{'index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!";          open($self->{'index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!";
310    

Legend:
Removed from v.12  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26