--- trunk2/lib/WebPAC.pm 2004/06/20 18:39:30 376
+++ trunk2/lib/WebPAC.pm 2004/07/24 13:48:08 398
@@ -198,9 +198,12 @@
my $rec = $self->{'data'}->{$mfn};
$self->create_lookup($rec, @{$arg->{'lookup'}});
+ $self->progress_bar($mfn,$maxmfn);
+
}
$self->{'current_mfn'} = 1;
+ $self->{'last_pcnt'} = 0;
# store max mfn and return it.
return $self->{'max_mfn'} = $maxmfn;
@@ -228,9 +231,45 @@
return;
}
+ $self->progress_bar($mfn,$self->{'max_mfn'});
+
return $self->{'data'}->{$mfn};
}
+=head2 progress_bar
+
+Draw progress bar on STDERR.
+
+ $webpac->progress_bar($current, $max);
+
+=cut
+
+sub progress_bar {
+ my $self = shift;
+
+ my ($curr,$max) = @_;
+
+ my $log = $self->_get_logger();
+
+ $log->logconfess("no current value!") if (! $curr);
+ $log->logconfess("no maximum value!") if (! $max);
+
+ if ($curr > $max) {
+ $max = $curr;
+ $log->debug("overflow to $curr");
+ }
+
+ $self->{'last_pcnt'} ||= 1;
+
+ $self->{'last_pcnt'} = $curr if ($curr < $self->{'last_pcnt'});
+
+ my $p = int($curr * 100 / $max);
+ if ($p != $self->{'last_pcnt'}) {
+ printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$curr,$max,"=" x ($p/2).">", $p );
+ $self->{'last_pcnt'} = $p;
+ }
+}
+
=head2 open_import_xml
Read file from C directory and parse it.
@@ -335,6 +374,7 @@
if ($$rec->{$f}) {
return '' if (! $$rec->{$f}->[$i]);
+ no strict 'refs';
if ($sf && $$rec->{$f}->[$i]->{$sf}) {
$$found++ if (defined($$found));
return $$rec->{$f}->[$i]->{$sf};
@@ -616,7 +656,8 @@
my @ds = $webpac->data_structure($rec);
This method will also set C<$webpac->{'currnet_filename'}> if there is
- tag in C.
+ tag in C and C<$webpac->{'headline'}> if there is
+ tag.
=cut
@@ -629,6 +670,7 @@
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o);
undef $self->{'currnet_filename'};
+ undef $self->{'headline'};
my @sorted_tags;
if ($self->{tags_by_order}) {
@@ -666,6 +708,15 @@
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v;
}
+ if ($field eq 'filename') {
+ $self->{'current_filename'} = join('',@v);
+ $log->debug("filename: ",$self->{'current_filename'});
+ } elsif ($field eq 'headline') {
+ $self->{'headline'} .= join('',@v);
+ $log->debug("headline: ",$self->{'headline'});
+ next; # don't return headline in data_structure!
+ }
+
# does tag have type?
if ($tag->{'type'}) {
push @{$row->{$tag->{'type'}}}, @v;
@@ -674,10 +725,6 @@
push @{$row->{'swish'}}, @v;
}
- if ($field eq 'filename') {
- $self->{'current_filename'} = join('',@v);
- $log->debug("filename: ",$self->{'current_filename'});
- }
}