| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Console::ProgressBar; |
|
2
|
5
|
|
|
5
|
|
238027
|
use 5.008001; |
|
|
5
|
|
|
|
|
55
|
|
|
3
|
5
|
|
|
5
|
|
25
|
use strict; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
116
|
|
|
4
|
5
|
|
|
5
|
|
18
|
use warnings; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
110
|
|
|
5
|
5
|
|
|
5
|
|
2942
|
use utf8; |
|
|
5
|
|
|
|
|
63
|
|
|
|
5
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "1.01"; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
4
|
|
|
4
|
0
|
325
|
my ($class,$_title,$_maxValue,$configuration) = @_; |
|
11
|
4
|
|
|
|
|
29
|
my $this = { |
|
12
|
|
|
|
|
|
|
_index => 0, |
|
13
|
|
|
|
|
|
|
title => $_title, |
|
14
|
|
|
|
|
|
|
titleMaxSize => 30, |
|
15
|
|
|
|
|
|
|
maxValue => $_maxValue, |
|
16
|
|
|
|
|
|
|
length => 20, |
|
17
|
|
|
|
|
|
|
segment => '#' |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
4
|
|
|
|
|
10
|
bless($this,$class); |
|
20
|
|
|
|
|
|
|
|
|
21
|
4
|
100
|
|
|
|
15
|
if(defined($configuration)) { |
|
22
|
1
|
|
|
|
|
2
|
my %conf = %{ $configuration }; |
|
|
1
|
|
|
|
|
5
|
|
|
23
|
1
|
|
|
|
|
3
|
foreach my $parameter (keys %conf) { |
|
24
|
3
|
|
|
|
|
10
|
$this->{$parameter} = $conf{$parameter}; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
13
|
return $this; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _calculateCurrentValue { |
|
32
|
7
|
|
|
7
|
|
25
|
my($this) = @_; |
|
33
|
7
|
|
|
|
|
31
|
return int( ( $this->{_index} / $this->{maxValue} ) * 100 ); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _getGraphicBars { |
|
37
|
7
|
|
|
7
|
|
3168
|
my($this,$percentage) = @_; |
|
38
|
7
|
|
|
|
|
14
|
my $bars = ""; |
|
39
|
7
|
|
|
|
|
22
|
my $nbrBars = int( ($percentage / 100) * $this->{length} ); |
|
40
|
7
|
|
|
|
|
21
|
$bars = $this->{segment} x $nbrBars; |
|
41
|
|
|
|
|
|
|
|
|
42
|
7
|
|
|
|
|
28
|
return $bars; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub reset { |
|
46
|
1
|
|
|
1
|
1
|
3
|
my ($this) = @_; |
|
47
|
1
|
|
|
|
|
2
|
$this->{_index} = 0; |
|
48
|
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
2
|
return $this; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub setTitle { |
|
53
|
1
|
|
|
1
|
1
|
9
|
my ($this,$title) = @_; |
|
54
|
1
|
|
|
|
|
2
|
$this->{title} = $title; |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
return $this; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub setIndex { |
|
60
|
3
|
|
|
3
|
1
|
13
|
my ($this,$value) = @_; |
|
61
|
3
|
|
|
|
|
8
|
$this->{_index} = $value; |
|
62
|
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
7
|
return $this; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub getIndex { |
|
67
|
1
|
|
|
1
|
0
|
6
|
my ($this)= @_; |
|
68
|
1
|
|
|
|
|
6
|
return $this->{_index}; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub next { |
|
72
|
100
|
|
|
100
|
1
|
218
|
my ($this) = @_; |
|
73
|
100
|
50
|
|
|
|
145
|
if( $this->{_index} < $this->{maxValue} ) { |
|
74
|
100
|
|
|
|
|
108
|
$this->{_index}++; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
100
|
|
|
|
|
114
|
return $this; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub back { |
|
80
|
40
|
|
|
40
|
1
|
86
|
my ($this) = @_; |
|
81
|
40
|
50
|
|
|
|
58
|
if($this->{_index} > 0) { |
|
82
|
40
|
|
|
|
|
40
|
$this->{_index}--; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
40
|
|
|
|
|
48
|
return $this; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub render { |
|
88
|
0
|
|
|
0
|
0
|
|
my ($this) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $percentage = $this->_calculateCurrentValue(); |
|
91
|
0
|
|
|
|
|
|
my $bars = $this->_getGraphicBars($percentage); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $progressBar = sprintf("%-$this->{titleMaxSize}s [%-$this->{length}s] %d%%",$this->{title},$bars,$percentage); |
|
94
|
0
|
|
|
|
|
|
print "$progressBar\r"; |
|
95
|
0
|
|
|
|
|
|
$|++; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
|
99
|
|
|
|
|
|
|
__END__ |