File Coverage

blib/lib/Sub/Timekeeper.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Sub::Timekeeper;
2              
3 1     1   24365 use 5.008_001;
  1         5  
  1         42  
4              
5 1     1   6 use strict;
  1         2  
  1         29  
6 1     1   5 use warnings;
  1         6  
  1         42  
7              
8             require Exporter;
9 1     1   6 use Time::HiRes ();
  1         1  
  1         287  
10              
11             our $VERSION = '0.01';
12              
13             our @ISA = qw(Exporter);
14             our @EXPORT_OK = qw(timekeeper);
15             our %EXPORT_TAGS = (
16             all => [ @EXPORT_OK ],
17             );
18              
19             sub timekeeper {
20 7     7 0 4697 my $guard = Sub::Timekeeper::Guard->new(\$_[0]); shift;
  7         12  
21 7         10 my $subref = shift;
22              
23 7         21 return $subref->(@_);
24             }
25              
26             # utility class
27             {
28             package # hide from pause
29             Sub::Timekeeper::Guard;
30             sub new {
31 7     7   14 my ($klass, $elapsed) = @_;
32 7         42 bless [ $elapsed, Time::HiRes::time ], $klass;
33             }
34             sub DESTROY {
35 7     7   1000407 my $self = shift;
36 7         35 ${$self->[0]} = Time::HiRes::time - $self->[1];
  7         438  
37             }
38             }
39              
40             1;
41             __END__