File Coverage

blib/lib/Catmandu/Fix/sleep.pm
Criterion Covered Total %
statement 23 26 88.4
branch 6 10 60.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 35 43 81.4


line stmt bran cond sub pod time code
1              
2             use Catmandu::Sane;
3 2     2   85605  
  2         6  
  2         16  
4             our $VERSION = '1.2018';
5              
6             use Moo;
7 2     2   13 use Time::HiRes;
  2         5  
  2         13  
8 2     2   673 use namespace::clean;
  2         4  
  2         20  
9 2     2   135 use Catmandu::Fix::Has;
  2         4  
  2         15  
10 2     2   916  
  2         4  
  2         15  
11             with 'Catmandu::Fix::Inlineable';
12              
13             has seconds => (fix_arg => 1);
14             has units => (fix_arg => 1);
15              
16             my ($self, $data) = @_;
17              
18 4     4 0 35 my $sleep = $self->seconds;
19             my $units = $self->units;
20 4         19  
21 4         16 if ($units =~ /^microsecond(s)?$/i) { }
22             elsif ($units =~ /^millisecond(s)$/i) {
23 4 50       39 $sleep *= 1000;
    50          
    100          
    50          
    50          
24             }
25 0         0 elsif ($units =~ /^second(s)?$/i) {
26             $sleep *= 1000000;
27             }
28 3         14 elsif ($units =~ /^minute(s)?$/i) {
29             $sleep *= 60 * 1000000;
30             }
31 0         0 elsif ($units =~ /^hour(s)?$/i) {
32             $sleep *= 3600 * 1000000;
33             }
34 0         0 else {
35             $sleep *= 1000000;
36             }
37 1         2  
38             Time::HiRes::usleep($sleep);
39              
40 4         2500925 $data;
41             }
42 4         452  
43             1;
44              
45              
46             =pod
47              
48             =head1 NAME
49              
50             Catmandu::Fix::sleep - Do nothing for a specified amount of time
51              
52             =head1 SYNOPSIS
53            
54             sleep(10,MICROSECONDS)
55              
56             sleep(3,MILLISECONDS)
57              
58             sleep(1,SECOND)
59             sleep(2,SECONDS)
60              
61             sleep(5,MINUTES)
62              
63             sleep(1,HOURS)
64              
65             =head1 SEE ALSO
66              
67             L<Catmandu::Fix>
68              
69             =cut