blib/lib/Term/Sk.pm

filter: Statementstmt 90.7% 215 / 237 Branchbran 73.6% 84 / 114 Conditioncond 80.0% 24 / 30 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 83.3% 20 / 24 Podpod 0.0% 0 / 19 totaltotal 80.1% 351 / 438 CC 70 SCAR 25.5
CC
70
Cov
85%
new
23.1
show
19.9
show_maybe
11.2
CRAP 12.8
↑ Summary
1 package Term::Sk;
2 1 $Term::Sk::VERSION = '0.18';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Fcntl qw(:seek);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10  
11 1 our @ISA = qw(Exporter);
12 1 our %EXPORT_TAGS = ( 'all' => [ qw(set_chunk_size set_bkup_size rem_backspace) ] );
13 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
14 1 our @EXPORT = qw();
15  
16 1 our $errcode = 0;
17 1 our $errmsg = '';
18  
19 28 ▶sub new {
Subroutine new: called CC=23 SCAR=31.4
Pod undocumented
20 28 shift;
21 28 my $self = {};
22 28 bless $self;
23  
24 28 $errcode = 0;
25 28 $errmsg = '';
26  
27 28 my %hash = (freq => 1, base => 0, target => 1_000, quiet => 0, test => 0, num => q{9_999});
28 28 ▶ %hash = (%hash, %{$_[1]}) if defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 28 0 28
29  
30 28 ▶ my $format = defined $_[0] ? $_[0] : '%8c';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 28 0 28
31  
32 28 $self->{base} = $hash{base};
33 28 $self->{target} = $hash{target};
34 28 $self->{quiet} = $hash{quiet};
35 28 $self->{test} = $hash{test};
36 28 $self->{format} = $format;
37 28 $self->{freq} = $hash{freq};
38 28 $self->{value} = $hash{base};
39 28 $self->{mock_tm} = $hash{mock_tm};
40 28 $self->{oldtext} = '';
41 28 $self->{line} = '';
42 28 $self->{pdisp} = '#';
43 28 $self->{commify} = $hash{commify};
44 28 ▶ $self->{token} = defined($hash{token}) ? ref($hash{token}) eq 'ARRAY' ? $hash{token} : [$hash{token}] : [];
Branch: 2 branches
BranchTrueFalseTotal
defined $hash{'token'} ? : 2 26 28
ref $hash{'token'} eq 'ARRAY' ? : 1 1 2
45  
46 28 ▶ unless (defined $self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"quiet"}) 0 28 28
47 0 $self->{quiet} = !-t STDOUT;
48 }
49  
50 28 ▶ if ($hash{num} eq '9') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash{'num'} eq '9') { } 1 27 28
51 1 $self->{sep} = '';
52 1 $self->{group} = 0;
53 }
54 else {
55 27 ▶ my ($sep, $group) = $hash{num} =~ m{\A 9 ([^\d\+\-]) (9+) \z}xms or do {
Branch: 1 branch
BranchTrueFalseTotal
() = $hash{"num"} =~ /\A 9 ([^\d\+\-]) (9+) \z/msx or do { $Term::Sk::errcode = 95; $Term::Sk::errmsg = qq[Can't parse num => '$hash{"num"}']; die sprintf("Error-%04d: %s", $Term::Sk::errcode, $Term::Sk::errmsg) } 26 1 27
56 1 $errcode = 95;
57 1 $errmsg = qq{Can't parse num => '$hash{num}'};
58 1 die sprintf('Error-%04d: %s', $errcode, $errmsg);
59 };
60 26 $self->{sep} = $sep;
61 26 $self->{group} = length($group);
62 }
63  
64 # Here we de-compose the format into $self->{action}
65  
66 27 $self->{action} = [];
67  
68 27 my $fmt = $format;
69 27 ▶ while ($fmt ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt ne "") 49 25 74
70 49 ▶ if ($fmt =~ m{^ ([^%]*) % (.*) $}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /^ ([^%]*) % (.*) $/msx) { } 45 4 49
71 45 my ($literal, $portion) = ($1, $2);
72 45 ▶ unless ($portion =~ m{^ (\d*) ([a-zA-Z]) (.*) $}xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($portion =~ /^ (\d*) ([a-zA-Z]) (.*) $/msx) 1 44 45
73 1 $errcode = 100;
74 1 $errmsg = qq{Can't parse '%[<number>]<alpha>' from '%$portion', total line is '$format'};
75 1 die sprintf('Error-%04d: %s', $errcode, $errmsg);
76 }
77  
78 44 my ($repeat, $disp_code, $remainder) = ($1, $2, $3);
79  
80 44 ▶ if ($repeat eq '') { $repeat = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat eq "") 24 20 44
81 0 ▶ if ($repeat < 1) { $repeat = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat < 1) 0 44 44
82  
83 44 ▶ unless ($disp_code eq 'b'
Branch: 1 branch
BranchTrueFalseTotal
unless ($disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p" or $disp_code eq "P" or $disp_code eq "t" or $disp_code eq "k") 1 43 44
Condition100%21/21
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p" or $disp_code eq "P" or $disp_code eq "t" or $disp_code eq "k"
l!l&&r!l&&!r
4031
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p" or $disp_code eq "P" or $disp_code eq "t"
l!l&&r!l&&!r
3554
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p" or $disp_code eq "P"
l!l&&r!l&&!r
3329
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p"
l!l&&r!l&&!r
31211
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m"
l!l&&r!l&&!r
211013
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d"
l!l&&r!l&&!r
17423
$disp_code eq "b" or $disp_code eq "c"
l!l&&r!l&&!r
21527
MC/DC100%8/8
$disp_code eq "b" or $disp_code eq "c" or $disp_code eq "d" or $disp_code eq "m" or $disp_code eq "p" or $disp_code eq "P" or $disp_code eq "t" or $disp_code eq "k"
$disp_code eq "b" $disp_code eq "c" $disp_code eq "d" $disp_code eq "m" $disp_code eq "p" $disp_code eq "P" $disp_code eq "t" $disp_code eq "k"
Truth table100%9/9
A or B or C or D or E or F or G or H
A= $disp_code eq "b"B= $disp_code eq "c"C= $disp_code eq "d"D= $disp_code eq "m"E= $disp_code eq "p"F= $disp_code eq "P"G= $disp_code eq "t"H= $disp_code eq "k"
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
84 or $disp_code eq 'c'
85 or $disp_code eq 'd'
86 or $disp_code eq 'm'
87 or $disp_code eq 'p'
88 or $disp_code eq 'P'
89 or $disp_code eq 't'
90 or $disp_code eq 'k') {
91 1 $errcode = 110;
92 1 $errmsg = qq{Found invalid display-code ('$disp_code'), expected ('b', 'c', 'd', 'm', 'p', 'P' 't' or 'k') in '%$portion', total line is '$format'};
93 1 die sprintf('Error-%04d: %s', $errcode, $errmsg);
94 }
95  
96 43 ▶ push @{$self->{action}}, {type => '*lit', len => length($literal), lit => $literal} if length($literal) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $literal > 0 41 2 43
97 43 push @{$self->{action}}, {type => $disp_code, len => $repeat};
98 43 $fmt = $remainder;
99 }
100 else {
101 4 push @{$self->{action}}, {type => '*lit', len => length($fmt), lit => $fmt};
102 4 $fmt = '';
103 }
104 }
105  
106 # End of format de-composition
107  
108 25 $self->{tick} = 0;
109 25 $self->{out} = 0;
110 25 ▶ $self->{sec_begin} = $self->{mock_tm} ? $self->{mock_tm} : time;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'mock_tm'} ? : 3 22 25
111 25 $self->{sec_print} = 0;
112  
113 25 $self->show;
114  
115 25 return $self;
116 }
117  
118 5 ▶sub mock_time {
Subroutine mock_time: called CC=1 SCAR=0.0
Pod undocumented
119 5 my $self = shift;
120  
121 5 $self->{mock_tm} = $_[0];
122 }
123  
124 1 ▶sub whisper {
Subroutine whisper: called CC=3 SCAR=14.8
Pod undocumented
125 1 my $self = shift;
126
127 1 my $back = qq{\010} x length $self->{oldtext};
128 1 my $blank = q{ } x length $self->{oldtext};
129  
130 1 $self->{line} = join('', $back, $blank, $back, @_, $self->{oldtext});
131  
132 1 ▶ unless ($self->{test}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"}) 0 1 1
133 0 local $| = 1;
134 0 ▶ if ($self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'quiet'}) { } 0 0 0
135 0 print @_;
136 }
137 else {
138 0 print $self->{line};
139 }
140 }
141 }
142
143 1 ▶sub mute_on {
Subroutine mute_on: called CC=3 SCAR=13.0
Pod undocumented
144 1 my $self = shift;
145
146 1 my $back = qq{\010} x length $self->{oldtext};
147 1 my $blank = q{ } x length $self->{oldtext};
148
149 1 $self->{line} = join('', $back, $blank, $back);
150
151 1 ▶ unless ($self->{test} or $self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"} or $self->{"quiet"}) 0 1 1
Condition33%1/3
$self->{"test"} or $self->{"quiet"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"test"} or $self->{"quiet"}
$self->{"test"} $self->{"quiet"}
Truth table33%1/3
A or B
A= $self->{"test"}B= $self->{"quiet"}
ABresult
1X1
011
000
152 0 local $| = 1;
153 0 print $self->{line};
154 }
155 }
156
157 1 ▶sub mute_off {
Subroutine mute_off: called CC=3 SCAR=14.2
Pod undocumented
158 1 my $self = shift;
159
160 1 $self->{line} = $self->{oldtext};
161
162 1 ▶ unless ($self->{test} or $self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"} or $self->{"quiet"}) 0 1 1
Condition33%1/3
$self->{"test"} or $self->{"quiet"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"test"} or $self->{"quiet"}
$self->{"test"} $self->{"quiet"}
Truth table33%1/3
A or B
A= $self->{"test"}B= $self->{"quiet"}
ABresult
1X1
011
000
163 0 local $| = 1;
164 0 print $self->{line};
165 }
166 }
167
168 35 ▶sub get_line {
Subroutine get_line: called CC=1 SCAR=0.0
Pod undocumented
169 35 my $self = shift;
170  
171 35 return $self->{line};
172 }
173  
174 61 ▶sub up { my $self = shift; $self->{value} += defined $_[0] ? $_[0] : 1; $self->show_maybe; }
Subroutine up: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 2 59 61
175 0 ▶sub down { my $self = shift; $self->{value} -= defined $_[0] ? $_[0] : 1; $self->show_maybe; }
Subroutine down: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
176 29 ▶sub close { my $self = shift; $self->{value} = undef; $self->show; }
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
177  
178 1 ▶sub ticks { my $self = shift; return $self->{tick} }
Subroutine ticks: called CC=1 SCAR=0.0
Pod undocumented
179  
180 2 ▶sub token {
Subroutine token: called CC=2 SCAR=6.9
Pod undocumented
181 2 my $self = shift;
182 2 my $tk = shift;
183 2 ▶ $self->{token} = ref($tk) eq 'ARRAY' ? $tk : [$tk];
Branch: 1 branch
BranchTrueFalseTotal
ref $tk eq 'ARRAY' ? : 1 1 2
184 2 $self->show;
185 }
186  
187 1 ▶sub tok_maybe {
Subroutine tok_maybe: called CC=2 SCAR=7.0
Pod undocumented
188 1 my $self = shift;
189 1 my $tk = shift;
190 1 ▶ $self->{token} = ref($tk) eq 'ARRAY' ? $tk : [$tk];
Branch: 1 branch
BranchTrueFalseTotal
ref $tk eq 'ARRAY' ? : 0 1 1
191 1 $self->show_maybe;
192 }
193  
194 28 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
195 28 my $self = shift;
196 28 $self->close;
197 }
198  
199 62 ▶sub show_maybe {
Subroutine show_maybe: called CC=7 SCAR=24.1
Pod undocumented
200 62 my $self = shift;
201  
202 62 $self->{line} = '';
203  
204 62 ▶ my $sec_now = ($self->{mock_tm} ? $self->{mock_tm} : time) - $self->{sec_begin};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'mock_tm'} ? : 5 57 62
205 62 my $sec_prev = $self->{sec_print};
206  
207 62 $self->{sec_print} = $sec_now;
208 62 $self->{tick}++;
209  
210 62 ▶ if ($self->{freq} eq 's') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'freq'} eq 's') { } 0 62 62
elsif ($self->{'freq'} eq 'd') { } 0 62 62
211 0 ▶ if (int($sec_prev) != int($sec_now)) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $sec_prev != int $sec_now) 0 0 0
212 0 $self->show;
213 }
214 }
215 elsif ($self->{freq} eq 'd') {
216 0 ▶ if (int($sec_prev * 10) != int($sec_now * 10)) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $sec_prev * 10 != int $sec_now * 10) 0 0 0
217 0 $self->show;
218 }
219 }
220 else {
221 62 ▶ unless ($self->{tick} % $self->{freq}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tick"} % $self->{"freq"}) 62 0 62
222 62 $self->show;
223 }
224 }
225 }
226  
227 118 ▶sub show {
Subroutine show: called CC=19 SCAR=29.9
Pod undocumented
228 118 my $self = shift;
229 118 $self->{out}++;
230  
231 118 my $back = qq{\010} x length $self->{oldtext};
232 118 my $blank = q{ } x length $self->{oldtext};
233  
234 118 my $text = '';
235 118 ▶ if (defined $self->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"value"}) 89 29 118
236  
237 # Here we compose a string based on $self->{action} (which, of course, is the previously de-composed format)
238  
239 89 my $tok_ind = 0;
240  
241 89 for my $act (@{$self->{action}}) {
242 216 my ($type, $lit, $len) = ($act->{type}, $act->{lit}, $act->{len});
243  
244 216 ▶ if ($type eq '*lit') { # print (= append to $text) a simple literal
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "*lit") 123 93 216
245 123 $text .= $lit;
246 123 next;
247 }
248 93 ▶ if ($type eq 't') { # print (= append to $text) time elapsed in format 'hh:mm:ss'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "t") 10 83 93
249 10 my $unit = int($self->{sec_print});
250 10 my $hour = int($unit / 3600);
251 10 my $min = int(($unit % 3600) / 60);
252 10 my $sec = $unit % 60;
253 10 my $stamp = sprintf '%02d:%02d:%02d', $hour, $min, $sec;
254  
255 10 ▶ $stamp = substr($stamp, -$len) if length($stamp) > $len;
Branch: 1 branch
BranchTrueFalseTotal
if length $stamp > $len 2 8 10
256  
257 10 $text .= sprintf "%${len}.${len}s", $stamp;
258 10 next;
259 }
260 83 ▶ if ($type eq 'd') { # print (= append to $text) a revolving dash in format '/-\|'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "d") 10 73 83
261 10 $text .= substr('/-\|', $self->{out} % 4, 1) x $len;
262 10 next;
263 }
264 73 ▶ if ($type eq 'b') { # print (= append to $text) progress indicator format '#####_____'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "b") 13 60 73
265 my $progress = $self->{target} == $self->{base} ? 0 :
266 13 ▶ int ($len * ($self->{value} - $self->{base}) / ($self->{target} - $self->{base}) + 0.5);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'target'} == $self->{'base'} ? : 0 13 13
267 0 ▶ if ($progress < 0) { $progress = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if ($progress < 0) { } 0 13 13
elsif ($progress > $len) { } 0 13 13
268 0 elsif ($progress > $len) { $progress = $len }
269 13 $text .= $self->{pdisp} x $progress.'_' x ($len - $progress);
270 13 next;
271 }
272 60 ▶ if ($type eq 'p') { # print (= append to $text) progress in percentage format '999%'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "p") 7 53 60
273 my $percent = $self->{target} == $self->{base} ? 0 :
274 7 ▶ 100 * ($self->{value} - $self->{base}) / ($self->{target} - $self->{base});
Branch: 1 branch
BranchTrueFalseTotal
$self->{'target'} == $self->{'base'} ? : 0 7 7
275 7 $text .= sprintf "%${len}.${len}s", sprintf("%.0f%%", $percent);
276 7 next;
277 }
278 53 ▶ if ($type eq 'P') { # print (= append to $text) literally '%' characters
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "P") 2 51 53
279 2 $text .= '%' x $len;
280 2 next;
281 }
282 51 ▶ if ($type eq 'c') { # print (= append to $text) actual counter value (commified)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "c") 32 19 51
283 32 $text .= sprintf "%${len}s", commify($self->{commify}, $self->{value}, $self->{sep}, $self->{group});
284 32 next;
285 }
286 19 ▶ if ($type eq 'm') { # print (= append to $text) target (commified)
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "m") 12 7 19
287 12 $text .= sprintf "%${len}s", commify($self->{commify}, $self->{target}, $self->{sep}, $self->{group});
288 12 next;
289 }
290 7 ▶ if ($type eq 'k') { # print (= append to $text) token
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "k") 7 0 7
291 7 $text .= sprintf "%-${len}s", $self->{token}[$tok_ind];
292 7 $tok_ind++;
293 7 next;
294 }
295 # default: do nothing, in the (impossible) event that $type is none of '*lit', 't', 'b', 'p', 'P', 'c', 'm' or 'k'
296 }
297  
298 # End of string composition
299 }
300  
301 118 $self->{line} = join('', $back, $blank, $back, $text);
302  
303 118 ▶ unless ($self->{test} or $self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"} or $self->{"quiet"}) 0 118 118
Condition33%1/3
$self->{"test"} or $self->{"quiet"}
l!l&&r!l&&!r
11800
MC/DC0%0/2
$self->{"test"} or $self->{"quiet"}
$self->{"test"} $self->{"quiet"}
Truth table33%1/3
A or B
A= $self->{"test"}B= $self->{"quiet"}
ABresult
1X1
011
000
304 0 local $| = 1;
305 0 print $self->{line};
306 }
307  
308 118 $self->{oldtext} = $text;
309 }
310  
311 44 ▶sub commify {
Subroutine commify: called CC=5 SCAR=16.1
Pod undocumented
312 44 my $com = shift;
313 44 ▶ if ($com) { return $com->($_[0]); }
Branch: 1 branch
BranchTrueFalseTotal
if ($com) 2 42 44
314  
315 42 local $_ = shift;
316 42 my ($sep, $group) = @_;
317  
318 42 ▶ if ($group > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group > 0) 40 2 42
319 40 my $len = length($_);
320 40 for my $i (1..$len) {
321 77 ▶ last unless s/^([-+]?\d+)(\d{$group})/$1$sep$2/;
Branch: 1 branch
BranchTrueFalseTotal
unless s/^([-+]?\d+)(\d{$group})/$1$sep$2/ 40 37 77
322 }
323 }
324 42 return $_;
325 }
326  
327 1 my $chunk_size = 10000;
328 1 my $bkup_size = 80;
329  
330 # Decision by Klaus Eichner, 31-MAY-2011:
331 # ---------------------------------------
332 # Make subs log_info(), set_chunk_size() and set_bkup_size() effectively dummy operations (i.e. they
333 # don't have any effect whatsoever)
334  
335 0 ▶sub log_info { }
Subroutine log_info: not called CC=1 SCAR=0.0
Pod undocumented
336 0 ▶sub set_chunk_size { }
Subroutine set_chunk_size: not called CC=1 SCAR=0.0
Pod undocumented
337 0 ▶sub set_bkup_size { }
Subroutine set_bkup_size: not called CC=1 SCAR=0.0
Pod undocumented
338  
339 3 ▶sub rem_backspace {
Subroutine rem_backspace: called CC=10 SCAR=23.3
Pod undocumented
340 3 my ($fname) = @_;
341  
342 3 ▶ open my $ifh, '<', $fname or die "Error-0200: Can't open < '$fname' because $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $ifh, "<", $fname or die "Error-0200: Can't open < '${fname}' because $!" 3 0 3
343 3 ▶ open my $tfh, '+>', undef or die "Error-0210: Can't open +> undef (tempfile) because $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $tfh, "+>", undef or die "Error-0210: Can't open +> undef (tempfile) because $!" 3 0 3
344  
345 3 my $out_buf = '';
346  
347 3 ▶ while (read($ifh, my $inp_buf, $chunk_size)) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $ifh, my $inp_buf, $chunk_size) 3 3 6
348 3 $out_buf .= $inp_buf;
349  
350 # here we are removing the backspaces:
351 3 ▶ while ($out_buf =~ m{\010+}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_buf =~ /\010+/msx) 4 3 7
352 4 my $pos_left = $-[0] * 2 - $+[0];
353 4 ▶ if ($pos_left < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos_left < 0) 0 4 4
354 0 $pos_left = 0;
355 }
356 4 $out_buf = substr($out_buf, 0, $pos_left).substr($out_buf, $+[0]);
357 }
358  
359 3 ▶ if (length($out_buf) > $bkup_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $out_buf > $bkup_size) 1 2 3
360 1 print {$tfh} substr($out_buf, 0, -$bkup_size);
361 1 $out_buf = substr($out_buf, -$bkup_size);
362 }
363 }
364  
365 3 CORE::close $ifh; # We need to employ CORE::close because there is already another close subroutine defined in the current namespace "Term::Sk"
366  
367 3 print {$tfh} $out_buf;
368  
369 # Now copy back temp-file to original file:
370  
371 3 ▶ seek $tfh, 0, SEEK_SET or die "Error-0220: Can't seek tempfile to 0 because $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $tfh, 0, 0 or die "Error-0220: Can't seek tempfile to 0 because $!" 3 0 3
372 3 ▶ open my $ofh, '>', $fname or die "Error-0230: Can't open > '$fname' because $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $ofh, ">", $fname or die "Error-0230: Can't open > '${fname}' because $!" 3 0 3
373  
374 3 ▶ while (read($tfh, my $buf, $chunk_size)) { print {$ofh} $buf; }
Branch: 1 branch
BranchTrueFalseTotal
if (read $tfh, my $buf, $chunk_size) 3 3 6
375  
376 3 CORE::close $ofh;
377 3 CORE::close $tfh;
378 }
379  
380 1 1;
381  
382 __END__
↑ Summary