File Coverage

inc/Test/Time.pm
Criterion Covered Total %
statement 16 23 69.5
branch 2 6 33.3
condition 0 2 0.0
subroutine 6 8 75.0
pod 0 1 0.0
total 24 40 60.0


line stmt bran cond sub pod time code
1             #line 1
2 2     2   1359 package Test::Time;
  2         5  
  2         66  
3 2     2   11 use strict;
  2         4  
  2         64  
4             use warnings;
5 2     2   12  
  2         5  
  2         27  
6             use Test::More;
7              
8             our $VERSION = '0.04';
9             our $time = CORE::time();
10              
11             my $pkg = __PACKAGE__;
12             my $in_effect = 1;
13              
14 6     6 0 17 sub in_effect {
15             $in_effect;
16             }
17              
18 2     2   15 sub import {
19 2 50       8 my ($class, %opts) = @_;
20             $time = $opts{time} if defined $opts{time};
21              
22 6 50   6   110 *CORE::GLOBAL::time = sub() {
23 6         26 if (in_effect) {
24             $time;
25 0         0 } else {
26             CORE::time();
27 2         9 }
28             };
29              
30 0 0   0     *CORE::GLOBAL::sleep = sub(;$) {
31 0   0       if (in_effect) {
32 0           my $sleep = shift || 1;
33 0           $time += $sleep;
34             note "sleep $sleep";
35 0           } else {
36             CORE::sleep(shift);
37             }
38 2         68 }
39             };
40              
41 0     0     sub unimport {
42             $in_effect = 0;
43             }
44              
45             1;
46             __END__