Guard/Timer.pm

filter: Statementstmt 100% 28 / 28 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 92.8% 39 / 42 CC 3 SCAR 4.8
CC
3
Cov
94%
timer_guard
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Log/Timer.pm ↑ Summary
1 package Guard::Timer;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = '1.0.1'; # VERSION
7 # ABSTRACT: a scope guard that keeps time
8  
9  
10 2 our @EXPORT = our @EXPORT_OK = qw/ timer_guard /;
11  
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Time::HiRes qw/ gettimeofday tv_interval /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Guard;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 6 ▶sub timer_guard(&;$) { ## no critic(ProhibitSubroutinePrototypes)
Subroutine timer_guard: called CC=3 SCAR=11.2
Pod documented
18 6 my ($subref, $decimal_points) = @_;
19 6 ▶ $decimal_points ||= 3;
Condition50%1/2
$decimal_points ||= 3
l!l
60
MC/DC0%0/1
$decimal_points ||= 3
$decimal_points
Truth table50%1/2
A
A= $decimal_points
Aresult
11
00
20 6 ▶ $decimal_points =~ /\A\d+\Z/
Branch: 1 branch
BranchTrueFalseTotal
$decimal_points =~ /\A\d+\Z/ or croak("timer_guard: Number of decimal points isn't an integer") 6 0 6
21 or croak("timer_guard: Number of decimal points isn't an integer");
22  
23 6 my $t0 = [ gettimeofday() ];
24  
25 6 ▶ return guard {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 6 my $duration = sprintf( "%.${decimal_points}f", tv_interval( $t0 ) );
27 6 $subref->($duration);
28 6 };
29 }
30  
31 2 1;
32  
33 __END__
« Log/Timer.pm ↑ Summary