blib/lib/Linux/Event/Timer.pm

filter: Statementstmt 93.4% 57 / 61 Branchbran 93.3% 28 / 30 Conditioncond 90.2% 37 / 41 MC/DCmcdc 85.0% 17 / 20 Subroutinesub 78.5% 11 / 14 Podpod 100% 2 / 2 totaltotal 90.4% 152 / 168 CC 30 SCAR 20.1
CC
30
Cov
92%
_schedule
12.0
_seconds
10.1
new
6.0
CRAP 7.4
« blib/lib/Linux/Event/Framer/DecimalLength.pm ↑ Summary blib/lib/Linux/Event/Signal.pm »
1 package Linux::Event::Timer;
2 28 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 28 our $VERSION = '0.105';
7  
8 28 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 28 ▶use POSIX qw(isfinite);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 28 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 28 require Linux::Event::Loop;
13  
14 28 my %CLASS_DESCRIPTOR;
15  
16 101561 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=5 SCAR=16.1
17 101561 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 101523 38 101561
18 38 ▶ croak 'Linux::Event::Timer is an abstract base class'
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 1 37 38
19 if $class eq __PACKAGE__;
20 37 ▶ croak "$class is not a Linux::Event::Timer subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 37 37
21 if !$class->isa(__PACKAGE__);
22 37 ▶ my $callback = $class->can('on_timer')
Condition100%2/2
$class->can("on_timer") // croak("$class must define on_timer()")
l!l
361
MC/DC100%1/1
$class->can("on_timer") // croak("$class must define on_timer()")
$class->can("on_timer")
Truth table100%2/2
A
A= $class->can("on_timer")
Aresult
11
00
23 // croak "$class must define on_timer()";
24 36 return $CLASS_DESCRIPTOR{$class}
25 = Linux::Event::Timer::_Descriptor->new($callback);
26 }
27  
28 101580 ▶sub _seconds ($method, $name, $value, $positive) {
Subroutine _seconds: called CC=10 SCAR=23.2
29 101580 ▶ my $seconds = !defined($value) || ref($value)
Branch: 1 branch
BranchTrueFalseTotal
!defined($value) || ref $value || !&looks_like_number($value) ? : 1 101579 101580
Condition50%3/6
not defined $value or ref $value or not &looks_like_number($value)
l!l&&r!l&&!r
01101579
not defined $value or ref $value
l!l&&r!l&&!r
00101580
MC/DC33%1/3
not defined $value or ref $value or not &looks_like_number($value)
not defined $value ref $value not &looks_like_number($value)
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not &looks_like_number($value)
ABCresult
1XX1
01X1
0011
0000
30 || !looks_like_number($value) ? undef : 0 + $value;
31 101580 ▶ croak "$method(): $name must be a "
Branch: 2 branches
BranchTrueFalseTotal
if not defined $seconds && isfinite($seconds) or $seconds < 0 or $positive and $seconds == 0 5 101575 101580
$positive ? : 2 3 5
Condition100%12/12
not defined $seconds && isfinite($seconds) or $seconds < 0 or $positive and $seconds == 0
l!l&&r!l&&!r
41101575
not defined $seconds && isfinite($seconds) or $seconds < 0
l!l&&r!l&&!r
31101576
defined $seconds && isfinite($seconds)
!ll&&!rl&&r
12101577
$positive and $seconds == 0
!ll&&!rl&&r
10157231
MC/DC100%5/5
not defined $seconds && isfinite($seconds) or $seconds < 0 or $positive and $seconds == 0
defined $seconds isfinite($seconds) $seconds < 0 $positive $seconds == 0
Truth table100%6/6
not(A && B) or C or D and E
A= defined $secondsB= isfinite($seconds)C= $seconds < 0D= $positiveE= $seconds == 0
ABCDEresult
0XXXX1
10XXX1
111XX1
110111
1100X0
110100
32 . ($positive ? 'positive' : 'non-negative')
33 . ' number of seconds'
34 if !defined($seconds) || !isfinite($seconds)
35 || $seconds < 0 || ($positive && $seconds == 0);
36 101575 return $seconds;
37 }
38  
39 101582 ▶sub _schedule ($method, $option) {
Subroutine _schedule: called CC=12 SCAR=24.8
40 my @unknown = sort grep {
41 101582 ▶ $_ ne 'after' && $_ ne 'at' && $_ ne 'every'
Condition100%6/6
$_ ne 'after' && $_ ne 'at' && $_ ne 'every'
!ll&&!rl&&r
10157851
$_ ne "after" and $_ ne "at"
!ll&&!rl&&r
101504746
MC/DC100%3/3
$_ ne 'after' && $_ ne 'at' && $_ ne 'every'
$_ ne "after" $_ ne "at" $_ ne 'every'
Truth table100%4/4
A and B && C
A= $_ ne "after"B= $_ ne "at"C= $_ ne 'every'
ABCresult
0XX0
10X0
1100
1111
42 } keys %$option;
43 101582 ▶ croak "$method(): unknown options: " . join(', ', @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 101581 101582
44  
45 101581 my $has_after = exists $option->{after};
46 101581 my $has_at = exists $option->{at};
47 101581 my $has_every = exists $option->{every};
48 101581 ▶ croak "$method(): after and at are mutually exclusive"
Branch: 1 branch
BranchTrueFalseTotal
if $has_after and $has_at 1 101580 101581
Condition100%3/3
$has_after and $has_at
!ll&&!rl&&r
781015021
MC/DC100%2/2
$has_after and $has_at
$has_after $has_at
Truth table100%3/3
A and B
A= $has_afterB= $has_at
ABresult
0X0
100
111
49 if $has_after && $has_at;
50 101580 ▶ croak "$method(): one of after, at, or every is required"
Branch: 1 branch
BranchTrueFalseTotal
unless $has_after or $has_at or $has_every 1 101579 101580
Condition100%6/6
$has_after or $has_at or $has_every
l!l&&r!l&&!r
10157541
$has_after or $has_at
l!l&&r!l&&!r
101502735
MC/DC100%3/3
$has_after or $has_at or $has_every
$has_after $has_at $has_every
Truth table100%4/4
A or B or C
A= $has_afterB= $has_atC= $has_every
ABCresult
1XX1
01X1
0011
0000
51 if !$has_after && !$has_at && !$has_every;
52  
53 my $every = $has_every
54 101579 ▶ ? _seconds($method, 'every', $option->{every}, 1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$has_every ? : 5 101574 101579
55 101577 my ($absolute, $first);
56 101577 ▶ if ($has_at) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_at) { } 73 101504 101577
elsif ($has_after) { } 101502 2 101504
57 73 $absolute = 1;
58 73 $first = _seconds($method, 'at', $option->{at}, 0);
59 }
60 elsif ($has_after) {
61 101502 $absolute = 0;
62 101502 $first = _seconds($method, 'after', $option->{after}, 0);
63 }
64 else {
65 2 $absolute = 0;
66 2 $first = $every;
67 }
68 101574 return ($absolute, $first, $every);
69 }
70  
71 101570 ▶sub new ($class, %option) {
Subroutine new: called CC=6 SCAR=18.0
Pod documented
72 101570 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 101570 101570
73 101570 my $loop = delete $option{loop};
74 101570 ▶ croak 'new(): loop must be an object implementing add()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") 1 101569 101570
Condition83%5/6
defined $loop and not ref $loop && $loop->can("add")
!ll&&!rl&&r
10156361
ref $loop && $loop->can('add')
!ll&&!rl&&r
106
MC/DC66%2/3
defined $loop and not ref $loop && $loop->can("add")
defined $loop ref $loop $loop->can('add')
Truth table75%3/4
A and not(B && C)
A= defined $loopB= ref $loopC= $loop->can('add')
ABCresult
0XX0
1110
10X1
1101
75 if defined($loop) && (!ref($loop) || !$loop->can('add'));
76 101569 my $data = delete $option{data};
77 101569 my ($absolute, $first, $every) = _schedule('new', \%option);
78 101561 my $timer = $class->_new_native(
79 _descriptor_for($class), $absolute, $first, $every, $data,
80 );
81 101559 ▶ $loop->add($timer) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 6 101553 101559
82 101559 return $timer;
83 }
84  
85 13 ▶sub reschedule ($self, %option) {
Subroutine reschedule: called CC=1 SCAR=0.0
Pod documented
86 13 my ($absolute, $first, $every) = _schedule('reschedule', \%option);
87 13 return $self->_reschedule_native($absolute, $first, $every);
88 }
89  
90 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
91 0 %CLASS_DESCRIPTOR = ();
92 0 return;
93 }
94  
95 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
96  
97 package Linux::Event::Timer::_Descriptor;
98 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
99  
100 package Linux::Event::Timer;
101  
102 28 1;
103  
104 __END__
« blib/lib/Linux/Event/Framer/DecimalLength.pm ↑ Summary blib/lib/Linux/Event/Signal.pm »