line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Progress::PV; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1287
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use base qw( Class::Accessor::Fast Class::ErrorHandler ); |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
1770
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ |
9
|
|
|
|
|
|
|
pv |
10
|
|
|
|
|
|
|
options |
11
|
|
|
|
|
|
|
stdin |
12
|
|
|
|
|
|
|
stdout |
13
|
|
|
|
|
|
|
stderr |
14
|
|
|
|
|
|
|
/); |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
16736
|
use IPC::Run qw( run ); |
|
2
|
|
|
|
|
116243
|
|
|
2
|
|
|
|
|
102
|
|
17
|
2
|
|
|
2
|
|
17
|
use Carp qw( carp ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1195
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %options = ( |
20
|
|
|
|
|
|
|
progress => '-p', |
21
|
|
|
|
|
|
|
timeron => '-t', |
22
|
|
|
|
|
|
|
etatimer => '-e', |
23
|
|
|
|
|
|
|
ratecnter => '-r', |
24
|
|
|
|
|
|
|
avgrate => '-a', |
25
|
|
|
|
|
|
|
bytecnter => '-b', |
26
|
|
|
|
|
|
|
timeron => '-t', |
27
|
|
|
|
|
|
|
numericop => '-n', |
28
|
|
|
|
|
|
|
quietmode => '-q', |
29
|
|
|
|
|
|
|
waitmode => '-W', |
30
|
|
|
|
|
|
|
forceop => '-f', |
31
|
|
|
|
|
|
|
cursorpos => '-c', |
32
|
|
|
|
|
|
|
linemode => '-l', |
33
|
|
|
|
|
|
|
help => '-h', |
34
|
|
|
|
|
|
|
version => '-V', |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
assumesize => '-s SIZE', |
37
|
|
|
|
|
|
|
termwidth => '-w WIDTH', |
38
|
|
|
|
|
|
|
termheight => '-h HEIGHT', |
39
|
|
|
|
|
|
|
nameprefix => '-N NAME', |
40
|
|
|
|
|
|
|
ratelimit => '-L RATE', |
41
|
|
|
|
|
|
|
bufsize => '-B BYTES', |
42
|
|
|
|
|
|
|
inputfiles => '-file files... (shell globbed)', |
43
|
|
|
|
|
|
|
cmd => '-cmd command to run in pipe' |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
2
|
|
|
2
|
1
|
250
|
my $class = shift; |
48
|
2
|
|
50
|
|
|
23
|
my $self = { |
49
|
|
|
|
|
|
|
pv => shift || 'pv', |
50
|
|
|
|
|
|
|
options => [] |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
13191
|
system("$self->{pv} -V > /dev/null 2>&1"); |
54
|
2
|
|
|
|
|
81
|
my $ret = $? >> 8; |
55
|
2
|
50
|
33
|
|
|
137
|
if ( $ret != 0 and $ret != 1 ) { |
56
|
2
|
|
|
|
|
1306
|
carp "Can't find pv command."; |
57
|
2
|
|
|
|
|
457
|
exit 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
bless $self, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub showprogress { |
64
|
0
|
|
|
0
|
1
|
|
my ($opts, %h, $files, $cmd, $shcmd, @shcmd) = (); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
$opts = $self->{options}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
%h = %{$opts}; |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my @pvopts = (); |
72
|
0
|
|
|
|
|
|
for my $key (keys(%h)) { |
73
|
0
|
|
|
|
|
|
my $value = $h{$key}; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if($key =~ /\-file/) { |
76
|
0
|
|
|
|
|
|
$files = $value; |
77
|
0
|
|
|
|
|
|
next; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
0
|
|
|
|
|
if($key =~ /\-cmd/) { |
80
|
0
|
|
|
|
|
|
$shcmd = $value; |
81
|
0
|
|
|
|
|
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
0
|
|
|
|
|
if(int($value) != 1) { |
84
|
0
|
|
|
|
|
|
push @pvopts, $key . ' ' . $value; |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
push @pvopts, $key; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
$cmd = $self->{pv}; |
91
|
0
|
|
|
|
|
|
my $pvoptsline = join ' ', @pvopts; |
92
|
0
|
0
|
|
|
|
|
if(defined($files)) { |
93
|
0
|
|
|
|
|
|
$pvoptsline = $pvoptsline . " " . join " ", $files; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $fullcmd = $cmd . " " . $pvoptsline; |
97
|
0
|
|
|
|
|
|
$fullcmd =~ s/\s+/ /g; |
98
|
0
|
|
|
|
|
|
my @runcmd = split / /, $fullcmd; |
99
|
0
|
0
|
|
|
|
|
if(defined($shcmd)) { |
100
|
0
|
|
|
|
|
|
@shcmd = ($shcmd); |
101
|
0
|
|
|
|
|
|
run \@runcmd, '|', \@shcmd; |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
run \@runcmd; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
return 0; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
*pr = \&showprogress; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |