17 |
|
|
18 |
our $VERSION = '0.01'; |
our $VERSION = '0.01'; |
19 |
|
|
|
#my $LOOKUP_REGEX = '\[[^\[\]]+\]'; |
|
|
#my $LOOKUP_REGEX_SAVE = '\[([^\[\]]+)\]'; |
|
|
my $LOOKUP_REGEX = 'lookup{[^\{\}]+}'; |
|
|
my $LOOKUP_REGEX_SAVE = 'lookup{([^\{\}]+)}'; |
|
|
|
|
20 |
=head1 SYNOPSYS |
=head1 SYNOPSYS |
21 |
|
|
22 |
This module defines common functions, and is used as base for other, more |
This module defines common functions, and is used as base for other, more |
104 |
$log->debug("filter result: $format"); |
$log->debug("filter result: $format"); |
105 |
} |
} |
106 |
# do we have lookups? |
# do we have lookups? |
107 |
if ($format =~ /$LOOKUP_REGEX/o) { |
if ($self->{'lookup'}) { |
|
$log->debug("format '$format' has lookup"); |
|
108 |
return $self->lookup($format); |
return $self->lookup($format); |
109 |
} else { |
} else { |
110 |
return $format; |
return $format; |
165 |
} |
} |
166 |
|
|
167 |
|
|
168 |
|
=head2 progress_bar |
169 |
|
|
170 |
|
Draw progress bar on STDERR. |
171 |
|
|
172 |
|
$webpac->progress_bar($current, $max); |
173 |
|
|
174 |
|
=cut |
175 |
|
|
176 |
|
sub progress_bar { |
177 |
|
my $self = shift; |
178 |
|
|
179 |
|
my ($curr,$max) = @_; |
180 |
|
|
181 |
|
my $log = $self->_get_logger(); |
182 |
|
|
183 |
|
$log->logconfess("no current value!") if (! $curr); |
184 |
|
$log->logconfess("no maximum value!") if (! $max); |
185 |
|
|
186 |
|
if ($curr > $max) { |
187 |
|
$max = $curr; |
188 |
|
$log->debug("overflow to $curr"); |
189 |
|
} |
190 |
|
|
191 |
|
$self->{'last_pcnt'} ||= 1; |
192 |
|
$self->{'start_t'} ||= time(); |
193 |
|
|
194 |
|
my $p = int($curr * 100 / $max) || 1; |
195 |
|
|
196 |
|
# reset on re-run |
197 |
|
if ($p < $self->{'last_pcnt'}) { |
198 |
|
$self->{'last_pcnt'} = $p; |
199 |
|
$self->{'start_t'} = time(); |
200 |
|
} |
201 |
|
|
202 |
|
if ($p != $self->{'last_pcnt'}) { |
203 |
|
|
204 |
|
my $t = time(); |
205 |
|
my $rate = ($curr / ($t - $self->{'start_t'} || 1)); |
206 |
|
my $eta = ($max-$curr) / ($rate || 1); |
207 |
|
printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$curr,"=" x ($p/3)."$p%>", $max, $rate, $self->fmt_time($eta)); |
208 |
|
$self->{'last_pcnt'} = $p; |
209 |
|
$self->{'last_curr'} = $curr; |
210 |
|
} |
211 |
|
print STDERR "\n" if ($p == 100); |
212 |
|
} |
213 |
|
|
214 |
|
=head2 fmt_time |
215 |
|
|
216 |
|
Format time (in seconds) for display. |
217 |
|
|
218 |
|
print $webpac->fmt_time(time()); |
219 |
|
|
220 |
|
This method is called by L<progress_bar> to display remaining time. |
221 |
|
|
222 |
|
=cut |
223 |
|
|
224 |
|
sub fmt_time { |
225 |
|
my $self = shift; |
226 |
|
|
227 |
|
my $t = shift || 0; |
228 |
|
my $out = ""; |
229 |
|
|
230 |
|
my ($ss,$mm,$hh) = gmtime($t); |
231 |
|
$out .= "${hh}h" if ($hh); |
232 |
|
$out .= sprintf("%02d:%02d", $mm,$ss); |
233 |
|
$out .= " " if ($hh == 0); |
234 |
|
return $out; |
235 |
|
} |
236 |
|
|
237 |
|
# |
238 |
|
# |
239 |
|
# |
240 |
|
|
241 |
=head1 INTERNAL METHODS |
=head1 INTERNAL METHODS |
242 |
|
|
243 |
Here is a quick list of internal methods, mostly useful to turn debugging |
Here is a quick list of internal methods, mostly useful to turn debugging |