line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
29946
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
2
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
65
|
|
3
|
|
|
|
|
|
|
package Acme::ProgressBar; |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$Acme::ProgressBar::VERSION = '1.127'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
# ABSTRACT: a simple progress bar for the patient |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1147
|
use Time::HiRes (); |
|
1
|
|
|
|
|
2405
|
|
|
1
|
|
|
|
|
36
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
463
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(progress); ## no critic Export |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub progress(&) { ## no critic Prototype |
17
|
2
|
|
|
2
|
1
|
18
|
my ($code) = @_; |
18
|
2
|
|
|
|
|
12
|
local $| = 1; ## no critic |
19
|
2
|
|
|
|
|
8
|
_overprint(_message(0,10,undef)); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
10
|
my $begun = Time::HiRes::time; |
22
|
2
|
|
|
|
|
7
|
$code->(); |
23
|
2
|
|
|
|
|
1000197
|
my $total = Time::HiRes::time - $begun; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
10
|
for (1 .. 9) { |
26
|
18
|
|
|
|
|
113
|
_overprint(_message($_,10,$total)); |
27
|
18
|
|
|
|
|
9005134
|
Time::HiRes::sleep($total); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
20
|
_overprint(_message(10,10,$total)); |
31
|
2
|
|
|
|
|
44
|
print "\n"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _message { |
35
|
22
|
|
|
22
|
|
98
|
my ($iteration, $total, $time) = @_; |
36
|
22
|
|
|
|
|
176
|
my $message = 'Progress: [' |
37
|
|
|
|
|
|
|
. q{=} x $iteration |
38
|
|
|
|
|
|
|
. q{ } x ($total - $iteration) |
39
|
|
|
|
|
|
|
. '] '; |
40
|
|
|
|
|
|
|
|
41
|
22
|
100
|
|
|
|
85
|
if (defined $time) { |
42
|
20
|
|
|
|
|
404
|
$message .= sprintf '%0.0fs remaining%25s', |
43
|
|
|
|
|
|
|
(($total - $iteration) * $time), q{ }; |
44
|
|
|
|
|
|
|
} else { |
45
|
2
|
|
|
|
|
9
|
$message .= '(calculating time remaining)'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _overprint { |
50
|
22
|
|
|
22
|
|
47
|
my ($message) = @_; |
51
|
22
|
|
|
|
|
395
|
print $message, "\r"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
"48102931829 minutes remaining"; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |