--- trunk2/lib/WebPAC.pm 2004/06/20 17:52:41 375
+++ trunk2/lib/WebPAC.pm 2004/07/20 17:15:48 389
@@ -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};
@@ -375,6 +415,9 @@
This function B perform parsing of format to inteligenty skip
delimiters before fields which aren't used.
+This method will automatically decode UTF-8 string to local code page
+if needed.
+
=cut
sub fill_in {
@@ -390,6 +433,10 @@
# FIXME remove for speedup?
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o);
+ if (utf8::is_utf8($format)) {
+ $format = $self->_x($format);
+ }
+
my $found = 0;
my $eval_code;