/[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 13 by dpavlin, Sun Dec 5 14:35:54 2004 UTC revision 14 by dpavlin, Sun Dec 5 15:35:53 2004 UTC
# Line 92  sub new { Line 92  sub new {
92    
93          my $index_dir = $self->{'index_dir'};          my $index_dir = $self->{'index_dir'};
94    
95            my $cwd;
96            chomp($cwd = `pwd`);
97            $self->{'cwd'} = $cwd || carp "can't get cwd!";
98            
99          if ($index_dir !~ m#^/#) {          if ($index_dir !~ m#^/#) {
                 chomp(my $cwd = `pwd`);  
100                  $index_dir = "$cwd/$index_dir";                  $index_dir = "$cwd/$index_dir";
101                  print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'});                  print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'});
102                  $self->{'index_dir'} = $index_dir;                  $self->{'index_dir'} = $index_dir;
# Line 143  sub check_bin { Line 146  sub check_bin {
146          confess $self->{'search'}," binary is not SWISH++" unless ($s =~ m/^SWISH\+\+/);          confess $self->{'search'}," binary is not SWISH++" unless ($s =~ m/^SWISH\+\+/);
147    
148          if ($i eq $s) {          if ($i eq $s) {
149                    $i =~ s/^SWISH\+\+\s+// || confess "can't strip SWISH++ from version";
150                  $self->{'version'} = $i;                  $self->{'version'} = $i;
151                  return 1;                  return 1;
152          } else  {          } else  {
# Line 217  sub search { Line 221  sub search {
221    
222          my $query = shift || return;          my $query = shift || return;
223    
224          $self->_close_index;          $self->finish_update;
225    
226          my @results;          my @results;
227    
# Line 261  It will be called on DESTROY when $i goe Line 265  It will be called on DESTROY when $i goe
265  sub finish_update {  sub finish_update {
266          my $self = shift;          my $self = shift;
267    
268            print STDERR "## finish_update\n" if ($self->{'debug'});
269    
270          $self->_close_index;          $self->_close_index;
271  }  }
272    
# Line 289  It will also create empty file C<_stopwo Line 295  It will also create empty file C<_stopwo
295  sub _init_indexer {  sub _init_indexer {
296          my $self = shift;          my $self = shift;
297    
298          $self->{'tmp_dir'} = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!";          return if ($self->{'_index_fh'});
299    
300          chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!";          my $tmp_dir = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!";
301            $self->{'tmp_dir'} = $tmp_dir;
302    
303            chdir $tmp_dir || confess "can't chdir to ".$tmp_dir.": $!";
304    
305            print STDERR "## tmp_dir: $tmp_dir" if ($self->{'debug'});
306    
307          my $opt = "-v " . ($self->{'debug'} || '0');          my $opt = "-v " . ($self->{'debug'} || '0');
308    
# Line 304  sub _init_indexer { Line 315  sub _init_indexer {
315    
316          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 -';
317    
318          print STDERR "## open index $open_cmd\n" if ($self->{'index'});          print STDERR "## init_indexer: $open_cmd\n" if ($self->{'debug'});
319    
320          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: $!";
321    
322            chdir $self->{'cwd'} || confess "can't chdir to ".$self->{'cwd'}.": $!";
323    
324          return $self->{'index_fh'};          return $self->{'_index_fh'};
325  }  }
326    
327  =head2 _create_doc  =head2 _create_doc
# Line 336  sub _create_doc { Line 348  sub _create_doc {
348          my $arg = {@_};          my $arg = {@_};
349    
350          # open indexer if needed          # open indexer if needed
351          $self->{'index_fh'} ||= $self->_init_indexer;          $self->_init_indexer;
352    
353          my $path = $self->{'tmp_dir'} || confess "no tmp_dir?";          my $path = $self->{'tmp_dir'} || confess "no tmp_dir?";
354            $path .= '/' . $arg->{'path'};
355    
356            print STDERR "## _create_doc: $path\n" if ($self->{'debug'});
357    
358          open(TMP, '>', $arg->{'path'}) || die "can't create temp file ".$arg->{'path'}.": $!";          open(TMP, '>', $path) || die "can't create temp file $path: $!";
359    
360          print TMP '<html><head>';          print TMP '<html><head>';
361    
# Line 363  sub _create_doc { Line 378  sub _create_doc {
378                    
379          close(TMP) || confess "can't close tmp file ".$arg->{'path'}.": $!";          close(TMP) || confess "can't close tmp file ".$arg->{'path'}.": $!";
380    
381          print { $self->{'index_fh'} } $arg->{'path'}."\n";          print { $self->{'_index_fh'} } $arg->{'path'}."\n";
382  }  }
383    
384  =head2 _close_index  =head2 _close_index
# Line 379  You have to close index before searching Line 394  You have to close index before searching
394  sub _close_index {  sub _close_index {
395          my $self = shift;          my $self = shift;
396    
397          return unless ($self->{'index_fh'});          return unless ($self->{'_index_fh'});
398    
399          print STDERR "## close index\n" if ($self->{'debug'});          print STDERR "## close index\n" if ($self->{'debug'});
400    
401          close($self->{'index_fh'});          close($self->{'_index_fh'});
402          undef $self->{'index_fh'};          undef $self->{'_index_fh'};
403  }  }
404    
405  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26