line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Guard::Timer; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
58058
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
5
|
2
|
|
|
2
|
|
8
|
use Exporter 'import'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
95
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a scope guard that keeps time |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = our @EXPORT_OK = qw/ timer_guard /; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
17
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
122
|
|
13
|
2
|
|
|
2
|
|
10
|
use Time::HiRes qw/ gettimeofday tv_interval /; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
14
|
2
|
|
|
2
|
|
918
|
use Guard; |
|
2
|
|
|
|
|
837
|
|
|
2
|
|
|
|
|
304
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub timer_guard(&;$) { ## no critic(ProhibitSubroutinePrototypes) |
18
|
6
|
|
|
6
|
1
|
81
|
my ($subref, $decimal_points) = @_; |
19
|
6
|
|
50
|
|
|
14
|
$decimal_points ||= 3; |
20
|
6
|
50
|
|
|
|
32
|
$decimal_points =~ /\A\d+\Z/ |
21
|
|
|
|
|
|
|
or croak("timer_guard: Number of decimal points isn't an integer"); |
22
|
|
|
|
|
|
|
|
23
|
6
|
|
|
|
|
20
|
my $t0 = [ gettimeofday() ]; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return guard { |
26
|
6
|
|
|
6
|
|
10073
|
my $duration = sprintf( "%.${decimal_points}f", tv_interval( $t0 ) ); |
27
|
6
|
|
|
|
|
164
|
$subref->($duration); |
28
|
6
|
|
|
|
|
60
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |