blib/lib/Time/Nanos.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 91.6% 11 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 97.5% 79 / 81 CC 9 SCAR 11.8
CC
9
Cov
97%
clock_source
6.0
nanos
2.0
micros
2.0
CRAP 3.3
« blib/lib/Time/example.pl ↑ Summary Nanos.xs »
1 package Time::Nanos;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use autouse 'Carp' => qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = 'v0.1.6';
10 1 our @EXPORT = qw(nanos micros millis);
11 1 our $CLOCK = 0;
12  
13 1 require XSLoader;
14 1 XSLoader::load('Time::Nanos', $VERSION);
15  
16 8 ▶sub nanos {
Subroutine nanos: called CC=2 SCAR=6.9
Pod documented
17 8 my $as_array = shift();
18 8 my $ns = hrtime($Time::Nanos::CLOCK);
19  
20 8 ▶ if ($as_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_array) 3 5 8
21 3 my $sec = int($ns / 1_000_000_000);
22 3 my $nsec = $ns % 1_000_000_000;
23  
24 3 return ($sec, $nsec);
25 }
26  
27 5 return $ns;
28 }
29  
30 5 ▶sub micros {
Subroutine micros: called CC=2 SCAR=6.9
Pod documented
31 5 my $as_array = shift();
32 5 my $ns = hrtime($Time::Nanos::CLOCK);
33  
34 5 ▶ if ($as_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_array) 2 3 5
35 2 my $sec = int($ns / 1_000_000_000);
36 2 my $usec = int(($ns % 1_000_000_000) / 1000);
37  
38 2 return ($sec, $usec);
39 }
40  
41 3 my $us = int($ns / 1000);
42 3 return $us;
43 }
44  
45 5 ▶sub millis {
Subroutine millis: called CC=2 SCAR=6.9
Pod documented
46 5 my $as_array = shift();
47 5 my $ns = hrtime($Time::Nanos::CLOCK);
48  
49 5 ▶ if ($as_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_array) 2 3 5
50 2 my $sec = int($ns / 1_000_000_000);
51 2 my $msec = int(($ns % 1_000_000_000) / 1_000_000);
52 2 return ($sec, $msec);
53 }
54  
55 3 my $ms = int($ns / 1_000_000);
56 3 return $ms;
57 }
58  
59 5 ▶sub clock_source {
Subroutine clock_source: called CC=6 SCAR=18.0
Pod documented
60 5 my $input = shift();
61  
62 5 ▶ if (!defined $input) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $input) { } 0 5 5
elsif ($input eq 'realtime' or $input eq '0') { } 2 3 5
elsif ($input eq 'monotonic' or $input eq '1') { } 2 1 3
63 0 croak("clock_source() requires an argument");
64 ▶ } elsif ($input eq "realtime" || $input eq "0") {
Condition100%3/3
$input eq "realtime" or $input eq 0
l!l&&r!l&&!r
113
MC/DC100%2/2
$input eq "realtime" or $input eq 0
$input eq "realtime" $input eq 0
Truth table100%3/3
A or B
A= $input eq "realtime"B= $input eq 0
ABresult
1X1
011
000
65 2 $CLOCK = 0;
66 ▶ } elsif ($input eq "monotonic" || $input eq "1") {
Condition100%3/3
$input eq "monotonic" or $input eq 1
l!l&&r!l&&!r
111
MC/DC100%2/2
$input eq "monotonic" or $input eq 1
$input eq "monotonic" $input eq 1
Truth table100%3/3
A or B
A= $input eq "monotonic"B= $input eq 1
ABresult
1X1
011
000
67 2 $CLOCK = 1;
68 } else {
69 1 croak("Unknown source '$input'");
70 }
71 }
72  
73 1 1;
74  
75 __END__
« blib/lib/Time/example.pl ↑ Summary Nanos.xs »