blib/lib/Linux/Event/Kernel/Timer.pm

filter: Statementstmt 87.1% 68 / 78 Branchbran 86.8% 33 / 38 Conditioncond 83.0% 44 / 53 MC/DCmcdc 65.3% 17 / 26 Subroutinesub 70.0% 14 / 20 Podpod 50.0% 1 / 2 totaltotal 81.5% 177 / 217 CC 38 SCAR 19.4
CC
38
Cov
86%
_schedule
12.0
_seconds
10.1
_fork_preflight
9.1
CRAP 7.0
« blib/lib/Linux/Event/_Socket/Descriptor.pm ↑ Summary blib/lib/Linux/Event/TLS.pm »
1 package Linux::Event::Kernel::Timer;
2 41 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 41 our $VERSION = '0.120';
7  
8 41 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use POSIX qw(isfinite);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 41 ▶use Scalar::Util qw(looks_like_number refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 41 require Linux::Event::Loop;
13  
14 41 my %CLASS_DESCRIPTOR;
15  
16 101575 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=4 SCAR=13.9
17 101575 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 101534 41 101575
18 41 ▶ croak "$class is not a Linux::Event::Kernel::Timer subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 41 41
19 if !$class->isa(__PACKAGE__);
20 41 ▶ my $callback = $class->can('on_timer')
Condition100%2/2
$class->can("on_timer") // croak("$class must define on_timer() or receive on_timer => coderef")
l!l
392
MC/DC100%1/1
$class->can("on_timer") // croak("$class must define on_timer() or receive on_timer => coderef")
$class->can("on_timer")
Truth table100%2/2
A
A= $class->can("on_timer")
Aresult
11
00
21 // croak "$class must define on_timer() or receive on_timer => coderef";
22 39 return $CLASS_DESCRIPTOR{$class}
23 = Linux::Event::Kernel::Timer::_Descriptor->new($callback);
24 }
25  
26 101585 ▶sub _effective_descriptor ($class, $option) {
Subroutine _effective_descriptor: called CC=4 SCAR=13.9
27 101585 ▶ croak "$class is not a Linux::Event::Kernel::Timer subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 101585 101585
28 if !$class->isa(__PACKAGE__);
29 101585 ▶ return _descriptor_for($class) if !exists $option->{on_timer};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option->{"on_timer"} 101575 10 101585
30 10 my $callback = delete $option->{on_timer};
31 10 ▶ croak 'new(): on_timer must be a coderef' if ref($callback) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback ne "CODE" 1 9 10
32 9 return Linux::Event::Kernel::Timer::_Descriptor->new($callback);
33 }
34  
35 101593 ▶sub _seconds ($method, $name, $value, $positive) {
Subroutine _seconds: called CC=10 SCAR=23.2
36 101593 ▶ my $seconds = !defined($value) || ref($value)
Branch: 1 branch
BranchTrueFalseTotal
!defined($value) || ref $value || !&looks_like_number($value) ? : 1 101592 101593
Condition50%3/6
not defined $value or ref $value or not &looks_like_number($value)
l!l&&r!l&&!r
01101592
not defined $value or ref $value
l!l&&r!l&&!r
00101593
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
37 || !looks_like_number($value) ? undef : 0 + $value;
38 101593 ▶ 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 101588 101593
$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
41101588
not defined $seconds && isfinite($seconds) or $seconds < 0
l!l&&r!l&&!r
31101589
defined $seconds && isfinite($seconds)
!ll&&!rl&&r
12101590
$positive and $seconds == 0
!ll&&!rl&&r
10158531
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
39 . ($positive ? 'positive' : 'non-negative')
40 . ' number of seconds'
41 if !defined($seconds) || !isfinite($seconds)
42 || $seconds < 0 || ($positive && $seconds == 0);
43 101588 return $seconds;
44 }
45  
46 101595 ▶sub _schedule ($method, $option) {
Subroutine _schedule: called CC=12 SCAR=24.8
47 my @unknown = sort grep {
48 101595 ▶ $_ ne 'after' && $_ ne 'at' && $_ ne 'every'
Condition100%6/6
$_ ne 'after' && $_ ne 'at' && $_ ne 'every'
!ll&&!rl&&r
10159151
$_ ne "after" and $_ ne "at"
!ll&&!rl&&r
101513786
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
49 } keys %$option;
50 101595 ▶ croak "$method(): unknown options: " . join(', ', @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 101594 101595
51  
52 101594 my $has_after = exists $option->{after};
53 101594 my $has_at = exists $option->{at};
54 101594 my $has_every = exists $option->{every};
55 101594 ▶ croak "$method(): after and at are mutually exclusive"
Branch: 1 branch
BranchTrueFalseTotal
if $has_after and $has_at 1 101593 101594
Condition100%3/3
$has_after and $has_at
!ll&&!rl&&r
821015111
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
56 if $has_after && $has_at;
57 101593 ▶ croak "$method(): one of after, at, or every is required"
Branch: 1 branch
BranchTrueFalseTotal
unless $has_after or $has_at or $has_every 1 101592 101593
Condition100%6/6
$has_after or $has_at or $has_every
l!l&&r!l&&!r
10158841
$has_after or $has_at
l!l&&r!l&&!r
101511775
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
58 if !$has_after && !$has_at && !$has_every;
59  
60 my $every = $has_every
61 101592 ▶ ? _seconds($method, 'every', $option->{every}, 1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$has_every ? : 5 101587 101592
62 101590 my ($absolute, $first);
63 101590 ▶ if ($has_at) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_at) { } 77 101513 101590
elsif ($has_after) { } 101511 2 101513
64 77 $absolute = 1;
65 77 $first = _seconds($method, 'at', $option->{at}, 0);
66 }
67 elsif ($has_after) {
68 101511 $absolute = 0;
69 101511 $first = _seconds($method, 'after', $option->{after}, 0);
70 }
71 else {
72 2 $absolute = 0;
73 2 $first = $every;
74 }
75 101587 return ($absolute, $first, $every);
76 }
77  
78 101585 ▶sub new ($class, %option) {
Subroutine new: called CC=6 SCAR=18.0
Pod undocumented
79 101585 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 101585 101585
80 101585 my $descriptor = _effective_descriptor($class, \%option);
81 101582 my $loop = delete $option{loop};
82 101582 ▶ croak 'new(): loop must be an object implementing add()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") 1 101581 101582
Condition83%5/6
defined $loop and not ref $loop && $loop->can("add")
!ll&&!rl&&r
101566151
ref $loop && $loop->can('add')
!ll&&!rl&&r
1015
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
83 if defined($loop) && (!ref($loop) || !$loop->can('add'));
84 101581 my $data = delete $option{data};
85 101581 my ($absolute, $first, $every) = _schedule('new', \%option);
86 101573 my $timer = $class->_new_native(
87 $descriptor, $absolute, $first, $every, $data,
88 );
89 101573 ▶ $loop->add($timer) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 15 101558 101573
90 101573 return $timer;
91 }
92  
93 14 ▶sub reschedule ($self, %option) {
Subroutine reschedule: called CC=1 SCAR=0.0
Pod documented
94 14 my ($absolute, $first, $every) = _schedule('reschedule', \%option);
95 14 return $self->_reschedule_native($absolute, $first, $every);
96 }
97  
98 4 ▶sub _fork_preflight ($self, $mode, $loop) {
Subroutine _fork_preflight: called CC=7 SCAR=22.1
99 4 my $owner = $self->loop;
100 4 ▶ croak 'fork(): Timer is not active in this Loop'
Branch: 1 branch
BranchTrueFalseTotal
if not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active 0 4 4
Condition33%2/6
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active
l!l&&r!l&&!r
004
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop)
l!l&&r!l&&!r
004
MC/DC0%0/3
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active
not $owner builtin::refaddr($owner) != builtin::refaddr($loop) not $self->is_active
Truth table25%1/4
not(A) or B or not(C)
A= not $ownerB= builtin::refaddr($owner) != builtin::refaddr($loop)C= not $self->is_active
ABCresult
1XX1
01X1
0011
0000
101 if !$owner || refaddr($owner) != refaddr($loop) || !$self->is_active;
102 4 ▶ croak "fork(): Timer does not support '$mode'"
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "drop" and $mode ne "clone" and $mode ne "move" 0 4 4
Condition83%5/6
$mode ne "drop" and $mode ne "clone" and $mode ne "move"
!ll&&!rl&&r
220
$mode ne "drop" and $mode ne "clone"
!ll&&!rl&&r
112
MC/DC0%0/3
$mode ne "drop" and $mode ne "clone" and $mode ne "move"
$mode ne "drop" $mode ne "clone" $mode ne "move"
Truth table75%3/4
A and B and C
A= $mode ne "drop"B= $mode ne "clone"C= $mode ne "move"
ABCresult
0XX0
10X0
1100
1111
103 if $mode ne 'drop' && $mode ne 'clone' && $mode ne 'move';
104 4 return 1;
105 }
106  
107 0 ▶sub _fork_child_clone ($self, $loop) { $loop->add($self); return }
Subroutine _fork_child_clone: not called CC=1 SCAR=6.9
108 0 ▶sub _fork_child_move ($self, $loop) { $loop->add($self); return }
Subroutine _fork_child_move: not called CC=1 SCAR=6.9
109 0 ▶sub _fork_child_drop ($self, $loop) { $self->cancel; return }
Subroutine _fork_child_drop: not called CC=1 SCAR=6.9
110 1 ▶sub _fork_parent_move ($self, $child_pid) { $self->cancel; return }
Subroutine _fork_parent_move: called CC=1 SCAR=0.0
111  
112 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
113 0 %CLASS_DESCRIPTOR = ();
114 0 return;
115 }
116  
117 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
118  
119 package Linux::Event::Kernel::Timer::_Descriptor;
120 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
121  
122 package Linux::Event::Kernel::Timer;
123  
124 41 1;
125 __END__
« blib/lib/Linux/Event/_Socket/Descriptor.pm ↑ Summary blib/lib/Linux/Event/TLS.pm »