--- trunk2/lib/WebPAC.pm 2004/09/13 23:13:54 439 +++ trunk2/lib/WebPAC.pm 2004/09/15 22:36:23 454 @@ -209,6 +209,8 @@ if (my $s = $self->{'start_mfn'}) { $log->info("skipping to MFN $s"); $startmfn = $s; + } else { + $self->{'start_mfn'} = $startmfn; } $maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); @@ -264,7 +266,7 @@ } - $self->{'current_mfn'} = $startmfn; + $self->{'current_mfn'} = -1; $self->{'last_pcnt'} = 0; $log->debug("max mfn: $maxmfn"); @@ -287,7 +289,15 @@ my $log = $self->_get_logger(); - my $mfn = $self->{'current_mfn'}++ || $log->logconfess("it seems that you didn't load database!"); + $log->logconfess("it seems that you didn't load database!") unless ($self->{'current_mfn'}); + + if ($self->{'current_mfn'} == -1) { + $self->{'current_mfn'} = $self->{'start_mfn'}; + } else { + $self->{'current_mfn'}++; + } + + my $mfn = $self->{'current_mfn'}; if ($mfn > $self->{'max_mfn'}) { $self->{'current_mfn'} = $self->{'max_mfn'}; @@ -304,6 +314,19 @@ } } +=head2 mfn + +Returns current record number (MFN). + + print $webpac->mfn; + +=cut + +sub mfn { + my $self = shift; + return $self->{'current_mfn'}; +} + =head2 progress_bar Draw progress bar on STDERR. @@ -329,13 +352,13 @@ $self->{'last_pcnt'} ||= 1; - my $p = int($curr * 100 / $max); + my $p = int($curr * 100 / $max) || 1; # reset on re-run if ($p < $self->{'last_pcnt'}) { $self->{'last_pcnt'} = $p; $self->{'last_t'} = time(); - $self->{'last_curr'} = 1; + $self->{'last_curr'} = undef; } if ($p != $self->{'last_pcnt'}) { @@ -754,6 +777,31 @@ return @arr; } +=head2 sort_arr + +Sort array ignoring case and html in data + + my @sorted = $webpac->sort_arr(@unsorted); + +=cut + +sub sort_arr { + my $self = shift; + + my $log = $self->_get_logger(); + + # FIXME add Schwartzian Transformation? + + my @sorted = sort { + $a =~ s#<[^>]+/*>##; + $b =~ s#<[^>]+/*>##; + lc($b) cmp lc($a) + } @_; + $log->debug("sorted values: ",sub { join(", ",@sorted) }); + + return @sorted; +} + =head2 data_structure @@ -811,15 +859,8 @@ next if (! @v); if ($tag->{'sort'}) { - # very special sort, ignoring case and - # html - @v = sort { - $a =~ s#<[^>]+/*>##; - $b =~ s#<[^>]+/*>##; - lc($b) cmp lc($a) - } @v; + @v = $self->sort_arr(@v); $log->warn("sort within tag is usually not what you want!"); - $log->debug("sorted values: ",sub { join(", ",@v) }); } # use format? @@ -880,7 +921,6 @@ # post-sort all values in field if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { $log->warn("sort at field tag not implemented"); - } push @ds, $row;