Moose/Countdown.pm

filter: Statementstmt 63.1% 24 / 38 Branchbran 25.0% 2 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 61.4% 35 / 57 CC 6 SCAR 23.4
CC
6
Cov
56%
countdown
19.7
BEGIN
1.0
BEGIN
1.0
CRAP 10.3
« Moose/Instrument/OI_ITC503.pm ↑ Summary Moose/Instrument/ABB_TRMC2.pm »
1 package Lab::Moose::Countdown;
2 6 $Lab::Moose::Countdown::VERSION = '3.931';
3 #ABSTRACT: Verbose countdown/delay with pretty printing of remaining time
4  
5 6 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Time::HiRes qw/time sleep/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Time::Seconds;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 our @EXPORT = qw/countdown/;
15  
16  
17  
18 354 ▶sub countdown {
Subroutine countdown: called CC=6 SCAR=29.8
Pod documented
19  
20 # Do not use MooseX::Params::Validate for performance reasons.
21 354 my $delay = shift;
22 354 ▶ my $prefix = shift // "Sleeping for ";
Condition50%1/2
shift() // "Sleeping for "
l!l
0354
MC/DC0%0/1
shift() // "Sleeping for "
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
23  
24 354 ▶ if ( $delay < 0.5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delay < "0.5") 354 0 354
25 354 ▶ if ( $delay > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delay > 0) 0 354 354
26 0 sleep $delay;
27 }
28 354 return;
29 }
30  
31 0 my $t1 = time();
32  
33 0 my $autoflush = STDOUT->autoflush();
34  
35 0 while () {
36 0 my $remaining = $delay - ( time() - $t1 );
37 0 ▶ if ( $remaining < 0.5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining < "0.5") 0 0 0
38 0 ▶ if ( $remaining > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining > 0) 0 0 0
39 0 sleep $remaining;
40 }
41 0 last;
42 }
43 0 $remaining = Time::Seconds->new( int($remaining) + 1 );
44 0 sleep 0.1;
45 0 print $prefix, $remaining->pretty, " \r";
46 }
47 0 say " " x 80;
48 0 STDOUT->autoflush($autoflush);
49 }
50  
51 __END__
« Moose/Instrument/OI_ITC503.pm ↑ Summary Moose/Instrument/ABB_TRMC2.pm »